Results 1 to 7 of 7

Thread: player command am i going in the right direction

  1. #1
    ... connecting
    Join Date
    Aug 2022
    Posts
    4
    Thanks
    5
    Thanked 1 Time in 1 Post

    player command am i going in the right direction

    i have been trying to write some code.
    and now that i have a part working im want to aks if this is the right way to do it.

    the code:

    PHP Code:
    checkIfExist(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetentitynumber() == Int(number))
                return 
    true;
        }
        return 
    false;    
    }

    thirdArgument(args)
    {
        
    text "";
        for(
    i=3i<args.sizei++)
            
    text += args[i] + " ";
        return 
    text;
    }

    getPlayerNameById(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetentitynumber() == Int(number))
                return 
    players[i].name;
        }
        return 
    false;
    }

    getPlayerById(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetEntityNumber() == Int(number))
                return 
    players[i];
        }
        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 "");
    }   


    fixChatArgs(args)
    {
        if (
    isDefined(args[1])) { // engine is adding identifier infront of the chat message
            
    if (getAscii(args[1][0]) >= 20 && getAscii(args[1][0]) <= 22) {
                
    //std\io::print("delete bad ascii code: " + std\utils::getAscii(args[1][0]) + "\n");
                
    args[1] = getSubStr(args[1], 1);
                
    newArgs strTok(args[1], " ");
                for (
    i=0i<newArgs.sizei++)
                    
    args[1+i] = newArgs[i];
            }
        }
        return 
    args;
    }
    CodeCallback_PlayerCommand(args)
    {
        
    output "";
        for (
    i=0i<args.sizei++)
            
    output += args[i] + ", ";
        
        
    //std\io::print("PLAYER COMMAND! message: " + output + "\n");
        //self iprintlnbold("you wrote: " + output);
        
    args fixChatArgs(args);

        
        if (
    args[0] == "say" && isDefined(args[1]) && args[1][0] == "!")    
        {

            
            switch (
    getSubStr(args[1], 1))
            {
                case 
    "pm":
                
                    if (
    isDefined(args[2]) && isint(args[2]) && isDefined(args[3])) 
                    {                      
                        
    args[2] = int(args[2]);
                        if(!
    checkIfExist(args[2]))
                        {
                            
    self iprintlnbold("Couldn\'t find a player with this number.");
                            return;
                        }
                        
                        
            
                    
    pmmessage "";
                    for (
    i=3i<args.sizei++)
            
                    
    pmmessage += args[i] + " ";
                    
    targetnum getPlayerById(args[2]);
                    
    targetname getPlayerNameById(args[2]);
                    
    sendname self.name;
                    
    sendid self getentitynumber();
        
                    
    sendgameservercommand(self getentitynumber(), "h \"^2Nanny:^7" " ^3PM to ^7" targetname "^7: " pmmessage "\"");
                    
    sendgameservercommand(targetnum getentitynumber(), "h \"^2Nanny:^7" " ^3PM from ^7" sendname "^3[^7" sendid "^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;
                        }
        
                case 
    "fps":
                
                    if (
    isDefined(args[2]) && isint(args[2])) 
                    {   
                        
    firstmessage "";
                        for (
    i=1i<args.sizei++)
                        
    firstmessage += args[i] + " ";
            
                        
    self sayall(firstmessage);
                        
                        
    args[2] = int(args[2]);
                        if(!
    checkIfExist(args[2]))
                        {
                            
    self iprintlnbold("Couldn\'t find a player with this number.");
                            return;
                        }

            
                    
                    
    targetnum getPlayerById(args[2]);
                    
    targetname getPlayerNameById(args[2]);
                    
    fpstarget targetnum getFps();
        
                    
    tellMessageWorld(targetname " FPS: " fpstarget);
                    return;
                    }
                    
                    if (!
    isDefined(args[2]))
                    {    
                        
    firstmessage "";
                        for (
    i=1i<args.sizei++)
                        
    firstmessage += args[i] + " ";
            
                        
    self sayall(firstmessage);
                        
                        
    fpsself self getFps();
                        
    sendname self.name;
                        
    tellMessageWorld(sendname " FPS: " fpsself);
                        return;
                    }
                    else
                    {
                        
    tellMessage("no name found");
                        return;
                    }

            }
        }
        
        
    self ClientCommand();


    whole script _callbacksetup.gsc
    PHP Code:
    // Callback Setup
    // This script provides the hooks from code into script for the gametype callback functions.

    //================================================== ===========================
    // Code Callback functions

    /*================
    Called by code after the level's main script function has run.
    ================*/
    CodeCallback_StartGameType()
    {
    // If the gametype has not beed started, run the startup
    if(!isDefined(level.gametypestarted) || !level.gametypestarted)
    {
    //disableGlobalPlayerCollision(); // libcod: disable player collisions
    thread consoleName();
    thread sayw();
    [[
    level.callbackStartGameType]]();
    level.gametypestarted true// so we know that the gametype has been started up
    }
    }

    /*================
    Called when a player begins connecting to the server.
    Called again for every map change or tournement restart.

    Return undefined if the client should be allowed, otherwise return
    a string with the reason for denial.

    Otherwise, the client will be sent the current gamestate
    and will eventually get to ClientBegin.

    firstTime will be qtrue the very first time a client connects
    to the server machine, but qfalse on map changes and tournement
    restarts.
    ================*/
    CodeCallback_PlayerConnect()
    {
    self endon("disconnect");
    [[
    level.callbackPlayerConnect]]();
    }

    /*================
    Called when a player drops from the server.
    Will not be called between levels.
    self is the player that is disconnecting.
    ================*/
    CodeCallback_PlayerDisconnect()
    {
    self notify("disconnect");
    [[
    level.callbackPlayerDisconnect]]();
    }

    /*================
    Called when a player has taken damage.
    self is the player that took damage.
    ================*/
    CodeCallback_PlayerDamage(eInflictoreAttackeriDamageiDFlagssMeansOfDeathsWeaponvPointvDirsHitLoctimeOffset)
    {
    self endon("disconnect");
    [[
    level.callbackPlayerDamage]](eInflictoreAttackeriDamageiDFlagssMeansOfDeathsWeaponvPointvDirsHitLoctimeOffset);
    }

    /*================
    Called when a player has been killed.
    self is the player that was killed.
    ================*/
    CodeCallback_PlayerKilled(eInflictoreAttackeriDamagesMeansOfDeathsWeaponvDirsHitLoctimeOffsetdeathAnimDuration)
    {
    self endon("disconnect");
    [[
    level.callbackPlayerKilled]](eInflictoreAttackeriDamagesMeansOfDeathsWeaponvDirsHitLoctimeOffsetdeathAnimDuration);
    }

    //================================================== ===========================

    /*================
    Setup any misc callbacks stuff like defines and default callbacks
    ================*/
    SetupCallbacks()
    {

    SetDefaultCallbacks();
    // Set defined for damage flags used in the playerDamage callback
    level.iDFLAGS_RADIUS 1;
    level.iDFLAGS_NO_ARMOR 2;
    level.iDFLAGS_NO_KNOCKBACK 4;
    level.iDFLAGS_NO_TEAM_PROTECTION 8;
    level.iDFLAGS_NO_PROTECTION 16;
    level.iDFLAGS_PASSTHRU 32;
    }

    /*================
    Called from the gametype script to store off the default callback functions.
    This allows the callbacks to be overridden by level script, but not lost.
    ================*/
    SetDefaultCallbacks()
    {
    level.default_CallbackStartGameType level.callbackStartGameType;
    level.default_CallbackPlayerConnect level.callbackPlayerConnect;
    level.default_CallbackPlayerDisconnect level.callbackPlayerDisconnect;
    level.default_CallbackPlayerDamage level.callbackPlayerDamage;
    level.default_CallbackPlayerKilled level.callbackPlayerKilled;
    }

    /*================
    Called when a gametype is not supported.
    ================*/
    AbortLevel()
    {
    println("Aborting level - gametype is not supported");
    level.callbackStartGameType = ::callbackVoid;
    level.callbackPlayerConnect = ::callbackVoid;
    level.callbackPlayerDisconnect = ::callbackVoid;
    level.callbackPlayerDamage = ::callbackVoid;
    level.callbackPlayerKilled = ::callbackVoid;
    setcvar("g_gametype""dm");
    exitLevel(false);
    }

    /*================
    ================*/
    callbackVoid()
    {
    }

    consoleName()
    {
    for (;;)
    {
    if (
    getCvar("consoleName") != "")
    {
    level.consoleName getCvar("consoleName");
    }
    wait 0.05;
    }
    }

    sayw()
    {
    setcvar("sayw""");
    for (;;)
    {
    if (
    getCvar("sayw") != "")
    {
    message getCvar("sayw");
    sendGameServerCommand(-1"h \"" level.consoleName "^7: " message "\"");
    setcvar("sayw""");
    }
    wait 0.05;
    }
    }

    checkIfExist(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetentitynumber() == Int(number))
                return 
    true;
        }
        return 
    false;    
    }

    thirdArgument(args)
    {
        
    text "";
        for(
    i=3i<args.sizei++)
            
    text += args[i] + " ";
        return 
    text;
    }

    getPlayerNameById(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetentitynumber() == Int(number))
                return 
    players[i].name;
        }
        return 
    false;
    }

    getPlayerById(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetEntityNumber() == Int(number))
                return 
    players[i];
        }
        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 "");
    }   


    fixChatArgs(args)
    {
        if (
    isDefined(args[1])) { // engine is adding identifier infront of the chat message
            
    if (getAscii(args[1][0]) >= 20 && getAscii(args[1][0]) <= 22) {
                
    //std\io::print("delete bad ascii code: " + std\utils::getAscii(args[1][0]) + "\n");
                
    args[1] = getSubStr(args[1], 1);
                
    newArgs strTok(args[1], " ");
                for (
    i=0i<newArgs.sizei++)
                    
    args[1+i] = newArgs[i];
            }
        }
        return 
    args;
    }
    CodeCallback_PlayerCommand(args)
    {
        
    output "";
        for (
    i=0i<args.sizei++)
            
    output += args[i] + ", ";
        
        
    //std\io::print("PLAYER COMMAND! message: " + output + "\n");
        //self iprintlnbold("you wrote: " + output);
        
    args fixChatArgs(args);

        
        if (
    args[0] == "say" && isDefined(args[1]) && args[1][0] == "!")    
        {

            
            switch (
    getSubStr(args[1], 1))
            {
                case 
    "pm":
                
                    if (
    isDefined(args[2]) && isint(args[2]) && isDefined(args[3])) 
                    {                      
                        
    args[2] = int(args[2]);
                        if(!
    checkIfExist(args[2]))
                        {
                            
    self iprintlnbold("Couldn\'t find a player with this number.");
                            return;
                        }
                        
                        
            
                    
    pmmessage "";
                    for (
    i=3i<args.sizei++)
            
                    
    pmmessage += args[i] + " ";
                    
    targetnum getPlayerById(args[2]);
                    
    targetname getPlayerNameById(args[2]);
                    
    sendname self.name;
                    
    sendid self getentitynumber();
        
                    
    sendgameservercommand(self getentitynumber(), "h \"^2Nanny:^7" " ^3PM to ^7" targetname "^7: " pmmessage "\"");
                    
    sendgameservercommand(targetnum getentitynumber(), "h \"^2Nanny:^7" " ^3PM from ^7" sendname "^3[^7" sendid "^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;
                        }
        
                case 
    "fps":
                
                    if (
    isDefined(args[2]) && isint(args[2])) 
                    {   
                        
    firstmessage "";
                        for (
    i=1i<args.sizei++)
                        
    firstmessage += args[i] + " ";
            
                        
    self sayall(firstmessage);
                        
                        
    args[2] = int(args[2]);
                        if(!
    checkIfExist(args[2]))
                        {
                            
    self iprintlnbold("Couldn\'t find a player with this number.");
                            return;
                        }

            
                    
                    
    targetnum getPlayerById(args[2]);
                    
    targetname getPlayerNameById(args[2]);
                    
    fpstarget targetnum getFps();
        
                    
    tellMessageWorld(targetname " FPS: " fpstarget);
                    return;
                    }
                    
                    if (!
    isDefined(args[2]))
                    {    
                        
    firstmessage "";
                        for (
    i=1i<args.sizei++)
                        
    firstmessage += args[i] + " ";
            
                        
    self sayall(firstmessage);
                        
                        
    fpsself self getFps();
                        
    sendname self.name;
                        
    tellMessageWorld(sendname " FPS: " fpsself);
                        return;
                    }
                    else
                    {
                        
    tellMessage("no name found");
                        return;
                    }

            }
        }
        
        
    self ClientCommand();


    i didnt write most parts myselft, but i put different codes together.
    what im asking is:

    - is the way to send the reply good?
    - is the return statement good for the switch case or should it be break?
    - should this be or stay in this script or should i write it in a seperate script and only call that script from the callbacksetup?

    thanks
    Last edited by Blutus; 21st August 2023 at 19:12.

  2. #2
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts
    Do you use Nanny? if so, why?

    libcod has a getFps function allowing you to get the com_maxfps value of players?
    Last edited by raphael; 25th August 2023 at 12:18.

  3. #3
    ... connecting
    Join Date
    Aug 2022
    Posts
    4
    Thanks
    5
    Thanked 1 Time in 1 Post
    the script is working.

    im using libcod.
    when players type !fps command the getfps() gets the actual fps value of the player or self.
    What i am asking is if this is the way to do it, and what flaws i put in.

    i am using nanny but it is thirdparty software and i wanted to write in in cod gsc script to make it send pm message and handle more message at the same time.
    and because im just starting it isnt a lot of work to change before i start writing the rest of the code.

    oh i see now because of the name Nanny, i just used that name for the console from the nanny code and still use that now.
    Last edited by Blutus; 22nd August 2023 at 16:37.

  4. The Following User Says Thank You to Blutus For This Useful Post:

    raphael (23rd August 2023)

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,725
    Thanks
    17
    Thanked 1,080 Times in 682 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

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

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

  7. #5
    ... connecting
    Join Date
    Aug 2022
    Posts
    4
    Thanks
    5
    Thanked 1 Time in 1 Post
    thanks for the tips i will use that to understand the script better.
    i noticed the fall trough case with pm but wasnt sure why.
    i think i updated the script already before i got awnsers but will use the tips to change the script.

  8. #6
    ... connecting
    Join Date
    Aug 2022
    Posts
    4
    Thanks
    5
    Thanked 1 Time in 1 Post
    Script update

    PHP Code:
    getPlayerNameById(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetentitynumber() == Int(number))
                return 
    players[i].name;
        }
        return 
    undefined;
    }

    getPlayerById(number)
    {
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetEntityNumber() == Int(number))
                return 
    players[i];
        }
        return 
    undefined;
    }

    getPlayerByName(name)
    {
        
    name checkname(name);
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    tolower(stripcolors(players[i].name)) == name)
                return 
    players[i];
        }
        return 
    undefined;

    }

    checkname(name)
    {
        
    name tolower(stripcolors(name)); //strip colors, remove capitals
        
    return name;
    }

    // strip a players name from color ^characters with numbers, and spaces 
    stripcolors(string)
    {
        
    gotcolors true;
        
        while(
    gotcolors)
        {
            
    gotcolors false;
            for(
    0string.size 1i++)
            {
                if(
    string[i] == "^" && isint(string[1]))
                {
                    
    newstring "";
                    if(
    0)
                        
    newstring += getsubstr(string0i);
                    if(
    string.size 2)
                        
    newstring += getsubstr(string2);
                    
    string newstring;
                    
    gotcolors true;
                    break;
                }
            }
        }
        
    gotspaces true;

        while(
    gotspaces)
        {    
            
    gotspaces false;
            for(
    0string.size 1i++)
            {
                if(
    string[i] == " ")
                {
                    
    newstring "";
                    if(
    0)
                        
    newstring += getsubstr(string0i);
                    if(
    string.size 2)
                        
    newstring += getsubstr(string1);
                    
    string newstring;
                    
    gotspaces true;
                    break;
                }
            }
        }

        return 
    string;
    }

    // used to send a pm message to self player
    tellMessage(message)
    {
        
    sendgameservercommand(self getentitynumber(), "h \"^2Nanny^7[^3PM^7]: " message "\"");
    }

    // to show color and characters of the players name in chat
    chat(message)
    {
        
    sendgameservercommand(-1"h \"" self.name "^7: " message "\"");
    }

    // should be a gameservercommand that replies in team chat with full name
    chatteam(message)
    {
        
    self sayTeam(message);
    }

    // used to send a chat message to everyone
    tellMessageWorld(message)
    {
        
    sendgameservercommand(-1"h \"^2Nanny^7:" message "\"");
    }

    // used to send a PM message from player to player
    tellMessageTarget(playermessage)
    {
        
    sendgameservercommand(player getentitynumber(), "h \"^2Nanny^7:" message "\"");
    }

    // not sure but makes from an INT a string?
    mijnstring(string)
    {  
        return ((
    int(string) + "") == string "");
    }

    isint(char)
    {
        
    asc getAscii(char);
        return 
    asc <= 57 && asc >= 48;   
    }


    CodeCallback_PlayerCommand(args)
    {

        if ((
    args[0] == "say" || args[0] == "say_team") && isDefined(args[1]) && args[1][0] == "!")    
        {
            
    printchat "";
            for (
    i=1i<args.sizei++)
            {
                
    printchat += args[i] + " ";
            }
                        
            
    LogPrint(getLocalTime() + " " self getIp() + " " self getGuid() + " " self.name ": " printchat "\n");

            switch (
    getSubStr(args[1], 1))
            {          
            
                case 
    "pm":
                {
                    if (
    isDefined(args[2]) && mijnstring(args[2])) 
                    {                      
                       
    player getPlayerById(int(args[2]));
                        if(!
    isDefined(player))
                        {
                            
    tellMessage("^4Couldn\'t find a player with this number.");
                            return;
                        }
                        if(
    isDefined(player) && !isDefined(args[3]))
                        {
                            
    tellMessage("^4No message?");
                            return;
                        }
                                                    
                        
    pmmessage "";
                        for (
    i=3i<args.sizei++)
                        {
                        
    pmmessage += args[i] + " ";
                        }
        
                        
    tellMessage("^3PM to ^7" player.name "^3[^7" player getEntityNumber() + "^3]^7: " pmmessage); //shows the player who you send it to and the message
                        
    tellMessageTarget(player" ^3PM from ^7" self.name "^3[^7" self getEntityNumber() + "^3]^7: " pmmessage); //shows the name and clientID from the player who send the message to the receiver                
                        
    return;
                    }

                    if (
    isDefined(args[2]) && !mijnstring(args[2])) 
                    {                      
                       
    player getPlayerByName(args[2]);
                        if(!
    isDefined(player))
                        {
                            
    tellMessage("^4Couldn\'t find a player with this name.");
                            return;
                        }
                        if(
    isDefined(player) && !isDefined(args[3]))
                        {
                            
    tellMessage("^4No message?");
                            return;
                        }
                                                    
                        
    pmmessage "";
                        for (
    i=3i<args.sizei++)
                        {
                        
    pmmessage += args[i] + " ";
                        }
        
                        
    tellMessage("^3PM to ^7" player.name "^3[^7" player getEntityNumber() + "^3]^7: " pmmessage); //shows the player who you send it to and the message
                        
    tellMessageTarget(player" ^3PM from ^7" self.name "^3[^7" self getEntityNumber() + "^3]^7: " pmmessage); //shows the name and clientID from the player who send the message to the receiver                
                        
    return;
                    }

                    else if (!
    isDefined(args[2]))
                    {                    
                        
    tellMessage("^4Use clientId for private message");
                        return;
                    }
                    else 
                    {
                        
    tellMessage("^4Use clientId, im working on using player name to send PM!");
                        return;
                    }
                } 
    // end pm
                        
                    
                
    case "fps":
                {
                    if (
    isDefined(args[2]) && mijnstring(args[2]))   
                    {                                
                        
    player getPlayerById(int(args[2]));
                        if(!
    isDefined(player))
                        {
                            
    tellMessage("^4Couldn\'t find a player with this number.");
                            return;
                        }
                        
    chat "";
                        for (
    i=1i<args.sizei++)
                        {
                            
    chat += args[i] + " ";
                        }
                        
                        
    chat(chat);
                        
    tellMessageWorld(player.name " FPS: " player getFps());
                        return;
                    }

                    if (
    isDefined(args[2]) && !mijnstring(args[2]))   
                    {                                
                        
    player getPlayerByName(args[2]);
                        if(!
    isDefined(player))
                        {
                            
    tellMessage("^4Couldn\'t find a player with this name.");
                            return;
                        }
                        
    chat "";
                        for (
    i=1i<args.sizei++)
                        {
                            
    chat += args[i] + " ";
                        }
                        
                        
    chat(chat);
                        
    tellMessageWorld(player.name " FPS: " player getFps());
                        return;
                    }
                    else if(!
    isDefined(args[2]))
                    {
                        
    chat "";
                        for (
    i=1i<args.sizei++)
                        {
                            
    chat += args[i] + " ";
                        }

                        
    chat(chat);
                        
    tellMessageWorld(self.name " FPS: " self getFps());
                        return;
                    }
                    else
                    {
                        
    tellMessage("no name found");
                        return;
                    }
                } 
    // end fps

                
    case "id":
                {
                    
    // Sends a list of al players + ID as pm to the player
                    
    if (isDefined(args[2]) && IsString(args[2]) && args[2] == "all")
                    {
                            
    tellMessage("id all comand" args[2]);
                            
    players getentarray("player""classname");

                            for(
    0players.sizei++)
                            {
                                
    tellMessage(players[i].name "^7 id: " players[igetEntityNumber());                            
                                
    wait(0.05);
                                                    
                            }
                            
    tellMessage("That are all players");
                            return;                                            
                    }

                    
    // shows the id of the searched player name
                    
    if (isDefined(args[2]) && !mijnstring(args[2]))   
                    {                                
                        
    player getPlayerByName(args[2]);
                        if(!
    isDefined(player))
                        {
                            
    tellMessage("^4Couldn\'t find a player with this name.");
                            return;
                        }

                        
    stripname checkname(player.name); 
                        
    tellMessage(player.name "^7 id: " player getEntityNumber() + "^7 stripped name: " stripname);
                        return;
                    }

                    
    // shows the name of the searched id
                    
    if (isDefined(args[2]) && mijnstring(args[2]))   
                    {                                
                        
    player getPlayerById(int(args[2]));
                        if(!
    isDefined(player))
                        {
                            
    tellMessage("^4Couldn\'t find a player with this number.");
                            return;
                        }

                        
    stripname checkname(player.name); 
                        
    tellMessage(player.name "^7 id: " player getEntityNumber() + "^7 stripped name: " stripname);
                        return;
                    }                                                                                             

                    
    // shows your name with id as chat message
                    
    if (!isDefined(args[2]))
                        {                  
                            
    tellMessage("Name: " self.name "^7 id: " self getEntityNumber());
                            return;
                        }
                    else
                    {
                        
    tellMessage("command unknown");
                        return;
                    }                            

                    
                } 
    // end id

            
    //switch
        
    // if say and sayteam !

        // to make the names in chat show with colors and characters
        
    if ((args[0] == "say") && isDefined(args[1]))
            {
                
    chat "";
                        for (
    i=1i<args.sizei++)
                        {
                        
    chat += args[i] + " ";
                        }
                
    chat(chat);
                
    LogPrint(chat "\n");
                return;
            }

        
    // to make the names in team chat show with colors and characters
        // SAY_TEAM DOESTN WORK AS LIKE THAT
        // NOT SURE IF SENDGAMESERVERCOMMAND CAN TALK IN TEAM CHAT
        
    if ((args[0] == "say_team") && isDefined(args[1]))
            {
                
    chat "";
                        for (
    i=1i<args.sizei++)
                        {
                        
    chat += args[i] + " ";
                        }
                
    chatteam(chat);           
                
    LogPrint(getLocalTime() + " " self getIp() + " " self getGuid() + " " self.name ": " chat "\n");
                return;
            }

        
    self ClientCommand();
        return;
    }  
    //CodeCallback_PlayerCommand 

    And is this a good way to check players for guid or ip to give rights to commands?

    PHP Code:
    case "check":
                {
                    
    playerip getCvar("sv_ip_blutus");
                    
    playersubip getSubstr
                    playerguidstring 
    getCvar("sv_guid_blutus");
                    
    //tellMessage("sv_ip_blutus = " + playerip);
                    
    checkip self getIp();
                    
    //tellMessage("checkip = " + checkip);
                    
    checkguid self getguid();
                    
    playerguid int(playerguidstring);

                    
        
    players getentarray("player""classname");
        for(
    0players.sizei++) 
        {
            if(
    players[igetIp() == number)
            return 
    players[i];
        }
        


                    
    chat "";
                        for (
    i=1i<args.sizei++)
                        {
                        
    chat += args[i] + " ";
                        }
                   
                    
                    if (!
    isDefined(playerip) && !isDefined(playerguid))
                    {
                        
    tellMessageworld("ip undefined and guid undefined");
                        
    LogPrint(getLocalTime() + " " self getIp() + " " self getGuid() + " " self.name ": " chat "\n");
                        return;
                    }
                    if (
    isDefined(playerip) && !isDefined(checkip))
                    {
                        
    tellMessageworld("check ip undefined player ip: " playerip);
                        
    LogPrint(getLocalTime() + " " self getIp() + " " self getGuid() + " " self.name ": " chat "\n");
                        return;
                    }
                    if (
    isDefined(checkip) && checkip == playerip)
                    {
                        
    tellMessageworld("there is a match: " playerip " == " checkip);
                        
    printf(self.name "^7: " "there is a match: " playerip " == " checkip "\n""console" );
                        
    LogPrint(getLocalTime() + " " self getIp() + " " self getGuid() + " " self.name ": " chat "\n");

                        
    wait 5.05;
                        if (
    mapexists("mp_toujane"))
                        {
                            
    wait 5.05;
                            
    map("mp_toujane");
                            return;
                        }
                        
    tellMessageworld("map doesnt exist");
                        
    LogPrint(getLocalTime() + " " self getIp() + " " self getGuid() + " " self.name ": " chat "\n");
                        return;
                    } 

  9. #7
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 451 Times in 305 Posts
    You could cache the stripped player name with this callback and on connect:

    PHP Code:
    CodeCallback_UserInfoChanged(clientNum)
    {
        
    oldname self.name;
        
    name self get_userinfo("name");

        
    self clientuserinfochanged();

    This is how I remove the color tags and spaces:
    PHP Code:
    stripColorsAndSpaces(t)
    {
        if(!
    IsSubStr(t"^") && !IsSubStr(t" "))
            return 
    t// colorless spaceless text
        
        
    "";    
        for(
    i=0;i<t.size;i++)
        {
            if(
    t.size i+&& t[i] == "^" && t[i+1] == "^" && isInt(t[i+2]) && isInt(t[i+3]))
                
    += 3// skip ^^xx
            
    else if(t.size i+&& t[i] == "^" && isInt(t[i+1]))
                
    += 1// skip ^x
            
    else if(t[i] != " ")
                
    += t[i]; // append text
        
    }
        
        return 
    n;
    }

    isInt(char)
    {
        
    asc getAscii(char);
        return 
    asc >= 48 && asc <= 57;


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

    Blutus (21st September 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
  •