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

Random player problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Niak
SourceMod Donor
Join Date: Mar 2011
Location: France
Old 06-26-2014 , 13:48   Random player problem
Reply With Quote #1

Hello,
I am a beginner with sourcemod and i want to choose 2 different players to give one weapon but i don't succeed and i don't know how to do that. The problem is that sometimes it choose the same player for the two stuff. I don't have a clue how to do this. I have try several things, i don't find the solution. I think the best solution is to choose the 2 random players directly but i don't know how to take each player to apply one stuff.

Code:
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
	new player1 = GetRandomPlayer();
	new player2 = GetRandomPlayer();
	
	if(player1 != -1)
	{
		GivePlayerItem(player, "weapon_deagle");
	}
	
	if(player2 != -1)
	{
		GivePlayerItem(murder, "weapon_sawedoff");
	}
}

stock GetRandomPlayer()
{
    new clients[MaxClients+1], clientCount;
	
    for (new i = 1; i <= MaxClients; i++)
	{
        if (IsClientInGame(i))
		{
            clients[clientCount++] = i;
			
			clients[GetRandomInt(0, clientCount + -1)];
		}
	}
	
    return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount-1)];
}
__________________
Niak is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-26-2014 , 13:53   Re: Random player problem
Reply With Quote #2

Replace
Code:
new player2 = GetRandomPlayer();
with

Code:
new player2;
do
{
    player2 = GetRandomPlayer();
} while (player2 == player1);
Note that if only one player is on, this will enter into an infinite loop.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-26-2014 at 13:54.
Powerlord is offline
Niak
SourceMod Donor
Join Date: Mar 2011
Location: France
Old 06-26-2014 , 14:16   Re: Random player problem
Reply With Quote #3

Thank you very much sincerely, it work fine !
__________________
Niak 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 18:17.


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