Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

Community Script Hook V .NET


crosire
 Share

Recommended Posts

 

@Reck1501, upload your project somewhere with ScriptHookVDotNet.dll, i will see.

Ini file should have same name as dll yes?

Yes, or use Settings.Load.
there is no Settings.load n it still used default

 

var sett = ScriptSettings.Load( "filename" );
Edited by Inco
Link to comment
Share on other sites

Hello, thanks for help everyone)

 

Is there a way to create prop which will be placed under ground? I need to create rams so it will be a little bit underground because this:

World.CreateProp(myramp, ped.Position + ped.ForwardVector * distance, true, true);

doesn't place it correctly everytime, so I want to place it a little bit under ground level

 

Also, what does "dynamic" means in World.CreateProp?

 

Thanks!

Edited by Moder L
Link to comment
Share on other sites

I can do it like this

GTA.Math.Vector3 vec = new GTA.Math.Vector3(ped.Position.X, ped.Position.Y, ped.Position.Z - 1)

Can someone give me an example how to use native function GET_GROUND_Z_FOR_3D_COORD to get this Z coordinate?

Edited by Moder L
Link to comment
Share on other sites

flynhigh09

No clue but still not working falls back to default..

SPraceMod.net.ini[RACE_SETTINGS]VEHICLE=3057713523
  ScriptSettings _settings = ScriptSettings.Load("SPraceMod.net");//dont load at all   VehicleModel = _settings.GetValue<VehicleHash>("[RACE_SETTINGS]", "VEHICLE", VehicleHash.Dukes2);//loads if use Settings.GetValue to default value only.

 

 

@Reck1501, upload your project somewhere with ScriptHookVDotNet.dll, i will see.

Ini file should have same name as dll yes?

Yes, or use Settings.Load.
there is no Settings.load n it still used default

 

var sett = ScriptSettings.Load( "filename" );
Edited by flynhigh09
Link to comment
Share on other sites

Hello.

 

 

 

 

 

 

I can't figure what's wrong (maybe it's all wrong in the first place?).

Now let me say something: it may happen for once, or twice, then it starts working normal (just have to press Insert a couple of times). And there's something I noticed, and it is: It won't work when I start the game fresh (or reload any saved game), only by pressing Insert (maybe twice).

 

How can I solve it? I'm a beginner (as most of you can see).

Exception message explains it pretty well. You are attempting to create a vehicle inside the constructor, which itself has to stream in the vehicle model, which is a blocking call and thus not allowed. Anything attemping to block (calling "Script.Wait" or "Script.Yield") inside the constructor is not allowed, since the constructor is executed in the base thread and would block the entire Script Hook.

You have to do those kind of things in the Tick or KeyDown/Up events.

 

 

 

 

 

Thanks, it did the work!

 

 

 

 

 

 

I may be wrong questioning this in this topic, but: How can I get the actual heading of the player, ingame?
If there was an obvious way, I apologize for not getting it in the first place, but anyway I haven't found it yet.


 

 

float heading = Game.Player.Character.Heading;

 

Thanks for that, it did the work.

But now I have another concern, and it is regarding ped|car density.

I've been looking for natives and there are some lines that would allegedly work, but I can't get them to do the job:

void SET_PED_DENSITY_MULTIPLIER_THIS_FRAME(float multiplier)
void SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME(float p0)
void SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME(float p0)

I tried to set the parameters to 0.0 but it did nothing:

  GTA.Native.Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 0.0)  GTA.Native.Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.0)  GTA.Native.Function.Call(Hash.SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.0)

I may be doing something stupid, but even If I am, can't figure what it is. Could someone help me?

 

 

 

 

 

Thanks, it did the work too!

 

Now, regarding the 'DrivingStyle' I mentioned before:

It seems that the best of those 'styles' is the 6 (AvoidTrafficExtremely). But still, they are slow and, they don't really 'avoid' most of the traffic (AI mainly ramming against it).

Curiously, when I tried to use the BJXL (BeeJay XL), the AI was much slower than some other cars (like Dilettante, Emperor, Alpha, etc). And that car isn't that much slower than those. Although this may be related to the 'handling.meta' file: there is a line that says the type of handling the AI has for all cars. The BJXL had 'TRUCK' (like all others trucks in that file), but most of the 'normal cars' had 'AVERAGE'. Maybe that's related to the AI being so much slower with some vehicles.

