PDA

View Full Version : display admins in message



Ni3ls
17th October 2015, 16:55
Hi all,

I made a !comment that will show the admins who are on the server

case "admins":
if(!isdefined(self.pers["admin"]) || self.pers["admin"] <1)
{
//self iprintlnbold("RANK: "+self.rank);
self iprintlnbold("No Admin");
return;
}
players_to_admins = []; // changed
players = getentarray("player", "classname");
for (i = 0; i < players.size; i++)
{
if (players[i].pers["admin"] == 1)
players_to_admins[players_to_admins.size] = players[i]; // changed

}

if (players_to_admins.size == 1)
{
mp = "Admins online: ";
mp += players_to_admins[0].name + "^1(^7"+players_to_admins[0].loginname + "^1)" + " ";
}
else if (players_to_admins.size >= 2)
{
mp = "Admins online: ";
for (i = 0; i < players_to_admins.size; i++)
mp += players_to_admins[i].name + "^1(^7"+players_to_admins[i].loginname + "^1)" + " ";
}
else
{
mp = "No Admins online";
}

self thread tellMessage(mp);
return;

For 1 player and 0 admins it works. However, when there are more than 1 admins, the message isnt shown.

Param 0 needs to be an int, >make function for this<=0 given! NumParams=2
Param 1 needs to be a string, >make function for this<=0 given! NumParams=2
1 of those is the error :P

maxdamage99
17th October 2015, 17:01
Maybe show


tellmessage(mp)

??

Ni3ls
17th October 2015, 17:32
tellMessage(message)
{
sendgameservercommand(self getentitynumber(), "h \"console: " + message + "\"");
//sendgameservercommand(-1, "h \"" + self.name + "^7: " + command + "\"");
}

kung foo man
17th October 2015, 21:40
Using http://jsbeautifier.org/:



case "admins":
if (!isdefined(self.pers["admin"]) || self.pers["admin"] < 1) {
//self iprintlnbold("RANK: "+self.rank);
self iprintlnbold("No Admin");
return;
}
players_to_admins = []; // changed
players = getentarray("player", "classname");
for (i = 0; i < players.size; i++) {
if (players[i].pers["admin"] == 1)
players_to_admins[players_to_admins.size] = players[i]; // changed

}

if (players_to_admins.size == 1) {
mp = "Admins online: ";
mp += players_to_admins[0].name + "^1(^7" + players_to_admins[0].loginname + "^1)" + " ";
} else if (players_to_admins.size >= 2) {
mp = "Admins online: ";
for (i = 0; i < players_to_admins.size; i++)
mp += players_to_admins[i].name + "^1(^7" + players_to_admins[i].loginname + "^1)" + " ";
} else {
mp = "No Admins online";
}

self thread tellMessage(mp);
return;


The variable "mp" is local INSIDE the if, outside it will be undefined. Just declare it beforehand:



mp = ""; // FIX
if (players_to_admins.size == 1) {
mp = "Admins online: ";
mp += players_to_admins[0].name + "^1(^7" + players_to_admins[0].loginname + "^1)" + " ";
} else if (players_to_admins.size >= 2) {
mp = "Admins online: ";
for (i = 0; i < players_to_admins.size; i++)
mp += players_to_admins[i].name + "^1(^7" + players_to_admins[i].loginname + "^1)" + " ";
} else {
mp = "No Admins online";
}

Ni3ls
18th October 2015, 08:00
Now there isnt any message shown at all

Param 1 needs to be a string, >make function for this<=0 given! NumParams=2

kung foo man
18th October 2015, 08:31
There is no libcod function called whose first argument is a string, so you either changed sendgameservercommand() to something else or the error is now somewhere else. Just add a bunch of "printf(a, b, c)", it will automatically iterate over the arguments and stringify them if possible.

IzNoGoD
18th October 2015, 11:44
Mostly that error happens when you send an undefined var to a function expecting a non-undefined var.

did you try with developer 1 yet

maxdamage99
31st October 2015, 07:44
showadmins()
{
admins="";
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i].permissions["admin"])
{
if(admins=="")
{
admins+=monotone(players[i].name);
}
else if(admins!="")
{
admins+="^7, "+monotone(players[i].name);
}
}
else if(admins=="" && i==players.size)
{
sendGameServerCommand(self getEntityNumber(), "h \""+level.consolename+"^3Admins ^7are not present on the server \"");
}
}
if(admins!="")
sendGameServerCommand(self getEntityNumber(), "h \""+level.consolename+"^3Admins^7: "+admins+" \"");
}

Show message:
myserver: Admins: Admin name1, Admin name2, Admin name3
or
myserver: Admins are not present on the server

filthy_freak_
31st October 2015, 08:03
showadmins()
{
admins="";
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i].permissions["admin"])
{
if(admins.size)
admins += "^7, " + monotone(players[i].name);
else
admins += monotone(players[i].name);
}
}
if(admins.size)
sendGameServerCommand(self getEntityNumber(), "h \"" + level.consolename + "^3Admins^7: " + admins + " \"");
else
sendGameServerCommand(self getEntityNumber(), "h \"" + level.consolename + "^3Admins ^7are not present on the server \"");
}


Same code as above but easier to read.

maxdamage99
31st October 2015, 08:06
Ty : )

Kemi
13th November 2015, 14:26
I created the exact same command for my CoD4 mod, heres what I used:


case "admins":
thread checkForAdmins();
break;

Called upon function:


checkForAdmins()
{
string = "";
players = getentarray( "player", "classname" );
for( i = 0; i < players.size; i++ )
{
if(!isDefined(players[i].masked))
players[i].masked = 0;
if(!isDefined(players[i].mask))
players[i].mask = players[i] getPower();
players[i].rank = "";
if(int(players[i].masked) == 1)
{
players[i].rank = players[i].mask;
}
if( players[i].rank >= 10) //If the players rank is above 10 they are classified as an admin
{
if(int(players[i].masked) != 1)
players[i].rank
if(int(players[i].mask) != 0 || int(players[i].mask) != 1)
string = string + players[i].name + " ^3[^7" + players[i].rank + "^3], ^7";
}
}
exec( "say Admins online: " + string );
//iPrintLnBold( string );
}