AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Variable which can only be true || false (https://forums.alliedmods.net/showthread.php?t=220600)

Mofforg 07-12-2013 10:46

Variable which can only be true || false
 
Here's my little plugin (in the part of big plugin) which should control disables on high ping.

My question is - is it the correct defination of variable which could only be true or false? "static is_ping_ok=true" - maybe i should use another way? Can someone give me an example?

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

static is_ping_ok=true

public plugin_init() set_task(60.0"disables_on_high_ping"142600__"b")

public 
disables_on_high_ping()
{
    if (
GetAveragePing() > 150)
    {
        
is_ping_ok=false;
        
server_cmd("amxx pause something.amxx");
    }
    else 
    {
        
is_ping_ok=true;
        
server_cmd("amxx unpause something.amxx");
    }
    return 
PLUGIN_HANDLED
}

GetAveragePing()
{
    new 
players[32], n;
    
get_players(playersn"ch");
    
    if (!
n)
        return 
0;
    
    new 
sum;
    
    for (new 
ipinglossni++)
    {
        
get_user_ping(players[i], pingloss);
        
sum += ping;
    }
    
    return 
sum n;
}

public 
client_putinserver()
{
    if(
is_ping_okserver_print("ping is OK")
    else 
server_print("ping is BAD")



claudiuhks 07-12-2013 10:53

Re: Variable which can only be true || false
 
PHP Code:

static something /* constant value attribution */;

something 32;

static 
boolcan_be_true_or_false true /* constant value attribution */;

can_be_true_or_false false;

can_be_true_or_false = (something != 0) ? true false


kungfulon 07-12-2013 10:53

Re: Variable which can only be true || false
 
PHP Code:

new bool:is_ping_ok=true 


Mofforg 07-12-2013 10:57

Re: Variable which can only be true || false
 
Thanks. Topic may be closed.


All times are GMT -4. The time now is 06:32.

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