Anyway, that being true or not, AI is not as fast as it has to be (I remember in GTA IV they really pushed the cars to the maximum, and didn't brake in some random spots like here).

 

PD: I know this last has not much to do with scripting, but since there are some interesting projects for race mods, it would be not of hurt to share something I think may be useful.

Edited by NXT
Link to comment
Share on other sites

Prof_Farnsworth

 

No clue but still not working falls back to default..

SPraceMod.net.ini[RACE_SETTINGS]VEHICLE=3057713523
  ScriptSettings _settings = ScriptSettings.Load("SPraceMod.net");//dont load at all   VehicleModel = _settings.GetValue<VehicleHash>("[RACE_SETTINGS]", "VEHICLE", VehicleHash.Dukes2);//loads if use Settings.GetValue to default value only.

 

 

@Reck1501, upload your project somewhere with ScriptHookVDotNet.dll, i will see.

Ini file should have same name as dll yes?

Yes, or use Settings.Load.
there is no Settings.load n it still used default

 

var sett = ScriptSettings.Load( "filename" );

 

Same for me still. Can anyone give an example of how they successfully used this?

Link to comment
Share on other sites

monsterxsync

Any idea why this isn't working?:

            Ped MyPed = Game.Player.Character;            Function.Call(Hash.SET_EXPLOSIVE_AMMO_THIS_FRAME, MyPed);

(it is in void OnTick)

Try this..

Function.Call(Hash.SET_EXPLOSIVE_AMMO_THIS_FRAME, Game.Player);

Link to comment
Share on other sites

 

No clue but still not working falls back to default..

SPraceMod.net.ini[RACE_SETTINGS]VEHICLE=3057713523
  ScriptSettings _settings = ScriptSettings.Load("SPraceMod.net");//dont load at all   VehicleModel = _settings.GetValue<VehicleHash>("[RACE_SETTINGS]", "VEHICLE", VehicleHash.Dukes2);//loads if use Settings.GetValue to default value only.

 

 

@Reck1501, upload your project somewhere with ScriptHookVDotNet.dll, i will see.

Ini file should have same name as dll yes?

Yes, or use Settings.Load.
there is no Settings.load n it still used default

 

var sett = ScriptSettings.Load( "filename" );

 

Filename of your ini is SPraceMod.net.ini, not SPraceMod.net , this is first. Second, where is your ini file? In scripts folder? Then scripts\\SPraceMod.net.ini

 

 

Any idea why this isn't working?:
           Ped MyPed = Game.Player.Character;            Function.Call(Hash.SET_EXPLOSIVE_AMMO_THIS_FRAME, MyPed); 
(it is in void OnTick)
Look at native db, this function require player handle.
var player = Game.Player;Function.Call( Hash.SET_EXPLOSIVE_AMMO_THIS_FRAME, player.Handle );
Edited by Inco
Link to comment
Share on other sites

 

No clue but still not working falls back to default..

SPraceMod.net.ini

[RACE_SETTINGS]

VEHICLE=3057713523

ScriptSettings _settings = ScriptSettings.Load("SPraceMod.net");//dont load at all

VehicleModel = _settings.GetValue<VehicleHash>("[RACE_SETTINGS]", "VEHICLE", VehicleHash.Dukes2);//loads if use Settings.GetValue to default value only.

 

And additionally to what Inco already said, the settings key in the script would be "RACE_SETTINGS", not "[RACE_SETTINGS"] for your INI file.

Edited by Crosire
Link to comment
Share on other sites

 

                Dim ReturnPed As Ped = World.CreatePed(GTA.Native.PedHash.SMMMovalien01, loc)                ReturnPed.RelationshipGroup = GTA.Relationship.Hate                GTA.Native.Function.Call(GTA.Native.Hash.GIVE_WEAPON_TO_PED, ReturnPed, GTA.Native.WeaponHash.AssaultRifle, 420, True, True)                'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq ReturnPed.BlockPermanentEvents = True                ReturnPed.Task.GuardCurrentPosition()                ReturnPed.Task.AimAt(loc, 10000)                GTA.World.AddRelationShipGroup("ARMY")                GTA.World.SetRelationshipBetweenGroups(Relationship.Hate, "PLAYER", "ARMY")                GTA.World.SetRelationshipBetweenGroups(Relationship.Hate, "ARMY", "PLAYER")                ReturnPed.Task.FightAgainst(Game.Player.Character, 7000)                fight.AddTask.FightAgainst(Game.Player.Character, 7000)                fight.AddTask.FightAgainstHatedTargets(30.0F)                fight.AddTask.AimAt(Game.Player.Character, 7000)                fight.AddTask.GuardCurrentPosition()                fight.AddTask.PerformSequence(1)                ReturnPed.Task.PerformSequence(Tasker)                ReturnPed.Money = 5000

