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

[CSGO]Probably a simple problem that I just can't figure out...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 05-11-2017 , 05:35   [CSGO]Probably a simple problem that I just can't figure out...
Reply With Quote #1

Hello!

Before you think that I am just lazy and haven't googled this, let me just say that I have tried 3 days to get this to work... How can I go through all players on the server, list their steamid or userid to arrays(?) like player[0], player[1], etc... AND use those arrays/values in different event (round end)?

It probably goes something like this (simplified):
Code:
public void OnPluginStart()
{
	HookEvent("round_start", Event_RoundStart);
	HookEvent("round_end", Event_RoundEnd);
}

public void OnMapStart()
{
	roundCounter = 0;
}

public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
	if (GameRules_GetProp("m_bWarmupPeriod") == 0 && roundCounter == 0)
	{
		for(new i = 1; i <= GetClientCount(); i++)
		{
			new id = GetClientUserId(i);
			
			new x = GetRandomInt(1,10);
			if(x >= 6)
			{
				//Assign this player's steamid or clientid to a variable that can be used later in Event_RoundEnd
			}
		}
		roundCounter += 1;
	}
}

public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
	if (GameRules_GetProp("m_bWarmupPeriod") == 0)
	{
		//Do something to specific players that we determined by GetRandomInt
	}
}
Edit: If you need to know why I need this, I am moving specific players from one team to another and tracking and modifying their stats until they get at least 1 death and 1 kill.
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.

Last edited by VJScope; 05-11-2017 at 07:37.
VJScope is offline
SomePanns
Senior Member
Join Date: Dec 2013
Old 05-11-2017 , 07:02   Re: [CSGO]Probably a simple problem that I just can't figure out...
Reply With Quote #2

I'm not sure if I understood what you want, but what about this? (new syntax because I'm not familiar with old, sorry)
PHP Code:
#include <sdktools>

char PlayerSteamID[MAXPLAYERS+1][255];
int RandomPlayer[MAXPLAYERS+1];
int roundCounter;

public 
void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);
}

public 
void OnMapStart()
{
    
roundCounter 0;
}

public 
void OnClientPostAdminCheck(int client)
{
    
GetClientAuthId(clientAuthId_SteamID64PlayerSteamID[client], sizeof(PlayerSteamID)); // Steam ID will be in 64-bit format
}

public 
Action Event_RoundStart(Handle event, const char[] namebool dontBroadcast)
{
    if (
GameRules_GetProp("m_bWarmupPeriod") == && roundCounter == 0)
    {
        for(
int i 1<= MaxClientsi++)
        {
            
RandomPlayer[i] = GetRandomInt(0,10); // Store the random integer in a player assigned variable
            
if(RandomPlayer[i] <= 6// Since all players have their steamid stored in a variable, remove it for those who aren't selected
            
{
                
                
Format(PlayerSteamID[i], sizeof(PlayerSteamID), "");  
            }
        }
        
        
roundCounter++;
    }
}

public 
Action Event_RoundEnd(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
    if (
GameRules_GetProp("m_bWarmupPeriod") == 0)
    {
        if(
RandomPlayer[client] == 666
        {
            
// Do something
        
}
        
        if(
StrEqual(PlayerSteamID[client], "123"false))
        {
            
// do something
        
}
    }


Last edited by SomePanns; 05-11-2017 at 07:05.
SomePanns is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 05-11-2017 , 07:27   Re: [CSGO]Probably a simple problem that I just can't figure out...
Reply With Quote #3

Thank you for a quick reply. Looks like I forgot to change the GetRandomInt to (1,10). That should confuse anyone! The original idea can be found here.

It goes through all clients and randomly chooses (if random int >= 6, which means that there is 40% chance that the player will be chosen)
Code:
new x = GetRandomInt(1,10);
if(x >= 6)
{
	CreateTimer(0.0, ShufflePlayers, i);
}
players and changes their side. Basically it is a 'team randomizer' after a warmup round. Players will suicide, so the plugin will respawn them. They will get -1 frag and +1 death, so the plugin will give them +1 frags and -1 deaths. The problem is that if they don't get at least 1 frag, their stats will change back to -1, and if they don't die they will get +1 deaths. So the plugin has to track the stats of players that got 'shuffled' until they get at least 1 frag and die once. This means that I have to 'mark' all players that got 'shuffled' and check their stats at the end of every round until they get +1 frag and +1 death.

I hope that my explanation wasn't too confusing...


Edit: Forgot to mention that this plugin moves CT and T in turn. If the previous guy was T and the next guy is T, it will not change the second guy's team.
Code:
if(currTeam == CS_TEAM_CT && currTeam != prevTeam)
...
else if(currTeam == CS_TEAM_T && currTeam != prevTeam)
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.

Last edited by VJScope; 05-11-2017 at 07:38.
VJScope is offline
good_live
AlliedModders Donor
Join Date: Oct 2013
Old 05-11-2017 , 07:40   Re: [CSGO]Probably a simple problem that I just can't figure out...
Reply With Quote #4

Quote:
Originally Posted by SomePanns View Post
I'm not sure if I understood what you want, but what about this? (new syntax because I'm not familiar with old, sorry)
PHP Code:
#include <sdktools>

char PlayerSteamID[MAXPLAYERS+1][255];
int RandomPlayer[MAXPLAYERS+1];
int roundCounter;

public 
void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);
}

