AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   CREATE TIMER for plugin (https://forums.alliedmods.net/showthread.php?t=311051)

vegeta1241 10-02-2018 07:42

CREATE TIMER for plugin
 
Hello i have a timer for my script to choose a random ct but want i timer for swap all player in Terrorist.
If you can help me

Code:

#include <sourcemod>
#include <cstrike>
#include <sdktools>

public void OnPluginStart()
{
    HookEvent("round_end", round_end);
}

public Action round_end(Handle event, const char[] name, bool dontbroadcast)
{
    ServerCommand("mp_autoteambalance 0");
    new ctone = GetRandomPlayer();
    CreateTimer(2.0, goct, ctone);
    for (new i = 1; i <= MaxClients; i++)
    {
        ChangeClientTeam(i, CS_TEAM_T);
    }
}

public Action goct(Handle timer, ctone)
{
    ChangeClientTeam(ctone, CS_TEAM_CT);
}

GetRandomPlayer()
{
    new clients[MaxClients+1], clientCount;
    for (new i = 1; i <= MaxClients; i++)
        if (IsClientInGame(i) && GetClientTeam(CS_TEAM_T))
        clients[clientCount++] = i;
    return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount-1)];
}


eyal282 10-02-2018 10:14

Re: CREATE TIMER for plugin
 
Code:

#include <sourcemod>
#include <cstrike>
#include <sdktools>

public void OnPluginStart()
{
    HookEvent("round_end", round_end);
}

public Action round_end(Handle event, const char[] name, bool dontbroadcast)
{
    ServerCommand("mp_autoteambalance 0");

    CreateTimer(2.0, goct);
    for (new i = 1; i <= MaxClients; i++)
    {
        ChangeClientTeam(i, CS_TEAM_T);
    }
}

public Action goct(Handle timer, ctone)
{
for(new i=1;i <= MaxClients;i++)
{
if(!isClientInGame(i))
continue;

else if(GetClientTeam(i) != CS_TEAM_T)
continue;

ChangeClientTeam(i, CS_TEAM_CT);
}
}
}

On a different scenario:

GetClientTeam(CS_TEAM_T)

This is a mistake, meaning that no what what, this will ALWAYS return either true or false ( IDK which ).

This means that either no player will be taken as a random player or that all players will, depending on whether or not the client that has the index same as CS_TEAM_T has is any team apart from unassigned. Fix it.

Ilusion9 10-02-2018 12:16

Re: CREATE TIMER for plugin
 
PHP Code:

#include <sourcemod> 
#include <cstrike> 
#include <sdktools> 

public void OnPluginStart()
{
    
HookEvent("round_prestart"round_prestart);
}

public 
Action round_prestart(Handle event, const char[] namebool dontbroadcast)
{
    
ServerCommand("mp_autoteambalance 0");
    
int ctone GetRandomPlayer();
    
    if (
ctone)
    {
        
CS_SwitchTeam(ctoneCS_TEAM_CT);
    }

    for (
int i 1<= MaxClientsi++) 
    {
        if (
IsClientInGame(i) && != ctone)
        {
            
CS_SwitchTeam(iCS_TEAM_T);
        }
    }


GetRandomPlayer() 

    
int clients[MAXPLAYERS 1], clientCount;
    
    for (
int i 1<= MaxClientsi++) 
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == CS_TEAM_T)
        {
            
clients[clientCount++] = i;
        }
    }

    return 
clientCount clients[GetRandomInt(0clientCount 1)] : 0



mug1wara 10-02-2018 14:22

Re: CREATE TIMER for plugin
 
@Ilusion9

If you wouldn't mind... "but want i timer for swap all player in Terrorist"

Ilusion9 10-03-2018 06:27

Re: CREATE TIMER for plugin
 
Quote:

Originally Posted by mug1wara (Post 2617764)
@Ilusion9

If you wouldn't mind... "but want i timer for swap all player in Terrorist"

and where's your code? where is the answer for his question? i gave him a better solution for his problem.

mug1wara 10-03-2018 08:26

Re: CREATE TIMER for plugin
 
Quote:

Originally Posted by Ilusion9 (Post 2617818)
and where's your code? where is the answer for his question? i gave him a better solution for his problem.

Ye, sure, but you did the opposite of what he asked for.

Ilusion9 10-03-2018 11:04

Re: CREATE TIMER for plugin
 
Quote:

Originally Posted by mug1wara (Post 2617831)
Ye, sure, but you did the opposite of what he asked for.

then you can't read sourcemod code if you think that.

Psyk0tik 10-03-2018 11:18

Re: CREATE TIMER for plugin
 
Quote:

Originally Posted by Ilusion9 (Post 2617847)
then you can't read sourcemod code if you think that.

I see what you did. Rather than using a timer at round_end, you just decided to run the code before round_start to simulate the same "delay."

mug1wara 10-03-2018 11:49

Re: CREATE TIMER for plugin
 
Altough I'm not entirely sure what he wants...

Quote:

Originally Posted by Ilusion9 (Post 2617847)
then you can't read sourcemod code if you think that.

Guess I can't read sourcemod code then.


All times are GMT -4. The time now is 22:01.

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