I'm trying to get a created ped to fight me but i'm not sure how to set the sequence properly.

I tried learning from c# so far no luck

Link to comment
Share on other sites

monsterxsync

how would we go about getting the waypoints position? is this implemented?

Link to comment
Share on other sites

flynhigh09

So its finding it now but still only getting default value only?


.ini
[RACE_SETTINGS]VEHICLE=3057713523
  VehicleHash Duk = VehicleHash.Dukes2;                 _settings = ScriptSettings.Load("scripts\\SPraceMod.net.ini");             if( _settings == null)                 _settings.SetValue<VehicleHash>("RACE_SETTINGS", "VEHICLE", Duk);            else            VehicleModel = _settings.GetValue<VehicleHash>("RACE_SETTINGS", "VEHICLE", Duk);
Edited by flynhigh09
Link to comment
Share on other sites

 

                 _settings = ScriptSettings.Load("scripts\\SPraceMod.net.ini");
ScriptSettings.Load("SPraceMod.net.ini");

All paths are relative to the script folder.

Link to comment
Share on other sites

 

 

                 _settings = ScriptSettings.Load("scripts\\SPraceMod.net.ini");
ScriptSettings.Load("SPraceMod.net.ini");

All paths are relative to the script folder.

 

 

Nope.

 

 

So its finding it now but still only getting default value only?

 

.ini
[RACE_SETTINGS]VEHICLE=3057713523
  VehicleHash Duk = VehicleHash.Dukes2;                 _settings = ScriptSettings.Load("scripts\\SPraceMod.net.ini");             if( _settings == null)                 _settings.SetValue<VehicleHash>("RACE_SETTINGS", "VEHICLE", Duk);            else            VehicleModel = _settings.GetValue<VehicleHash>("RACE_SETTINGS", "VEHICLE", Duk);

 

There is no checks for VehicleHash. So,

VehicleHash veh = (VehicleHash)_settings.GetValue( "RACE_SETTINGS", "VEHICLE", (UInt64)VehicleHash.Dukes2 );
Link to comment
Share on other sites

flynhigh09

 

 

 

                 _settings = ScriptSettings.Load("scripts\\SPraceMod.net.ini");
ScriptSettings.Load("SPraceMod.net.ini");
All paths are relative to the script folder.

 

Nope.

 

So its finding it now but still only getting default value only?

 

 

.ini

 

 

[RACE_SETTINGS]VEHICLE=3057713523

 

  VehicleHash Duk = VehicleHash.Dukes2;                 _settings = ScriptSettings.Load("scripts\\SPraceMod.net.ini");             if( _settings == null)                 _settings.SetValue<VehicleHash>("RACE_SETTINGS", "VEHICLE", Duk);            else            VehicleModel = _settings.GetValue<VehicleHash>("RACE_SETTINGS", "VEHICLE", Duk);
There is no checks for VehicleHash. So,

 

VehicleHash veh = (VehicleHash)_settings.GetValue( "RACE_SETTINGS", "VEHICLE", (UInt64)VehicleHash.Dukes2 );
Thanks sir it was the cast to uint64..
Link to comment
Share on other sites

Hello.

 

 

 

 

 

 

