Zeex / sampgdk

Write SA-MP gamemodes in C/C++
http://zeex.github.io/sampgdk
Apache License 2.0
156 stars 83 forks source link

Native function not found: SetPVarInt #213

Closed alimsahy closed 4 years ago

alimsahy commented 4 years ago

Hi,

When i try to call plugin function in 'OnPlayerConnect' or any callback, i always getting this error. Why? Where am I doing wrong?

#include <sampgdk/core.h>
#include <sampgdk/sdk.h>
#include "Players.h"

extern void* pAMXFunctions;

PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() 
{
    return true;
}

AMX_NATIVE_INFO PluginNatives[] =
{
    {"SetPlayerFaction", Players::SetPlayerFaction},
    {"GetPlayerFaction", Players::GetPlayerFaction},
    {0, 0}
};

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
    return sampgdk::Supports() | SUPPORTS_PROCESS_TICK | SUPPORTS_AMX_NATIVES;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData)
{
    pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
    sampgdk_logprintf("Shit is working....");
    return true;
}

PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
    sampgdk::Unload();
}

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX* amx)
{
    return amx_Register(amx, PluginNatives, -1);
}

PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX* amx)
{
    return AMX_ERR_NONE;
}

Pawn file:

public OnGameModeInit()
{
    printf ("Loaded");
    return 1;
}

public OnPlayerConnect(playerid)
{
    SetPlayerFaction(playerid, 10); // Native function not found: SetPVarInt
    return 1;
}
alimsahy commented 4 years ago

FIXED: It seems we should use it after OnGameModeInit.

Ex:


public OnGameModeInit()
{ return1; }

public OnPlayerConnect(playerid)
{
        SetPlayerFaction(playerid, 10); // Worked
        return 1;
}