Raised This Month: $ Target: $400
 0% 

Variable which can only be true || false


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-12-2013 , 10:46   Variable which can only be true || false
Reply With Quote #1

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")


Last edited by Mofforg; 07-12-2013 at 10:46.
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 07-12-2013 , 10:53   Re: Variable which can only be true || false
Reply With Quote #2

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
__________________

Last edited by claudiuhks; 07-12-2013 at 10:54.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
kungfulon
Junior Member
Join Date: Aug 2011
Location: Vietnam
Old 07-12-2013 , 10:53   Re: Variable which can only be true || false
Reply With Quote #3

PHP Code:
new bool:is_ping_ok=true 
__________________
c++
kungfulon is offline
Send a message via Yahoo to kungfulon
Mofforg
Senior Member
Join Date: Aug 2010
Location: Moscow, Russia
Old 07-12-2013 , 10:57   Re: Variable which can only be true || false
Reply With Quote #4

Thanks. Topic may be closed.
Mofforg is offline
Send a message via ICQ to Mofforg Send a message via Skype™ to Mofforg
Reply



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 06:32.


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