1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

[Tutorial]How to make commands

Discussion in 'Tutorials/Documentations' started by Float, Jan 18, 2017.

  1. Float

    Float Member

    Messages:
    29
    Likes Received:
    2
    Joined:
    Dec 2, 2016
    Hello guys.

    I am same new guy as you , i guess and i just wanted to help you (if you're new) to script some commands!

    Let's start.

    First of all , you should have basic understanding under C#.

    Here is an example how to start scripting command:
    Code:
     [Command("your command name")]
    Then second thing you want to do is create a PUBLIC function in order to execute your command.

    Code:
     public void YourFunctionName()
            {
               
            }
    Your command name can be anything you want , except the functions that already exist in your scripts.

    The Parameters

    Now , parameter are the things that you write in game after your command as follows:
    Code:
    /yourcommandname parameter1 parameter2 parameter3 (and etc...)
    These parameters can be used to target a player , to give a certain gun ,with a mod and amount of ammo that you want.For example , let's give command executor a weapon:

    Code:
     [Command("weapon")]
            public void WeaponCommand(Client player, WeaponHash hash)
            {
                //API.givePlayerWeapon(Client player, WeaponHash weaponHash, int ammo, bool equipNow, bool ammoLoaded);
                //                         player             hash              500        true           true
                API.givePlayerWeapon(player, hash, 500, true, true);
                //Instantly gives player a weapon that he typed.
            }
    So as you can see Client is a variable type (mostly the player that writes the command) and sender is a variable that stores the player ID (as far as i understand),secondly WeaponHash is also a variable type that is used to hold weapon hashes (weapon names for ex. WeaponHash.Railgun , WeaponHash.Pistol) So basically you write /weapon weaponname and the function takes "weaponname" as WeaponHash.


    Let's try playing an animation for a player that we want:

    Code:
     [Command("playanim")]
            public void OnPlayerRequestAnimationCommand(Client sender, string target)
            {
                //We create a varibale to store a playerID and we set it from his name by using native function
                Client player = API.getPlayerFromName(target);
                //If player exist in server we execute the command
                if (player != null)
                    //API.playPlayerAnimation(Client player, int flag, string animDict, string animName);
                    API.playPlayerAnimation(player, (int)(AnimationFlags.Loop | AnimationFlags.OnlyAnimateUpperBody | AnimationFlags.AllowPlayerControl), "mp_arresting", "idle");
                //If not we send a message to the executor that there is no such player in server
                else API.sendChatMessageToPlayer(sender, "Player doesn't exist.");
            }
    As you can see we will write /playanim playername and if the player exist it will play cuffed animation on a player that we want , by sending playername to a string and converting it to PlayerID with a native function API.getPlayerFromName(string name).

    Alternatively player can stop his animation with this command:

    Code:
     [Command("stop")]
            public void OnPlayerRequestToStopAnimation(Client sender)
            {
                API.stopPlayerAnimation(sender);
            }
    Or more complex , you can stop animation for a player:

    Code:
     [Command("s")]
            public void OnPlayerRequestToStopAnimation(Client sender,string target)
            {
                Client player = API.getPlayerFromName(target);
                if(player != null)
                    API.stopPlayerAnimation(target);
                else API.sendChatMessageToPlayer(sender, "Player doesn't exist.");
            }

    Feel free to ask question , i'm new as you too.Forum veterans , feel free to correct me or suggest better ways if this is wrong , i'm just writing what works for me and what i learned , because there isn't much in wiki right now...
     
    Last edited: Jan 18, 2017
    SheetTek likes this.
  2. VFRZ

    VFRZ Active Member

    Messages:
    65
    Likes Received:
    19
    Joined:
    Dec 29, 2016
    Currently the wiki is more complete for commands, you dont write anything about GreedyArgs and Alias ...
     
    Olaf likes this.
  3. Float

    Float Member

    Messages:
    29
    Likes Received:
    2
    Joined:
    Dec 2, 2016
    What are those?
     
  4. VFRZ

    VFRZ Active Member

    Messages:
    65
    Likes Received:
    19
    Joined:
    Dec 29, 2016
  5. Bitdevil2016

    Bitdevil2016 Member

    Messages:
    24
    Likes Received:
    0
    Joined:
    May 14, 2017
    Hi can send Commands per menu.js <- Example file Name?

    Or must all covert to extra Events?
     
  6. Olaf

    Olaf Member

    Messages:
    30
    Likes Received:
    2
    Joined:
    Dec 26, 2016
    You must use Events for this.
     

Share This Page