Log in to reply
 

vehicles statit to dynamic [javascript]



  • Hello to all,
    I've never written code for gta 5 until now.

    Now, I'm trying to do to port with MapEditor ... but the boat does not stand still, they drift.

    I would use the simple javascript to add to the map editor, as shown here: https://github.com/G...ng-a-Map-Script

    I thought sets the boats as static, and create a JavaScript script that changes static to dynamic when the player goes into vehicle.
    I tried this script:

    if (API.GTA.Game.Player.Character.IsInVehicle())
    {
    API.GTA.Game.Player.Character.CurrentVehicle.Dynamic();
    }

    Dynamic() it was only a hope, but do not seem to work.

    Can anyone help me figure out how to write the script? Or maybe given some guides that teaches how to use JavaScript in the gta 5?

    Thank you



  • @alebal Try freezing boat with Menyoo to see if it still drifts, may be a built in function



  • But they are also still with Map Editor unchecking the dynamic option. But I wish that when the player enters the vehicle would return dynamic. Any idea on how to do?



  • @alebal what is the variable set to when it is not in dynamic



  • boh .. I do not know ... it is a map editor option ... it is everywhere, vehicles, peds, props, etc.



  • MapEditor Dynamic



  • @alebal I'll try to find out for you when I get home



  • thank you so much



  • @alebal I was never sure whether the dynamic property applied to things that the player could interact with on a physics level. So something like a waste bin would be dynamic, so you could knock it about/shoot it etc... but something like a bus stop would be static... not sure if that's right or not, but that was my thought. Didn't actually know it applied to Vehicles though, I thought it was just a prop thing.

    Funnily enough, while testing my camera mod, I had the same problem with boats drifting... in fact I got so fed up with chasing the boats, that I flew to the lake in the park and spawned the boats in there. :)

    I thought about adding a virtual anchor which would lock the X and Y position and just allow the Z position to drift with the wave height. Again, not sure if that would work but I can't see why it wouldn't. So basically hit a key/check for a condition, save the X and Y location and then in your onTick, keep setting them.



  • Thanks for your reply, today I'm definitely not able to do what you're talking about. I am a php and mysql programmer, gta coding is foreign to me ...

    But in the coming days I attack me at google and try to figure it out ...

    Can help you understand how to do if I tell you that seems to do the same thing here

    the boat here also seems to be static, then when the player comes close "pluff" ends up in the water.
    Maybe there is a function or something ready ... but how do I find it ???



  • I Googled a bit.
    I first found this https://www.gta5-mods.com/scripts/anchor so maybe you can do it ...
    Then in the list of native I found this SET_BOAT_ANCHOR, maybe that's what I need ...

    But now turn this:
    SET_BOAT_ANCHOR
    in something like this:
    script.CallNative ("GIVE_WEAPON_TO_PED" API.GTA.Game.Player.Character, 453,432,689, 50, true, true); // Give pistol to player

    for me it is an epic undertaking ... some help ...
    What are the parameters of this thing ?? How can I find them?



  • I also found these
    REPLACE SET_BOAT_ANCHOR = 0x45087C, //0xA3906284 //1.26 //BLES
    SET_BOAT_ANCHOR = 0x439a40,
    SET_BOAT_ANCHOR = 0x44C798, //1.22

    Like ancient Egyptian for me ..



  • @alebal You might want to add this page to your bookmarks: http://www.dev-c.com/nativedb/

    That is a list of every native (which is what those are) and it shows what parameters are used in each one.

    In the case of SET_BOAT_ANCHOR, it requires a Vehicle and a Bool. There is also a _GET_BOAT_ANCHOR which returns a Bool telling you whether the anchor is on or off. I don't know how that works in Javascript, but in C# it would be:

    bool _anchorvalue = Function.Call<bool>(Hash._GET_BOAT_ANCHOR, _vehicle);
    

    To set the anchor, again in C#:

    Vehicle _vehicle = Function.Call<Vehicle>(Hash.GET_VEHICLE_PED_IS_TRYING_TO_ENTER, Game.Player.Character);
    int _class = Function.Call<int>(Hash.GET_VEHICLE_CLASS, _vehicle);
    
    if (_class == 14)
    {
        Function.Call(Hash.SET_BOAT_ANCHOR, _vehicle, true);
    }
    

    C# does have functions that replace those natives but I have shown the native as it might transfer better to Javascript. 14 is the value of Boats in the vehicle class enums.

    Edit: Sorry, I missed a parameter off that _GET_BOAT_ANCHOR. :(



  • Even I'm not expert in javascript. But more or less your code should become this (even reading here https://github.com/Guad/MapEditor/wiki/Writing-a-Map-Script)

    var vehicle = script.CallNative("GET_VEHICLE_PED_IS_TRYING_TO_ENTER", API.GTA.Game.Player.Character);
    var vehicle_class = script.CallNative("GET_VEHICLE_CLASS", vehicle);

    if (vehicle_class == 14)
    {
    script.CallNative("SET_BOAT_ANCHOR", vehicle, true);
    }

    But it does not work ... GTA says: Map Javascript error -> Exception Has Been thrown by the target of an invocation.

    The error comes right away from the vehicle variable used in GET_VEHICLE_CLASS function.
    Or am I wrong to write something, or MapEditor do not want variables in functions in the writing of javascript.

    I do not know ... Any help?



  • @alebal I'm afraid I can't offer anything on the side of Javascript or MapEditor. If I want objects, I manually spawn them and if I want functionality, I write C# scripts to give it to me.

    If I had more time spare, I could probably have a look at MapEditor but my mod is eating the day away every day, so spare time is a rarity. Sorry I can't be of more help.

    Based on the number of map mods that appear on this site, there must be surely someone willing to help.

    Edit: Actually, it's my fault for not explaining that what I have written there, would normally go inside a function that says:

    if (Function.Call<bool>(Hash.IS_PED_GETTING_INTO_A_VEHICLE, Game.Player.Character))
    {
        // Do that code
    }
    

    That function would be called every frame in your onTick(), waiting for you to try and enter a vehicle.

    Actually, thinking about it, I wonder if it's this line:

    var vehicle = script.CallNative("GET_VEHICLE_PED_IS_TRYING_TO_ENTER", API.GTA.Game.Player.Character);
    

    Is there anything in the documentation that tells you how to return a value from a native, or does it do it by default? If you notice, I specify Function.Call<bool> which tells it to return a true or false value back. You need to check if script.CallNative passes values back. If not, that could be the cause of the error.

    Just had a quick check, yes you can use onTick() and yes you can return values... use this (not sure how to specify the parameters)

    object script.ReturnNative(string nativeHash, int returnType, params object[] args)
    

    From the docs: Return a game native's value. Return types are as follow: Int = 0, UInt = 1, Long = 2, ULong = 3, String = 4, Vector3 = 5, Vector2 = 6, Float = 7

    Damn, I'm getting wrapped up in this... That return call won't work if it only allows you to choose from those return types. You need to get a Vehicle back and that's not included there. You might be better asking the author of MapEditor... I could just be further confusing things here by guessing at solutions.



  • I understand! Thank you so much for your time.

    Honestly, I also am not understanding nothing more ...

    These days I did more tests, but I never get what I expect.

    But I discovered something that I had never noticed., MapEditor also saves in C.

    The result is something like this:

    using System;
    using System.Collections.Generic;
    using GTA;
    using GTA.Math;
    using GTA.Native;

    public class MapEditorGeneratedMap : GTA.Script
    {
    public MapEditorGeneratedMap()
    {
    List<int> Props = new List<int>();
    int LodDistance = 3000;

        Func<int, Vector3, Vector3, bool, int> createProp = new Func<int, Vector3, Vector3, bool, int>(delegate(int hash, Vector3 pos, Vector3 rot, bool dynamic)
        {
    	    Model model = new Model(hash);
    	    model.Request(10000);
    	    Prop prop = GTA.World.CreateProp(model, pos, rot, dynamic, false);
    	    prop.Position = pos;
            prop.LodDistance = LodDistance;
            if (!dynamic)
                prop.FreezePosition = true;
    	    return prop.Handle;
        });
    
        bool Initialized = false;
    
    
        base.Tick += delegate (object sender, EventArgs args)
        {
            if (!Initialized)
            {
                /* PROPS */
    
    
                /* VEHICLES */
               GTA.World.CreateVehicle(new Model(231083307), new GTA.Math.Vector3(45.96207f, 494.799f, 165.9185f), -67.20878f);
    
    
                /* PEDS */
    
    
                /* PICKUPS */
    
                Initialized = true;
            }
    
            /* MARKERS */
    
    
            /* WORLD */
            Prop returnedProp;
    
        };
    }
    

    }

    At this point it might as well export all in C, and maybe add in the end, your function to the anchor of the boats.

    But being a programmer php I'm missing something ... like, C must be compiled, as I compile for use in GTA? It must be .ASI? As you export to .ASI?

    One other thing, I wish only a few boats were anchored, while others should run free to the lake, you can assign an identification to the vehicle in C? And in the first "if" use the identifiers in place of the class?

    P.S. does not put the code and pre tags in the right place, there is other code out . You can not edit the html of the post?



  • I have not managed to anchor boats in the harbor.
    But for the moment I went ahead with the map, here it is: https://www.gta5-mods.com/maps/franklin-s-lake-party

    Meanwhile, I keep thinking about how to do.

    Thank you for helps.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.