This is my first snipet and it is not fancy at all but it can be useful in some case.
It check if the integer is a Even or a Odd number:
PHP Code:
stock bool:IsEven(num)
{
return (num & 1) == 0;
}
stock bool:IsOdd(num)
{
return (num & 1) == 1;
}
Here an exemple of is use in a simple script that allow only one smoke grenade per two rounds:
PHP Code:
#include <sourcemod>
#include <cstrike>
new g_iClientSpawnCount[MAXPLAYERS];
new bool:g_bClientBuyedSmokeGrenade[MAXPLAYERS];
public OnPluginStart()
{
HookEvent("player_spawn", OnPlayerSpawn);
}
public OnClientPutInServer(client)
{
g_iClientSpawnCount[client] = 0;
g_bClientBuyedSmokeGrenade[client] = false;
}
public OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event,"userid"));
g_iClientSpawnCount[client]++;
g_bClientBuyedSmokeGrenade[client] = false;
}
public Action:CS_OnBuyCommand(client, const String:item_name[])
{
if (StrEqual(item_name, "smokegrenade"))
{
if (!IsEven(g_iClientSpawnCount[client]) || g_bClientBuyedSmokeGrenade[client])
{
PrintToChat(client, "You are only allow to buy one smoke grenade every two rounds");
return Plugin_Handled;
}
else
{
g_bClientBuyedSmokeGrenade[client] = true;
}
}
return Plugin_Continue;
}
stock bool:IsEven(num)
{
return (num & 1) == 0;
}