If you're packing MiniGameSO::onReset(%minigame, %client), make sure you create a schedule, that way if it gets called again it can reset the time instead of repeating it more than once.
Here's an example of choosing a random client using MiniGameSO functions, if they leave or join it resets them in case they were choosen. Sorry if it is too much, just giving an example.
package aaa
{
function MiniGameSO::onReset(%this, %client)
{
//Parent something that already exists by default
Parent::onReset(%this, %client);
//Make sure no one is choosen
MiniGame_ResetPick(%this);
//Cancel the schedule if it exists
if(isEventPending($MinigameStartThingy))
cancel($MinigameStartThingy);
//Start a schedule to pick someone.
$MinigameStartThingy = schedule(500, 0, "MiniGame_Start");
}
function MiniGameSO::addMember(%this, %client)
{
//Parent something that already exists by default
Parent::addMember(%this, %client);
//If they joined just reset it if it was somehow on.
%client.isChoosen = 0;
}
function MiniGameSO::removeMember(%this, %client)
{
//Parent something that already exists by default
Parent::removeMember(%this, %client);
//If they left just reset it.
%client.isChoosen = 0;
}
};
activatePackage("aaa");
function MiniGame_ResetPick(%minigame)
{
//Return if there is no object.
if(!isObject(%minigame))
return;
//Make sure there's more than 1 player.
if(%minigame.numMembers <= 0)
return;
//Cycle all members, make sure it is an actual client
for(%i = 0; %i < %minigame.numMembers; %i++)
{
//Set current data.
%member = %minigame.member[%i];
//Check to make sure they exist, and then make sure the class name is a client.
//If it succeeds, they are no longer choosen to be something.
if(isObject(%member) && %member.getClassName() $= "GameConnection")
%member.isChoosen = 0;
}
}
function MiniGame_StartPick(%minigame)
{
//Return if there is no object.
if(!isObject(%minigame))
return;
//Make sure there's more than 1 player.
if(%minigame.numMembers <= 0)
return;
//Cycle all members, make sure it is an actual client
%memberCount = 0;
for(%i = 0; %i < %minigame.numMembers; %i++)
{
//Set current data.
%member = %minigame.member[%i];
//Check to make sure they exist, and then make sure the class name is a client.
if(isObject(%member) && %member.getClassName() $= "GameConnection")
{
//Set the array value.
%member[%memberCount] = %member;
//Increase the amount every time we find one successfully.
%memberCount++;
}
}
//Make sure we have members in our locally stored data in this current function.
if(%memberCount > 0)
{
//Choose someone randomly.
%client = %member[getRandom(0, %memberCount-1)];
//Just to be sure the selected client exists.
if(isObject(%client))
{
//Tell everyone we found someone!
%minigame.messageAll('', '\c4%1 \c6has been choosen for something!', %client.getPlayerName());
%client.isChoosen = 1;
//Blah
}
else
warn("MiniGame_StartPick() - Uh oh! We somehow didn't find the client correctly!");
}
}