You use them when passing entities to functions. Here's an example from my Mutant Tanks plugin:
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
if (g_bPluginEnabled && StrEqual(classname, "tank_rock"))
{
// pass the reference of the entity to the timer...
CreateTimer(0.1, tTimerRockThrow, EntIndexToEntRef(entity), TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action tTimerRockThrow(Handle timer, int ref)
{
// convert the reference back to an index and check if that entity is still there...
int iRock = EntRefToEntIndex(ref);
if (!g_bPluginEnabled || iRock == INVALID_ENT_REFERENCE || !bIsValidEntity(iRock))
{
return Plugin_Stop;
}
// rest of the code here...
return Plugin_Continue;
}
The reason we pass entities like this is because entities can be changed or deleted anytime between the time of passing them through a function and the time of when we use them in that function.
We do the same thing with clients using
GetClientUserId() paired with
GetClientOfUserId() or
GetClientSerial() paired with
GetClientFromSerial():
PHP Code:
public void OnClientPostAdminCheck(int client)
{
if (!IsFakeClient(client))
{
CreateTimer(3.0, tTimerWelcome, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action tTimerWelcome(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if (!(0 < client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client)))
{
return Plugin_Stop;
}
PrintToChat(client, "[SM] Welcome %N!", client);
return Plugin_Continue;
}
__________________