error 021: symbol already defined: "OnPlayerConnect"
public OnPlayerConnect(playerid) { OnPlayerConnectEx(playerid); }
stock OnPlayerConnectEx(playerid) { //code you want to execute }
public OnPlayerConnect(playerid) { if(funcidx("FOnPlayerConnect") != -1) { return CallLocalFunction("F_OnPlayerConnect", "i", playerid); } return 1; } #if defined _ALS_OnPlayerConnect #undef OnPlayerConnect #else #define _ALS_OnPlayerConnect #endif #define OnPlayerConnect F_OnPlayerConnect forward F_OnPlayerConnect(playerid); stock F_OnPlayerConnect(playerid) { //code... }
\gamemodes\script.pwn(3013) : error 021: symbol already defined: "F_OnPlayerConnect" |
static
bool:gHasOPC = false;
public OnGameModeInit()
{
gHasOPC = funcidx("F_OnPlayerConnect") != -1;
if(funcidx("F_OnGameModeInit") != -1)
{
return CallLocalFunction("F_OnGameModeInit", "");
}
return 1;
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit F_OnGameModeInit
forward F_OnGameModeInit();
public OnPlayerConnect(playerid)
{
//code here
if(gHasOPC) //faster than using funcidx to check if have OnPlayerConnect callback in your gamemode
{
return CallLocalFunction("F_OnPlayerConnect", "i", playerid); //this calls OnPlayerConnect in your gamemode
}
//or here
return 1;
}
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect F_OnPlayerConnect
forward F_OnPlayerConnect(playerid);
public OnPlayerConnect(playerid)
{
OnPlayerConnectEx(playerid);
// Other connect stuff in the script here
return 1;
}
forward OnPlayerConnectEx(playerid);
public OnPlayerConnectEx(playerid)
{
// Do your include-stuff here
}
You don't use F_OnPlayerConnect - that basically renames the NEXT OnPlayerConnect which MAY be the one in the gamemode or one in another library.
|
public OnPlayerConnect(playerid) //yes, this is also in the include! { //code } public OnPlayerConnect(playerid) { if(funcidx("F_OnPlayerConnect") != -1) { return CallLocalFunction("F_OnPlayerConnect", "i", playerid); } return 1; } #if defined _ALS_OnPlayerConnect #undef OnPlayerConnect #else #define _ALS_OnPlayerConnect #endif #define OnPlayerConnect F_OnPlayerConnect forward F_OnPlayerConnect(playerid);
public OnPlayerConnect(playerid)
{
if(funcidx("F_OnPlayerConnect") != -1)
{
return CallLocalFunction("F_OnPlayerConnect", "i", playerid);
}
return 1;
}
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect F_OnPlayerConnect
forward F_OnPlayerConnect(playerid);
//In a different script (Or at least not the include)
public OnPlayerConnect(playerid)
{
//code
}
#if defined _ALS_OnPlayerConnect #undef OnPlayerConnect #else #define _ALS_OnPlayerConnect #endif
#define OnPlayerConnect F_OnPlayerConnect forward F_OnPlayerConnect(playerid);
Or do for example:
- In your script: pawn Код:
pawn Код:
|