I can't figure what's wrong (maybe it's all wrong in the first place?).

Now let me say something: it may happen for once, or twice, then it starts working normal (just have to press Insert a couple of times). And there's something I noticed, and it is: It won't work when I start the game fresh (or reload any saved game), only by pressing Insert (maybe twice).

 

How can I solve it? I'm a beginner (as most of you can see).

Exception message explains it pretty well. You are attempting to create a vehicle inside the constructor, which itself has to stream in the vehicle model, which is a blocking call and thus not allowed. Anything attemping to block (calling "Script.Wait" or "Script.Yield") inside the constructor is not allowed, since the constructor is executed in the base thread and would block the entire Script Hook.

You have to do those kind of things in the Tick or KeyDown/Up events.

 

 

 

 

 

Thanks, it did the work!

 

 

 

 

 

 

I may be wrong questioning this in this topic, but: How can I get the actual heading of the player, ingame?

If there was an obvious way, I apologize for not getting it in the first place, but anyway I haven't found it yet.

 

 

 

float heading = Game.Player.Character.Heading;

 

Thanks for that, it did the work.

But now I have another concern, and it is regarding ped|car density.

I've been looking for natives and there are some lines that would allegedly work, but I can't get them to do the job:

void SET_PED_DENSITY_MULTIPLIER_THIS_FRAME(float multiplier)
void SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME(float p0)
void SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME(float p0)

I tried to set the parameters to 0.0 but it did nothing:

  GTA.Native.Function.Call(Hash.SET_PED_DENSITY_MULTIPLIER_THIS_FRAME, 0.0)  GTA.Native.Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.0)  GTA.Native.Function.Call(Hash.SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0.0)

I may be doing something stupid, but even If I am, can't figure what it is. Could someone help me?

 

 

 

 

 

Thanks, it did the work too!

 

Now, regarding the 'DrivingStyle' I mentioned before:

It seems that the best of those 'styles' is the 6 (AvoidTrafficExtremely). But still, they are slow and, they don't really 'avoid' most of the traffic (AI mainly ramming against it).

Curiously, when I tried to use the BJXL (BeeJay XL), the AI was much slower than some other cars (like Dilettante, Emperor, Alpha, etc). And that car isn't that much slower than those. Although this may be related to the 'handling.meta' file: there is a line that says the type of handling the AI has for all cars. The BJXL had 'TRUCK' (like all others trucks in that file), but most of the 'normal cars' had 'AVERAGE'. Maybe that's related to the AI being so much slower with some vehicles.

