29.05.2012, 18:25
nice but your ALS code is kinda poor...
check here https://sampforum.blast.hk/showthread.php?tid=85907
you should make vars and hold if the next function really exist
if so call it,
your way your calling the function every time if it exists or not.
this is closer to what it should look like, (without the weapon code)
also redefining native functions you should also be using some sort of ALS
because if some other include try to redefine then it will break the code.
regards, J5
check here https://sampforum.blast.hk/showthread.php?tid=85907
you should make vars and hold if the next function really exist
if so call it,
your way your calling the function every time if it exists or not.
this is closer to what it should look like, (without the weapon code)
pawn Код:
static gAC_HasCB[6];
//--------------OnGameModeInit Hook-------------------
public OnGameModeInit()
{
//your OnGameModeInit pre code here
//function hook checks
gAC_HasCB[0] = funcidx("AC_OnGameModeExit") != -1;
gAC_HasCB[1] = funcidx("AC_OnPlayerConnect") != -1;
gAC_HasCB[2] = funcidx("AC_OnPlayerDeath") != -1;
gAC_HasCB[3] = funcidx("AC_OnPlayerDisconnect") != -1;
gAC_HasCB[4] = funcidx("AC_OnPlayerKeyStateChange") != -1;
gAC_HasCB[5] = funcidx("AC_OnPlayerSpawn") != -1;
if (funcidx("AC_OnGameModeInit") != -1)
{
CallLocalFunction("AC_OnGameModeInit", "");
}
//your OnGameModeInit post code here
return 1;
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit AC_OnGameModeInit
forward AC_OnGameModeInit();
//--------------OnGameModeExit Hook-------------------
public OnGameModeExit()
{
//your OnGameModeExit code here
if (gAC_HasCB[0])
{
return CallLocalFunction("AC_OnGameModeExit", "");
}
return 1;
}
#if defined _ALS_OnGameModeExit
#undef OnGameModeExit
#else
#define _ALS_OnGameModeExit
#endif
#define OnGameModeExit AC_OnGameModeExit
forward AC_OnGameModeExit();
//--------------OnPlayerConnect Hook-------------------
public OnPlayerConnect(playerid)
{
//your OnPlayerConnect code here
if (gAC_HasCB[1])
{
return CallLocalFunction("AC_OnPlayerConnect", "i",playerid);
}
return 1;
}
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect AC_OnPlayerConnect
forward AC_OnPlayerConnect(playerid);
//--------------OnPlayerDeath Hook-------------------
public OnPlayerDeath(playerid, killerid, reason)
{
//your OnPlayerDeath code here
if (gAC_HasCB[2])
{
return CallLocalFunction("AC_OnPlayerDeath", "iii",playerid, killerid, reason);
}
return 1;
}
#if defined _ALS_OnPlayerDeath
#undef OnPlayerDeath
#else
#define _ALS_OnPlayerDeath
#endif
#define OnPlayerDeath AC_OnPlayerDeath
forward AC_OnPlayerDeath(playerid, killerid, reason);
//--------------OnPlayerDisconnect Hook-------------------
public OnPlayerDisconnect(playerid, reason)
{
//your OnPlayerDisconnect code here
if (gAC_HasCB[3])
{
return CallLocalFunction("AC_OnPlayerDisconnect", "ii",playerid, reason);
}
return 1;
}
#if defined _ALS_OnPlayerDisconnect
#undef OnPlayerDisconnect
#else
#define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect AC_OnPlayerDisconnect
forward AC_OnPlayerDisconnect(playerid, reason);
//--------------OnPlayerKeyStateChange Hook-------------------
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
//your OnPlayerKeyStateChange code here
if (gAC_HasCB[4])
{
return CallLocalFunction("AC_OnPlayerKeyStateChange", "iii",playerid, newkeys, oldkeys);
}
return 1;
}
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange AC_OnPlayerKeyStateChange
forward AC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
//--------------OnPlayerSpawn Hook-------------------
public OnPlayerSpawn(playerid)
{
//your OnPlayerSpawn code here
if (gAC_HasCB[5])
{
return CallLocalFunction("AC_OnPlayerSpawn", "i",playerid);
}
return 1;
}
#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn AC_OnPlayerSpawn
forward AC_OnPlayerSpawn(playerid);
also redefining native functions you should also be using some sort of ALS
because if some other include try to redefine then it will break the code.
regards, J5