Raised This Month: $12 Target: $400
 3% 

Even and Odd number


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode