Raised This Month: $51 Target: $400
 12% 

CREATE TIMER for plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vegeta1241
AlliedModders Donor
Join Date: Apr 2017
Location: Switzerland
Old 10-02-2018 , 07:42   CREATE TIMER for plugin
Reply With Quote #1

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)]; 
}
vegeta1241 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-02-2018 , 10:14   Re: CREATE TIMER for plugin
Reply With Quote #2

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.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334

Last edited by eyal282; 10-02-2018 at 10:14.
eyal282 is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-02-2018 , 12:16   Re: CREATE TIMER for plugin
Reply With Quote #3

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


Last edited by Ilusion9; 10-02-2018 at 12:16.
Ilusion9 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 10-02-2018 , 14:22   Re: CREATE TIMER for plugin
Reply With Quote #4

@Ilusion9

If you wouldn't mind... "but want i timer for swap all player in Terrorist"
mug1wara is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-03-2018 , 06:27   Re: CREATE TIMER for plugin
Reply With Quote #5

Quote:
Originally Posted by mug1wara View Post
@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.
Ilusion9 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 10-03-2018 , 08:26   Re: CREATE TIMER for plugin
Reply With Quote #6

Quote:
Originally Posted by Ilusion9 View Post
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.
mug1wara is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-03-2018 , 11:04   Re: CREATE TIMER for plugin
Reply With Quote #7

Quote:
Originally Posted by mug1wara View Post
Ye, sure, but you did the opposite of what he asked for.
then you can't read sourcemod code if you think that.
Ilusion9 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-03-2018 , 11:18   Re: CREATE TIMER for plugin
Reply With Quote #8

Quote:
Originally Posted by Ilusion9 View Post
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."
__________________
Psyk0tik is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 10-03-2018 , 11:49   Re: CREATE TIMER for plugin
Reply With Quote #9

Altough I'm not entirely sure what he wants...

Quote:
Originally Posted by Ilusion9 View Post
then you can't read sourcemod code if you think that.
Guess I can't read sourcemod code then.
mug1wara 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 19:04.


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