Raised This Month: $ Target: $400
 0% 

Random Player on Server.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZeroEntity
New Member
Join Date: Jan 2016
Old 01-12-2016 , 20:47   Random Player on Server.
Reply With Quote #1

Hi, I'm pretty new to this.

It appears I am doing something wrong in my script and if anyone can give some pointers it'd be much appreciated.

I am trying to get a random player that is currently connected to the server, then getting that players name and printing a message to all clients every 60 seconds using that players name in the message string.

I'm also going to randomly select a string from an array of predefined strings but I believe I can manage that.

Thanks, Zero.

Code:
public OnPluginStart()
{
	PrintToServer("Etc Etc Plugin Started");
	TimedEvent();
}

public Action:Timer_Repeat(Handle:Timer)
{
	int rndNum = GetRandomInt(1,5);
	new iClient = GetRandomClient();
	
	decl String:name[32];
	GetClientName(iClient, name, sizeof(name));
	PrintToChatAll("Player %s was randomly chosen.", name);
}

void TimedEvent()
{
	CreateTimer(60.0, Timer_Repeat, _, TIMER_REPEAT);
}

void GetRandomClient()
{
	new clients[MaxClients+1], clientCount;
	for (new i = 1; i <=MaxClients; i++)
	{
		if (IsClientInGame(i))
		{
			clients[clientCount++] = i;
		}
		return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount-1)];
	}
}
ZeroEntity is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-12-2016 , 21:00   Re: Random Player on Server.
Reply With Quote #2

For help with SourceMod, you'll need to post in the SourceMod section.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 09:23.


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