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.

Locking all vehicles with sendNativeToPlayer

Discussion in 'Archive' started by Hazes, Apr 19, 2017.

  1. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Hi!

    I'm having this issue.. I'm trying to lock all the vehicles which have "locked" entity data set to true after player joins the server. It looks like this:
    Code:
        private void OnPlayerFinishedDownloadHandler(Client player)
    {
            foreach (NetHandle vehicle in API.getAllVehicles())
            {
                bool engineState = API.getEntitySyncedData(vehicle, "engineState");
                bool lockedState = API.getEntitySyncedData(vehicle, "locked");
                if(engineState == true){ API.setVehicleEngineStatus(vehicle, true); }
                if(lockedState == true) { API.sendNativeToPlayer(player, 0xB664292EAECF7FA6, vehicle, 2); }
            }
        }
    So if the lockedState is true, native should be sent to player and doors should be locked. It doesn't work wheter it's true or false, or without a statement.

    Native works well when player is on the server and locks the door:
    Code:
                            if (vehicleLocked == true)
                            {
                                API.sendNativeToAllPlayers(0xB664292EAECF7FA6, vehicle, 1);
                                API.sendChatMessageToPlayer(player, "~g~Door open!");
                                API.setEntitySyncedData(veh, "locked", false);
                            }
                            else if (vehicleLocked == false)
                            {
                                API.sendNativeToAllPlayers(0xB664292EAECF7FA6, vehicle, 2);
                                API.sendChatMessageToPlayer(player, "~g~Door closed!");
                                API.setEntitySyncedData(veh, "locked", true);
                            }
    The native I'm using:
    Code:
    void SET_VEHICLE_DOORS_LOCKED_FOR_ALL_PLAYERS(Vehicle vehicle, BOOL toggle)
    // 0xA2F80B8D040727CC 0x891BA8A4
    I also tried SET_VEHICLE_DOORS_LOCKED but it doesn't work when player joins the server. Any suggestions?

    Regards,
    Hazes.

    //EDIT: It works when I launch the command:
    Code:
        [Command("lockall")]
        public void LockAllVehiclesCommand(Client sender)
        {
            foreach(NetHandle vehicle in API.getAllVehicles())
            {
                if (API.getEntitySyncedData(vehicle, "locked") == true)
                {
                    API.sendNativeToAllPlayers(0xB664292EAECF7FA6, vehicle, 2);
                }
            }
        }
     
    Last edited: Apr 19, 2017
  2. Draex

    Draex Active Member

    Messages:
    64
    Likes Received:
    31
    Joined:
    Apr 2, 2017
    You'll have to change
    0xB664292EAECF7FA6 to "0xB664292EAECF7FA6" cause it's a string
    js doesn't support doubles (=64bit int)
    Apart from that im not sure if a native can workout with the vehicles nethandle
     
  3. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Hi. It's a CSharp file. Yeah native works with the vehicle's NetHandle just not in this case when I've put it in
    OnPlayerFinishedDownloadHandler.

    I've also changed the vehicle's NetHandle to Vehicle object. Still nothing.
     
    Last edited: Apr 19, 2017
  4. Draex

    Draex Active Member

    Messages:
    64
    Likes Received:
    31
    Joined:
    Apr 2, 2017
    Oh sry should have read it, paying more attention xD
    I think the error comes from OnPlayerFinishedDownloadHandler which probably doesn't get called at all.
    Also I'm assuming OnConnect will be called, but your stuff won't work there.
    You should try triggering an event on the server when the resource is initialized on the client. Then go catch it on the server and execute your native call there

    Hope it works ;-)
     
    Letho and Hazes like this.
  5. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    My bad, I didn't say it was CSharp file ;-)
    OnPlayerFinishedDownladHandler works, because it downloads all markers, text labels, vehicles and vehicle states. I will try calling the client event and then call server event from it, maybe it will work. Thanks.
     
  6. Draex

    Draex Active Member

    Messages:
    64
    Likes Received:
    31
    Joined:
    Apr 2, 2017
    Go tell me if it works then :=D
    I'm trying to avoid FinishedDownloads, caused way to much problems for me
     
  7. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    I'm trying to go with your suggestion but can't get it quite right. So, I call the first event in JS file, on clientside right? But I can't figure out WHEN I should call it. :=D

    //EDIT: I got it working in OnUpdateHandler, however I would like to call this only once. Can you give me any suggestions other than setting a variable equal to 1 before update and setting it to 0 after locking the vehicles? Can I maybe create my own Handler / Method that would be called whenever I want it to?
     
    Last edited: Apr 19, 2017
  8. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    I've fixed it by calling the native after user logs in inside my CEF, then a server event gets called AFTER I've set the players position. So it may have to do with distance from which I'm calling it. But can't prove it yet.
    Thanks for the help!
     
    Letho likes this.

Share This Page