Results 1 to 7 of 7

Thread: player command am i going in the right direction

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    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(
    0players.sizei++) 
        {
            if(
    players[igetentitynumber() == 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=3i<args.sizei++)
                        {
                            
    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();

    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  2. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    Blutus (22nd September 2023),raphael (23rd August 2023)

Posting Permissions

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