Author Topic: clientcmd and messageclient aren't working in the script. - Solved.  (Read 1195 times)

Torque is loving with my mind. Anyways, I have the following.

Code: [Select]
function timetochoose(%client) {
echo("Client = " @ %client);
schedule(0,0,"commandToClient",%client, 'bottomPrint', "\c2" @ $MapChange::BottomPrint);
schedule(0,0,"messageclient",%client, '',"\c2Use /pick # to vote for the next map!");
%client.playSound(TimeToChoose);
}

The schedules are there because it wouldn't send the bottomprint nor the text message before (and it still doesn't) so I added them to see if it would work on the next frame.

Anyways, the sound TimeToChoose is being played to the client, echo echoes a valid client ID but messageclient and commandtoclient are being rebellious. Any ideas why? If they're typed manually into the console (replacing %client with findclientbyname("P")), they work as intended.



Quick addition, the function is being called via
Code: [Select]
for(%i = 0; %i < clientGroup.getCount(); %i++)
{
%client = clientGroup.getObject(%i);
%client.pickLevel = 0;
echo("Resetting client data.");
if($RoundCount == $RoundBeforeChange) {
echo("Time to choose!");
if(%client.choosing != 1) {
timetochoose(%client);
}
}
}

When I put timetochoose(findclientbyname(P)); into the console, it works as expected. Just not in the code for some reason even when the echo echoes the same client ID.
« Last Edit: September 23, 2015, 01:06:45 PM by Pie Crust »

Try replacing the bottom print with:
%client.bottomPrint(etc,-1);
and the messageClient with:
%client.chatMessage(etc);

And see if that works.

The chatmessage is being shown now but not the bottomprint. I'll try adding a schedule incase it's Slayer who's bugging me.



Yep, it was definitely Slayer.

Slayer shouldn't interfere with those functions. (I don't believe it packages either of them) What are you trying to do?

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.
Code: [Select]
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!");
}
}

Slayer shouldn't interfere with those functions. (I don't believe it packages either of them) What are you trying to do?
They were being called before Slayer clears the client's data. (Kills, score, center/bottomprints, etc)