public 
void OnMapStart()
{
    
roundCounter 0;
}

public 
void OnClientPostAdminCheck(int client)
{
    
GetClientAuthId(clientAuthId_SteamID64PlayerSteamID[client], sizeof(PlayerSteamID)); // Steam ID will be in 64-bit format
}

public 
Action Event_RoundStart(Handle event, const char[] namebool dontBroadcast)
{
    if (
GameRules_GetProp("m_bWarmupPeriod") == && roundCounter == 0)
    {
        for(
int i 1<= MaxClientsi++)
        {
            
RandomPlayer[i] = GetRandomInt(0,10); // Store the random integer in a player assigned variable
            
if(RandomPlayer[i] <= 6// Since all players have their steamid stored in a variable, remove it for those who aren't selected
            
{
                
                
Format(PlayerSteamID[i], sizeof(PlayerSteamID), "");  
            }
        }
        
        
roundCounter++;
    }
}

public 
Action Event_RoundEnd(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
    if (
GameRules_GetProp("m_bWarmupPeriod") == 0)
    {
        if(
RandomPlayer[client] == 666
        {
            
// Do something
        
}
        
        if(
StrEqual(PlayerSteamID[client], "123"false))
        {
            
// do something
        
}
    }

Round end has no userid parameter. You will need to do another loop there.
good_live is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 05-12-2017 , 05:58   Re: [CSGO]Probably a simple problem that I just can't figure out...
Reply With Quote #5

All I need to know is how to assign each player's (in that for-loop) steamid to different variable and use them in another event..

Maybe this gives you better idea of what I'm trying to do:
Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

new prevTeam;
new currTeam;
new roundCounter;

public Plugin myinfo = 
{
	name = "Team Balance",
	author = "VJScope",
	version     = "1.0",
	description = "Shuffle teams in specific situations",
};

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

public void OnMapStart()
{
	roundCounter = 0;
	prevTeam = 7;
	currTeam = 8;
}

public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
	if (GameRules_GetProp("m_bWarmupPeriod") == 0 && roundCounter == 0)
	{
		PrintToChatAll(" \x04[SM] Warmup ended! Shuffling teams...");
		
		for(new i = 1; i <= GetClientCount(); i++)
		{
			new x = GetRandomInt(1,10);
			if(x >= 6)
			{
				CreateTimer(0.0, ShufflePlayers, i);
			}
		}
		
		roundCounter += 1;
	}
}

public Action:ShufflePlayers(Handle:timer, any:client)
{
	new isAlive = 0;
	currTeam = GetClientTeam(client);
	
	if(currTeam == CS_TEAM_CT && currTeam != prevTeam)
	{
		if(IsPlayerAlive(client))
		{			
			isAlive = 1;
			//Get player's steamid and store it to a variable. I will need a different variable for each of the players that are chosen.
			//I don't need everyone's steamid. Just the ones that were alive. That's why I chose this, but maybe there is better solution..
		}
		
		ChangeClientTeam(client, CS_TEAM_T);
		
		if (isAlive == 1)
		{
			CS_RespawnPlayer(client);
			new deaths = GetClientDeaths(client);
			new frags = GetClientFrags(client);
			deaths -= 1;
			frags += 1;
			SetEntProp(client, Prop_Data, "m_iDeaths", deaths);
			SetEntProp(client, Prop_Data, "m_iFrags", frags);
		}
		
		prevTeam = CS_TEAM_CT;
	}else if(currTeam == CS_TEAM_T && currTeam != prevTeam)
	{		
		if(IsPlayerAlive(client))
		{			
			isAlive = 1;
			//Get player's steamid and store it to a variable. I will need a different variable for each of the players that are chosen
			//I don't need everyone's steamid. Just the ones that were alive. That's why I chose this, but maybe there is better solution..
		}
		
		ChangeClientTeam(client, CS_TEAM_CT);
		
		if (isAlive == 1)
		{
			CS_RespawnPlayer(client);
			new deaths = GetClientDeaths(client);
			new frags = GetClientFrags(client);
			deaths -= 1;
			frags += 1;
			SetEntProp(client, Prop_Data, "m_iDeaths", deaths);
			SetEntProp(client, Prop_Data, "m_iFrags", frags);
		}
		
		prevTeam = CS_TEAM_T;
	}
}

public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
	//Go through all of the stored steamid and check their frags and deaths.
	//If player has 0 deaths and/or 0 kills, I need to fix his stats.
}
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.

Last edited by VJScope; 05-12-2017 at 06:00.
VJScope is offline
peenut
Member
Join Date: Nov 2013
Old 05-12-2017 , 08:16   Re: [CSGO]Probably a simple problem that I just can't figure out...
Reply With Quote #6

Store them in an array?

PHP Code:
char idList[64][64];
int idLength[64];

......

if(
IsPlayerAlive(client))
{            
    
isAlive 1;
    
char authid[64];
    
GetClientAuthId(clientAuthId_Steam3authidsizeof(authid));
    
idList[idLength][0] = authid;
    
idLength++;

peenut 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 15:55.


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