Author Topic: This server command will not do ANYTHING.  (Read 605 times)

So I'm trying to re-do my old add-on v18 broke, and I'm trying to re-create the color change command.
Code: [Select]
$SIAversion = "0.2";
$SIAbuild = "6-6";
$line1c = "FF3344";
$line2c = "FFEE00";
$line3c = "44CC77";
$line4c = "3388FF";
messageAll('',"Executed Server Info Announcer 2 version " @ $SIAversion @ " (build " @ $SIAbuild @ ")");

function getHostsName()
{
$hostsname = $pref::Player::NetName;
}
getHostsName();

function DoSIAAnnounce(%client)
{
$bricks = $Server::BrickCount;
$players = $Server::PlayerCount @ "/" @ $Pref::Server::MaxPlayers;
for(%i = 0; %i < ClientGroup.getCount(); %i++)
{
%cl = ClientGroup.getObject(%i);
%cl.perce = %cl.brickGroup.getCount()/$Server::BrickCount*100;
%cl.perce = mFloatLength(%cl.perce,1);
messageClient(%cl,"","<color:" @ $line1c @ ">  >> " @ $hostsname @ "'s " @ $Server::Name);
messageClient(%cl,"","<color:" @ $line2c @ ">  >> There are " @ $bricks @ " bricks in the server, " @ %cl.perce @ "% of which are yours.");
messageClient(%cl,"","<color:" @ $line3c @ ">  >> There are " @ $players @ " players in the server.");
messageClient(%cl,"","<color:" @ $line4c @ ">  >> You have a " @ %cl.getPing() @ " ms. delay with the server.");
}
}

-----> function servercmdSetSIAColor(%client,%servername,%brickcount,%playercount,%playerlag)
{
if(%client.isHost)
{
$line1c = %servername;
$line2c = %brickcount;
$line3c = %playercount;
$line4c = %playerlag;
messageAll('',"<color:00ffff>" @ $hostsname @ " has changed the announcer colors to " @ %servername @ ", " @ %brickcount @ ", " @ %playercount @ ", and " @ %playerlag @ ".");
}
}

And it does absolutely nothing.

1. %client.isHost is undefined. You need a package that sets it when the player connects. <- problem
2. You're using global variables when you should be using local variables (%) <- advice

1. %client.isHost is undefined. You need a package that sets it when the player connects. <- problem

Paste this at the bottom of your code / in another file and exec it to use .isHost:

Code: [Select]
package isHost
{
function GameConnection::autoAdminCheck(%this)
{
%this.isHost = (%this.isLocalConnection() || %this.bl_id == getNumKeyID());
return Parent::autoAdminCheck(%this);
}
};
activatePackage(isHost);

2. You're using global variables when you should be using local variables (%) <- advice

Yeah, you'll (OP, not Dest) make this transition pretty quickly when you start coding more.