AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   this code is kinda messed up, or is it? (https://forums.alliedmods.net/showthread.php?t=317118)

I am inevitable 06-27-2019 15:50

this code is kinda messed up, or is it?
 
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

xines 06-27-2019 17:18

Re: this code is kinda messed up, or is it?
 
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;



I am inevitable 06-27-2019 17:21

Re: this code is kinda messed up, or is it?
 
Quote:

Originally Posted by xines (Post 2656963)
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


All times are GMT -4. The time now is 13:20.

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