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.

Useful code snippets

Discussion in 'Snippets' started by MasterZero, Oct 20, 2016.

  1. Ruffo

    Ruffo Member

    Messages:
    11
    Likes Received:
    3
    Joined:
    Dec 26, 2016
    ahh, like Pointer :=D

    But did you not create a Instace copy for every player in the ServerPlayer list?
    foreach(Client Player in API.getAllPlayers()

    Edit: think The in stands for the reference,
    Yea so returning the Client directly is fester..

    Anyway, added a second function to get directly the Client.
     
    Last edited: Jan 17, 2017
  2. MissMelissa

    MissMelissa New Member

    Messages:
    0
    Likes Received:
    0
    Joined:
    Dec 26, 2016
    No, those are still references.

    Also, I looked it up, apparently strings aren't copied, they're still references internally. Having a constant such as "some string", that is also a reference in itself.
     
    Ruffo likes this.
  3. PedroBarbosaPT

    PedroBarbosaPT Member

    Messages:
    8
    Likes Received:
    3
    Joined:
    Dec 31, 2016
    For those who spam commands for debuging ingame
    you can use:

    Code:
    public void t([CallerLineNumber] int lineNumber = 0)
    {
        API.consoleOutput("Line" + lineNumber);
    }
    t();

    //Edit:
    I call the function "t" so that it doesn't slow me down every time I want to debug
     
    Ruffo and MissMelissa like this.
  4. darkcha0s

    darkcha0s Member

    Messages:
    7
    Likes Received:
    5
    Joined:
    Jan 10, 2017
    You could also just do
    Code:
    var searchText = PPieceName.ToUpper();
    var player = API.getAllPlayers().FirstOrDefault(x => x.name.ToUpper().Contains(searchText));
    
    or if you want multiple results
    Code:
    var searchText = PPieceName.ToUpper();
    var players = API.getAllPlayers().Where(x => x.name.ToUpper().Contains(searchText)).ToList();
    
    The player will actually be null too if not found, which is convenient.
     
    Last edited: Jan 17, 2017
    kova98 and Ruffo like this.
  5. MissMelissa

    MissMelissa New Member

    Messages:
    0
    Likes Received:
    0
    Joined:
    Dec 26, 2016
    You added this on the wiki, but I don't see how this is useful, there already is a Hash enum on the server containing all of these, and if you want to get hash integers you can use API.getHashKey as well.
     
  6. Eraknelo

    Eraknelo Active Member

    Messages:
    64
    Likes Received:
    61
    Joined:
    Dec 26, 2016
    CefHelper based on TypeScript.

    As the wait for load is a little buggy atm, and some other stuff too, I created this bigger, better (at least, I think so) CefHelper class for TypeScript.
    It has a .call queue, which queues all the .call functions you want to execute, and then executes them 1 second after the browser has been shown, to wait for it to load.

    Calls to the browser can be queued like this:
    Code:
    var myBrowser = new CefHelper("index.html");
    myBrowser.callMethod(b => b.call("event-name", arg1, arg2);
    myBrowser.show();
    That will create a new browser that opens the "index.html" page.
    Then queues a .call event for event-name with the args arg1 and arg2.
    Then shows the browser. This will create the browser (if it hasn't been already), and make it pop up.
    Then it waits for 1 second, and executes all the queued calls in-order.

    For callbacks from the browser side, there's a static array called CefHelper.eventHandlers
    You can listen for events from it like this:
    Code:
    CefHelper.eventHandlers["callback-event-name"] = (args: any[]) => {
        ...
    };
    And then call it from the browser's JS like this:
    Code:
    resourceCall("CefHelper.browserCallback", "callback-event-name", arg1, arg2);
    It works for multiple instances of CefHelper, but make sure your callback methods have unique names.

    Download
     
    Last edited: Jan 25, 2017
    kova98, Alf21, batman and 2 others like this.
  7. Ping_Gooty

    Ping_Gooty Member

    Messages:
    10
    Likes Received:
    4
    Joined:
    Feb 6, 2017
    A simple PM command made by me :=)
    Code:
        [Command("pm", GreedyArg = true)]
        public void PMESSAGE(Client player, Client dest, string text)
        {
                var msg_to_sender = "Message sent to " + dest.name + ": " + text;
                API.sendChatMessageToPlayer(player, msg_to_sender);
                var msg = "Personal Message from " + player.name + ": " + text;
                API.sendChatMessageToPlayer(dest, msg);
        
        }
    
     
    Last edited by a moderator: Feb 6, 2017
  8. WhiteFoxMax

    WhiteFoxMax Member

    Messages:
    9
    Likes Received:
    3
    Joined:
    Jan 28, 2017
    Car mod types enum C#(easy to change for JS, For display name replace underscore with space)

    Personally I wouldn't use Colour_1 and Colour_2 since they don't fit the numbers here:
    https://www.gtamodding.com/wiki/Vehicle_Color_IDs and here http://imgur.com/a/F4Ptk
    (credits to fiverp forums for the color lists)

    Code:
    public enum CarModsTypes
    {
        Spoilers = 0,
        Front_Bumper = 1,
        Rear_Bumper = 2,
        Side_Skirt = 3,
        Exhaust = 4,
        Frame = 5,
        Grille = 6,
        Hood = 7,
        Fender = 8,
        Right_Fender = 9,
        Roof = 10,
        Engine = 11,
        Brakes = 12,
        Transmission = 13,
        Horns = 14,
        Suspension = 15,
        Armor = 16,
        Turbo = 18,
        Xenon = 22,
        Front_Wheels = 23,
        Back_Wheels = 24,
        Plate_holders = 25,
        Trim_Design = 27,
        Ornaments = 28,
        Dial_Design = 30,
        Steering_Wheel = 33,
        Shift_Lever = 34,
        Plaques = 35,
        Hydraulics = 38,
        Livery = 48,
        Plate = 62,
        Colour_1 = 66,
        Colour_2 = 67,
        Window_Tint = 69
    }
     
    nvr and Jack8814 like this.
  9. MrBeav

    MrBeav New Member

    Messages:
    3
    Likes Received:
    0
    Joined:
    Feb 5, 2017

    I added more to this list, total of 119 ATMs here now but still many more to add from the 24/7's and LS Central Bank

    https://pastebin.gtanet.work/?901083391aeadae4#JSpilZ46CJzi+jRyUTa1uQmzXjHF0boeM/zStih7LuA=
     
  10. Stuyk

    Stuyk Active Member Public Relations Developer

    Messages:
    81
    Likes Received:
    76
    Joined:
    Jan 12, 2017
    _SET_PED_FACE_FEATURE

    Code:
    Nose Width: 0
    Nose Height: 1
    Nose Length: 2
    Nose Bridge: 3
    Nose Tip: 4
    Nose Bridge Depth: 5
    Eyebrow Height: 6
    Eyebrow Depth: 7
    Cheekbone Height: 8
    Cheekbone Depth: 9
    Cheekbone Width: 10
    Eyelids: 11
    Lips: 12
    Jaw Width: 13
    Jaw Depth: 14
    Jaw Length: 15
    Chin Fullness: 16
    Chin Width: 17
    18???
    Neck Width: 19
    20???
    21???
    
     
  11. Hansrutger

    Hansrutger Well-Known Member Donator

    Messages:
    114
    Likes Received:
    36
    Joined:
    Mar 4, 2017
    I hoped there'd be "today I learned" thread instead but I suppose this will do!

    I was running for fun "MySqlCommand.LastInsertedId;" to see what different types of responses I get back to CRUD queries. Perhaps useful for someone one day (probably not):

    Code:
    Update = id = 0
    Select = id = -1
    Insert = id = 4 (actual)
    Select: id = -1
    Select: id = -1
    Delete: id = 0
    Delete: id = 0
    Select = id = -1
    Update = id = 0
    Update = id = 0
    Insert = id = 5 (actual)
    Insert = id = 6 (actual)
    
    Conclusion
    Of course more tests should be run but it looks like a clear pattern. Obviously INSERT will give the correct id back, SELECT will always give you -1 meanwhile DELETE and UPDATE will always give 0.
     
  12. toyer

    toyer Member

    Messages:
    13
    Likes Received:
    0
    Joined:
    Nov 1, 2016

Share This Page