Raised This Month: $32 Target: $400
 8% 

this code is kinda messed up, or is it?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 06-27-2019 , 15:50   this code is kinda messed up, or is it?
Reply With Quote #1

PHP Code:
#include <sourcemod>
#include <cstrike>

bool g_bSomething;

public 
void OnMapStart()
{
    
CreateTimer(5.0Timer_Something_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_Something(Handle hTimerint iData)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsValidClient(i))
        {
            if (
g_bSomething)
                
CS_SetClientClanTag(i"Hey");
        
            else
                
CS_SetClientClanTag(i"Ho");
        
            
g_bSomething = !g_bSomething;
        }
    }
    
    return 
Plugin_Continue;
}

public 
bool IsValidClient(int iClient)
{
    if (!(
iClient <= MaxClients) || !IsClientConnected(iClient) || !IsClientInGame(iClient) || IsFakeClient(iClient))
        return 
false;
    
    return 
true;

Hi. I'm trying to make the clantags change every five seconds, and it works just fine when I'm by myself on the server, but whenever someone else joins, everyone has different clan tags and its like the plugin has entered the "failstate-mode".
the weird think is that it all again works fine when everyone but one player leaves the server
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-27-2019 , 17:18   Re: this code is kinda messed up, or is it?
Reply With Quote #2

Place your bool outside of your client loop.
Also don't use IsValidClient inside of your client loop as it's a waste of cpu for various reasons.

PHP Code:
bool g_bSomething;

public 
void OnMapStart()
{
    
CreateTimer(5.0Timer_Something_TIMER_REPEAT);
}

public 
Action Timer_Something(Handle timer
{
    
g_bSomething = !g_bSomething;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsFakeClient(i)) 
        {
            if (
g_bSomethingCS_SetClientClanTag(i"Hey");
            else 
CS_SetClientClanTag(i"Ho");
        }
    }
    
    return 
Plugin_Continue;

__________________
xines is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 06-27-2019 , 17:21   Re: this code is kinda messed up, or is it?
Reply With Quote #3

Quote:
Originally Posted by xines View Post
Place your bool outside of your client loop.
Also don't use IsValidClient inside of your client loop as it's a waste of cpu for various reasons.

PHP Code:
bool g_bSomething;

public 
void OnMapStart()
{
    
CreateTimer(5.0Timer_Something_TIMER_REPEAT);
}

public 
Action Timer_Something(Handle timer
{
    
g_bSomething = !g_bSomething;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsFakeClient(i)) 
        {
            if (
g_bSomethingCS_SetClientClanTag(i"Hey");
            else 
CS_SetClientClanTag(i"Ho");
        }
    }
    
    return 
Plugin_Continue;

thank you
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
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 12:00.


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