Anyway, that being true or not, AI is not as fast as it has to be (I remember in GTA IV they really pushed the cars to the maximum, and didn't brake in some random spots like here).

 

PD: I know this last has not much to do with scripting, but since there are some interesting projects for race mods, it would be not of hurt to share something I think may be useful.

I hear you and I do also believe that DrivingStyle is not just some integer which reflects the forcefulness of the style (the higher the value the more aggressive) but it seems to be a bit mask. For instance the "normal" driving style (obey all traffic laws) is 786603. I don't know what's behind that value but just the fact that it's not simply 1 tells me there must be more to it.

Edited by Cyron43
Link to comment
Share on other sites

I would recommend using lambda-expressions.

() => { code here }

 

 

Getting these errors:

You did add ScriptHookVDotNet.dll as an assembly reference to the project, did you?

 

Yea, turns out it was because it was an outdated version. I compiled the source myself and it works.

 

Also, I'm looking at the vehicle list in the sample trainer

    void OpenVehicleSpawnMenu()    {        ListMenu VehicleMenu = new ListMenu("Spawn Vehicle");        VehicleMenu.Add("Adder", "A fast car");        VehicleMenu.Add("LAZER", "A military jet");        VehicleMenu.Add("BMX", "A bike");        VehicleMenu.Add("Jetpack", "CLASSIFIED");        View.AddMenu(VehicleMenu);    }

How would I make them spawn when pressed, without making an individual function for each vehicle?

 

Link to comment
Share on other sites

monsterxsync

 

I would recommend using lambda-expressions.

() => { code here }

 

 

Getting these errors:

 

You did add ScriptHookVDotNet.dll as an assembly reference to the project, did you?

 

Yea, turns out it was because it was an outdated version. I compiled the source myself and it works.

 

Also, I'm looking at the vehicle list in the sample trainer

    void OpenVehicleSpawnMenu()    {        ListMenu VehicleMenu = new ListMenu("Spawn Vehicle");        VehicleMenu.Add("Adder", "A fast car");        VehicleMenu.Add("LAZER", "A military jet");        VehicleMenu.Add("BMX", "A bike");        VehicleMenu.Add("Jetpack", "CLASSIFIED");        View.AddMenu(VehicleMenu);    }

How would I make them spawn when pressed, without making an individual function for each vehicle?

 

 

Can you give a live example please? i also would like to know this.

Link to comment
Share on other sites

Is there a way of accessing a Menu's currently selected item/index and it's menu collection? (In the latest release - 0.9 , C#)

 

Also, a menu related suggestion:

I think menus and buttons should have some events, such as OnActivate, OnLeft, OnRight, OnUp, OnDown, OnBack, as done in C# GUI frameworks.

Their delegate would pass a sender object(menu/button) and perhaps an EventArgs object. It would be useful for actions that depend on menu/button data.

Link to comment
Share on other sites

Is there a way of accessing a Menu's currently selected item/index and it's menu collection? (In the latest release - 0.9 , C#)

SelectedIndex in the upstream.

Link to comment
Share on other sites

 

Is there a way of accessing a Menu's currently selected item/index and it's menu collection? (In the latest release - 0.9 , C#)

SelectedIndex in the upstream.

 

 

Thanks

 

 

 

I would recommend using lambda-expressions.

() => { code here }

 

 

Getting these errors:

 

You did add ScriptHookVDotNet.dll as an assembly reference to the project, did you?

 

Yea, turns out it was because it was an outdated version. I compiled the source myself and it works.

 

Also, I'm looking at the vehicle list in the sample trainer

    void OpenVehicleSpawnMenu()    {        ListMenu VehicleMenu = new ListMenu("Spawn Vehicle");        VehicleMenu.Add("Adder", "A fast car");        VehicleMenu.Add("LAZER", "A military jet");        VehicleMenu.Add("BMX", "A bike");        VehicleMenu.Add("Jetpack", "CLASSIFIED");        View.AddMenu(VehicleMenu);    }

How would I make them spawn when pressed, without making an individual function for each vehicle?

 

 

Can you give a live example please? i also would like to know this.

 

 

I have an example with Menu and MenuButtons(from the 0.9 release):

        public void OpenVehicleSpawnMenu()        {            Func<VehicleHash, MenuButton> VehAsButton = (hash) =>                {                    return new MenuButton(hash.ToString(), () =>                    {                        World.CreateVehicle(hash, Game.Player.Character.Position);                    });                };            List<VehicleHash> allVehicles = Enum.GetValues(typeof(VehicleHash)).Cast<VehicleHash>().ToList();            var menu = new GTA.Menu("Vehicle Spawner", allVehicles.Select(VehAsButton).OrderBy(mb => mb.Caption).ToArray());            View.AddMenu(menu);        }
Edited by NMDanny
Link to comment
Share on other sites

@Crosire: The .net script hook for GTA IV has an AlwaysKeepTask property. Has this yet to be implemented or isn't that necessary anymore with GTA V? I'm asking because if not then I can remove those lines of code from my migrated GTA IV mods (currently commented out).

Link to comment
Share on other sites

@Crosire: The .net script hook for GTA IV has an AlwaysKeepTask property. Has this yet to be implemented or isn't that necessary anymore with GTA V? I'm asking because if not then I can remove those lines of code from my migrated GTA IV mods (currently commented out).

 

There's a native function "PED::SET_PED_KEEP_TASK", but i don't know if it's what you're talking about. ^^'

Link to comment
Share on other sites

What a great coincidence(?). @IncoCode implemented it just an hour ago.

Thank you Inco. :)

Edited by Cyron43
Link to comment
Share on other sites

Can someone give me a hint how can I get entity hash from target? I tried Game.Player.GetTargetedEntity().Model.Hash but it works only on peds and vehicles, and I want to get hash of table, or ramp, or container. Is there a way?

Thanks

Link to comment
Share on other sites

Can someone give me a hint how can I get entity hash from target? I tried Game.Player.GetTargetedEntity().Model.Hash but it works only on peds and vehicles, and I want to get hash of table, or ramp, or container. Is there a way?

Thanks

Game.Player.GetTargetedEntity().GetHashCode();

And with this ?

Link to comment
Share on other sites

Game.Player.GetTargetedEntity().GetHashCode();

And with this ?

 

GetHashCode is a function inherited from System.Object. It's part of .NET, nothing related to GTA. It's to be used as key in hash maps etc. Script Hook implements it by returning the entity handle.

Edited by Crosire
Link to comment
Share on other sites

First you may want to define what you mean by "entity hash". GTA doesn't have such a thing, apart from the entity handle in which case Mcfloys suggestion would work (but you could as well use "Entity.Handle" directly).

Link to comment
Share on other sites

Any other ideas?

Game.Player.GetTargetedEntity().Model.Hash

It's my last anwser for that, can't find anything else ^^'

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 3 Users Currently Viewing
    0 members, 0 Anonymous, 3 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.