Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: display admins in message

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    display admins in message

    Hi all,

    I made a !comment that will show the admins who are on the server
    Code:
    		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.
    Code:
    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

  2. #2
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    Maybe show
    Code:
    tellmessage(mp)
    ??

  3. The Following User Says Thank You to maxdamage99 For This Useful Post:

    kung foo man (17th October 2015)

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Code:
    tellMessage(message)
    {
    		sendgameservercommand(self getentitynumber(), "h \"console: " + message + "\"");
    		//sendgameservercommand(-1, "h \"" + self.name + "^7: " + command + "\"");  
    }

  5. #4
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Using http://jsbeautifier.org/:

    PHP Code:
            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 (
    0players.sizei++) {
                    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 (
    0players_to_admins.sizei++)
                        
    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:

    PHP Code:
                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 (
    0players_to_admins.sizei++)
                        
    mp += players_to_admins[i].name "^1(^7" players_to_admins[i].loginname "^1)" " ";
                } else {
                    
    mp "No Admins online";
                } 
    timescale 0.01

  6. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Now there isnt any message shown at all
    Code:
    Param 1 needs to be a string, >make function for this<=0 given! NumParams=2

  7. #6
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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.
    timescale 0.01

  8. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    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
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. #8
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    PHP Code:
    showadmins()
    {
    admins="";
    players getentarray("player""classname");
    for(
    0players.sizei++)
    {
    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
    Last edited by maxdamage99; 31st October 2015 at 07:55.

  10. The Following User Says Thank You to maxdamage99 For This Useful Post:

    Ni3ls (1st January 2016)

  11. #9
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    PHP Code:
    showadmins()
    {
        
    admins="";
        
    players getentarray("player""classname");
        for(
    0players.sizei++)
        {
            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.

  12. The Following User Says Thank You to filthy_freak_ For This Useful Post:

    Ni3ls (1st January 2016)

  13. #10
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    Ty : )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •