View Single Post
Author Message
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-26-2012 , 16:22   Even and Odd number
Reply With Quote #1

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;


Last edited by Mathias.; 06-27-2012 at 06:40.
Mathias. is offline