Dont return false with getplayerbyid, return undefined instead and check for that.
Dont getplayername or exists by id, just use the getplayerbyid function with proper checks.
fixchatargs is included in libcod already: https://github.com/voron00/libcod/bl....cpp#L348-L348
I'd check for say_team as well as for say
The way you use the switch() won't work in any other language that gsc most likely, but if it works like this, it works.
Indentation on your for() loop to add the remaining args in pm is terrible
no need to use sayall if you got a clientcommand() at the end of it, that will handle the sayall anyway.
You got a fall-through case in your pm ifs where supplying it with a non-int args[2] will cause you to enter the fps thing (you can try this with !pm asdf)
Lots of duplicate code uisng thirdArgument-like function, while thirdArgument function remains unused
Here's a slightly revised version:
PHP Code:
getPlayerNameById(number)
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i] getentitynumber() == Int(number))
return players[i].name;
}
return false;
}
tellMessage(message)
{
sendgameservercommand(self getentitynumber(), "h \"^2Nanny^7[^3PM^7]: " + message + "\"");
}
tellMessageWorld(message)
{
sendgameservercommand(-1, "h \"^2Nanny^7:" + message + "\"");
}
isint(string)
{
return ((int(string) + "") == string + "");
}
CodeCallback_PlayerCommand(args)
{
if ((args[0] == "say" || args[0] == "say_team") && isDefined(args[1]) && args[1][0] == "!")
{
switch (getSubStr(args[1], 1))
{
case "pm":
{
if (isDefined(args[2]) && isint(args[2]) && isDefined(args[3]))
{
player = getPlayerById(int(args[2]));
if(!isDefined(player))
{
self iprintlnbold("Couldn\'t find a player with this number.");
return;
}
pmmessage = "";
for (i=3; i<args.size; i++)
{
pmmessage += args[i] + " ";
}
sendgameservercommand(self getentitynumber(), "h \"^2Nanny:^7" + " ^3PM to ^7" + player.name + "^7: " + pmmessage + "\"");
sendgameservercommand(targetnum getentitynumber(), "h \"^2Nanny:^7" + " ^3PM from ^7" + self.name + "^3[^7" + self getentitynumber() + "^3]^7" + "^7: " + pmmessage + "\"");
return;
}
else if (!isDefined(args[2]))
{
sendgameservercommand(self getentitynumber(), "h \"^2Nanny^7:" + " ^6Use the clientid to send a private message " + "\"");
return;
}
else
{
//there was a fall-through case here
return; //todo: maybe add an explanation here that you need to put in a number?
}
}
case "fps":
{
if (isDefined(args[2]) && isint(args[2]))
{
player = getPlayerById(int(args[2]));
if(!isDefined(player))
{
self iprintlnbold("Couldn\'t find a player with this number.");
return;
}
self ClientCommand();
tellMessageWorld(player.name + " FPS: " + player getFps());
return;
}
else if(!isDefined(args[2]))
{
self ClientCommand();
tellMessageWorld(self.name + " FPS: " + self getFps());
return;
}
else
{
tellMessage("no name found");
return;
}
}
}
}
self ClientCommand();
}