AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random Player on Server. (https://forums.alliedmods.net/showthread.php?t=277641)

ZeroEntity 01-12-2016 20:47

Random Player on Server.
 
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)];
        }
}


fysiks 01-12-2016 21:00

Re: Random Player on Server.
 
For help with SourceMod, you'll need to post in the SourceMod section.


All times are GMT -4. The time now is 09:23.

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