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

Hello @Crosire do you think you will implement the getclosestped that was in the gta iv .net scripthook?

as that would be great and help me out with getting the closestped to the player instead of basically having no easy way of doing it.

See https://github.com/crosire/scripthookvdotnet/commit/2fc0f5de388f768eaaced449f19be62c7a1f822a. But it didn't test it yet.

 

I've been trying to have some functions execute as soon as the game loads but I can't seem to get it to work. The onTick event seems to begin firing before the story mode has fully loaded, and I have tried waiting for Player.CanControlCharacter to return true before calling the functions but even that seems to return true before the game loads. An event like 'onGameLoad' would be very helpful, or just something that is definitely true only when the game has fully loaded that I can check.

The game starts executing scripts when still on the loading screen, not much can be done about that. I don't know if there is a native to check if one is still sitting on the loading screen or not? But without that such an event is a bit complicated.

 

 

The wiki probably should be updated with the following to work with the latest version of the .net loader.

Done. Thanks for reporting!

Link to comment
Share on other sites

qwerasdzxc

Can someone show me function and usage for GET_VEHICLE_PED_IS_USING please?

I can't get it to work.

Link to comment
Share on other sites

Can someone show me function and usage for GET_VEHICLE_PED_IS_USING please?

Why not simply:

Ped myPed = ...;Vehicle myVehicle = myPed.CurrentVehicle;
Link to comment
Share on other sites

qwerasdzxc

 

Can someone show me function and usage for GET_VEHICLE_PED_IS_USING please?

Why not simply:

Ped myPed = ...;Vehicle myVehicle = myPed.CurrentVehicle;

Okay, I realised that that's not what I wanted at first place.

I want to spawn last vehicle that I was driving, any help for that?

Link to comment
Share on other sites

Okay, I realised that that's not what I wanted at first place.

I want to spawn last vehicle that I was driving, any help for that?

 

 

 

Just use LastVehicle on your player object.

Link to comment
Share on other sites

qwerasdzxc

 

Okay, I realised that that's not what I wanted at first place.

I want to spawn last vehicle that I was driving, any help for that?

Just use LastVehicle on your player object.

 

'GTA.Ped' does not contain a definition for 'LastVehicle'

And also when I try to spawn the car it says that it cannot convert from 'GTA.Vehicle' to 'GTA.Model' if I use something like Crosire suggested me.

 

I am new to this so sorry if I'm acting a little newbish :)

Edited by qwerasdzxc
Link to comment
Share on other sites

Try GTA.Player Game.Player* (That's a big difference, sorry) ;-)

Edited by Mcfloy
Link to comment
Share on other sites

unknown modder

Hello @Crosire do you think you will implement the getclosestped that was in the gta iv .net scripthook?

as that would be great and help me out with getting the closestped to the player instead of basically having no easy way of doing it.

GetClosestPed like how iv net hook worked wont be here for a while. the way it worked on iv was manually searching the ped pool in memory. The GET_CLOSEST_PED native works, but wont find every kind of ped. GET_PED_NEARBY_PEDS only works with a ped handle, you cant plug game coordinates into there.

Link to comment
Share on other sites

 

The game starts executing scripts when still on the loading screen, not much can be done about that. I don't know if there is a native to check if one is still sitting on the loading screen or not? But without that such an event is a bit complicated.

 

 

Damn. Essentially what I want to do is create a blank or 'sandbox' environment in order to run my new planned single player game mode in, with no story elements getting in the way. What I currently do is kill all the game scripts currently active, using this list kindly provided by MulleDK19: http://link.to.mycomputer.treesoft.dk:1337/temp/clipboard%2816%29.txt

 

This works fine if I activate this while in game, e.g. with a button press, but if its exectued during the loading screen it prevents the game from loading - and I've yet to figure out how to call the scripts just after the game has fully loaded.

 

I wonder if the devs ever hardcoded in a sandbox environment themselves for testing, or if there is some other way to go about what I'm trying to achieve? Any help would be greatly appreciated.

 

Incidentally do you use IRC at all?

Link to comment
Share on other sites

qwerasdzxc

Try GTA.Player Game.Player* (That's a big difference, sorry) ;-)

Nah, can't get it to work :( I'll PM you so we can keep the conversation there if you don't mind?

Link to comment
Share on other sites

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.

 

Since it's my first post here, let me say great job to all of you who make modding better every day.

 

PD: and my English is not perfect, apologies for it.

Link to comment
Share on other sites

 

Try GTA.Player Game.Player* (That's a big difference, sorry) ;-)

Nah, can't get it to work :( I'll PM you so we can keep the conversation there if you don't mind?

 

Vehicle veh = Game.Player.LastVehicle;Vehicle newVeh = World.CreateVehicle( veh.Model, Game.Player.Character.Position );

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;
Edited by Inco
Link to comment
Share on other sites

qwerasdzxc

 

 

Try GTA.Player Game.Player* (That's a big difference, sorry) ;-)

Nah, can't get it to work :( I'll PM you so we can keep the conversation there if you don't mind?

 

Vehicle veh = Game.Player.LastVehicle;Vehicle newVeh = World.CreateVehicle( veh.Model, Game.Player.Character.Position );

Yeah, thanks works now, I didn't use veh.Model, just veh so that was the problem.

Link to comment
Share on other sites

I am about to migrate my Undertaker mod from GTA IV but my code doesn't recognize dead peds. Here are the responsible excerpts:

      private IEnumerable<Ped> GetPedsAround()      {         var pedsAround =            World.GetNearbyPeds(Game.Player.Character, _commonObjects.Configuration.CollectionRadius).ToList();         if(pedsAround.Count == 0)            ReleaseUndertaker("Whoops, the undertaker had an accident! Call him again.");         UI.Notify("DEBUG: " + pedsAround.Count + " peds found.");         return pedsAround;      }      private void RegisterDeadBodies()      {         lock(SyncLock)         {            if(!CommonFunctions.PedExists(Game.Player.Character))            {               _fail = true;               UI.ShowSubtitle(                  "ERROR: Game claims player character doesn't exist anymore. Please try again.", 5000);               return;            }            foreach(var ped in GetPedsAround().Where(ped => !ped.IsAlive || ped.IsDead || ped.Health <= 0))            {               if(CommonFunctions.PedExists(ped))               {                  var newDeadPed = EnsureDeadPedIsNotAlreadyRegistered(ped);                  if(newDeadPed == null)                     continue;                  newDeadPed.SetRequiredForMission(true);                  _commonObjects.DeadPedsAround.Add(newDeadPed);               }            }            UI.Notify("DEBUG: " + _commonObjects.DeadPedsAround.Count + " dead peds found.");         }      }      private Ped EnsureDeadPedIsNotAlreadyRegistered(Ped ped)      {         if(_commonObjects.DeadPedsAround.Exists(p => ReferenceEquals(p, ped)))            return null;         return ped;      }

Usually I just check the Ped.IsDead property but that didn't work and so I also checked !Ped.IsAlive and Ped.Health but still nothing.

As you can see by the debug messages in the screenshot the code finds two peds but allegedly none of them is dead.

9iacyw.jpg

Edited by Cyron43
Link to comment
Share on other sites

How can i get the purple target position on the map ? (If there's a function uncrypted)

Link to comment
Share on other sites

I am about to migrate my Undertaker mod from GTA IV bu my code doesn't recognize dead peds. Here are the responsible excerpts:

      private IEnumerable<Ped> GetPedsAround()      {         var pedsAround =            World.GetNearbyPeds(Game.Player.Character, _commonObjects.Configuration.CollectionRadius).ToList();         if(pedsAround.Count == 0)            ReleaseUndertaker("Whoops, the undertaker had an accident! Call him again.");         UI.Notify("DEBUG: " + pedsAround.Count + " peds found.");         return pedsAround;      }      private void RegisterDeadBodies()      {         lock(SyncLock)         {            if(!CommonFunctions.PedExists(Game.Player.Character))            {               _fail = true;               UI.ShowSubtitle(                  "ERROR: Game claims player character doesn't exist anymore. Please try again.", 5000);               return;            }            foreach(var ped in GetPedsAround().Where(ped => !ped.IsAlive || ped.IsDead || ped.Health <= 0))            {               if(CommonFunctions.PedExists(ped))               {                  var newDeadPed = EnsureDeadPedIsNotAlreadyRegistered(ped);                  if(newDeadPed == null)                     return;                  newDeadPed.SetRequiredForMission(true);                  _commonObjects.DeadPedsAround.Add(newDeadPed);               }            }            UI.Notify("DEBUG: " + _commonObjects.DeadPedsAround.Count + " dead peds found.");         }      }      private Ped EnsureDeadPedIsNotAlreadyRegistered(Ped ped)      {         if(_commonObjects.DeadPedsAround.Exists(p => ReferenceEquals(p, ped)))            return null;         return ped;      }
Usually I just check the Ped.IsDead property but that didn't work and so I also checked !Ped.IsAlive and Ped.Health but still nothing.

As you can see by the debug messages in the screenshot the code finds two peds but allegedly none of them is dead.

 

Add some debug message to check if you got in foreach. The problem could be in your CommonFunctions.PedExists() method.

How can i get the purple target position on the map ? (If there's a function uncrypted)

Wait for approval World::GetActiveBlips() method. With this method you can do following:

// type 4 - player's markerBlip blip = World.GetActiveBlips().FirstOrDefault( b => b.Type == 4 );if ( blip != null ){    player.Position = blip.Position;    UI.ShowSubtitle( "Done", 2000 );}else{    UI.ShowSubtitle( "Not found", 2000 );}
Edited by Inco
Link to comment
Share on other sites

Hi @Inco. CommonFunctions.PedExists just adds a null check to the Exists method of the .net script hook. I don't know if this is necessary with this one. It's a remnant from EFLC times where it was a necessity. I will do as you suggest just to make sure. I'll be back soon...

      public static bool PedExists(Ped ped)      {         lock(SyncLock)         {            return ped != null && ped.Exists();         }      }
Edited by Cyron43
Link to comment
Share on other sites

@Cyron43, just checked IsDead property and it's works fine.

I have set a debug message into the foreach loop right at the start but it never appeared in the game. So my conclusion is that none of the checks in the Where clause returned true. Heck! o_0

EDIT: Found something interesting. I inserted a kill for debugging and the fresh kills got registered (6). I dismissed the undertaker before he could collect the dead bodies. Then I waited for a few seconds and called him again and 4 new peds got killed and registered BUT not the other 6 from before!

Is it, by any chance, possible that the game replaces dead peds after a short while with some "puppet" objects that just look like peds?

EDIT2: Yep Trevor was surrounded by 10 dead bodies but the debug message claims there were 0 peds (dead or alive) around.

      private void RegisterDeadBodies()      {         lock(SyncLock)         {            if(!CommonFunctions.PedExists(Game.Player.Character))            {               _fail = true;               UI.ShowSubtitle(                  "ERROR: Game claims player character doesn't exist anymore. Please try again.", 5000);               return;            }            foreach(var ped in GetPedsAround())            {               UI.Notify("foreach loop");               KillForDebug(ped);               if(!ped.IsAlive || ped.IsDead || ped.Health <= 0)               {                  if(CommonFunctions.PedExists(ped))                  {                     var newDeadPed = EnsureDeadPedIsNotAlreadyRegistered(ped);                     if(newDeadPed == null)                        continue; //question: shouldn't it be continue?                     newDeadPed.SetRequiredForMission(true);                     _commonObjects.DeadPedsAround.Add(newDeadPed);                  }               }            }            UI.Notify("DEBUG: " + _commonObjects.DeadPedsAround.Count + " dead peds found.");         }      }      private void KillForDebug(Ped ped)      {         if(!ReferenceEquals(Game.Player.Character, ped))            ped.Kill();      }
Edited by Cyron43
Link to comment
Share on other sites

It seems like GetNearbyPeds returns only alive peds.

 

 

2e38x2c.jpg

2lnepuw.jpg

 

 

Code:

IEnumerable<Ped> GetPedsAround(){	return World.GetNearbyPeds( Game.Player.Character, 3f ).ToList();}void OnKeyDown( object sender, KeyEventArgs e ){	Ped player = Game.Player.Character;	if ( e.KeyData == Keys.I )	{		UI.ShowSubtitle( "Peds: " + this.GetPedsAround().Count(), 2000 );	}	if ( e.KeyData == Keys.L )	{		_peds.Add( World.CreatePed( PedHash.Beach01AFM, player.Position ) );		_peds.Add( World.CreatePed( PedHash.Beach01AFM, player.Position ) );		foreach ( Ped ped in _peds )		{			ped.BlockPermanentEvents = true;		}	}}
Edited by Inco
Link to comment
Share on other sites

Could someone provide me with an example of displaying text clearly at the centre of the screen? Thanks.

 

edit: nevermind figured it out, forgot it had to be drawn every tick!

Edited by Andross90
Link to comment
Share on other sites

Edit: Nevermind

Edited by Nacorpio
Link to comment
Share on other sites

Thank you for your help @Inco. Now that's a problem. I just had a look into the natives db (keyword "dead") but I couldn't find anything appropriate. :-/

@Nacorpio: That's a misunderstanding. I do the null check because GTA IV caused object disposing all the time to reduce memory consumption and so each time I want to access a vehicle or a ped I had to check for it's existence before. As I said before this is a remnant from GTA IV times and I don't know if this is still necessary with GTA V but at least it shouldn't cause a problem to do an extra check. Inco is right, GetNearbyPeds is the culprit.

Anyway I modified the code but that doesn't fix it. The code is just more logical now.

 

//...if(CommonFunctions.PedExists(ped) && !_commonObjects.DeadPedsAround.Contains(ped))               {                  ped.SetRequiredForMission(true);                  _commonObjects.DeadPedsAround.Add(ped);               }               else                  continue;               //...      
Edited by Cyron43
Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

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?

Are you calling those in a "Tick" event? They each end in "THIS_FRAME" - so they'll all need to be called once each frame. I think you can do this with a Tick event with Interval set to 0 (once per frame).
Link to comment
Share on other sites

How we create and handle objecs in .net scripthookv? im trying to use the CREATE_OBJECT native but i cant obtain a entity to handle (dont know what is the correct type to use as return). SO, i sapwn the object but cant control it.

Also, someone have used the DELETE_ROPE method? I always obtain scripthook .asi script crash (asi loader message) when i try to use it (im using Native.InputArgument in the parameter)

Link to comment
Share on other sites

Hello, is there a method which will return all vehicle models?

VehicleHash[] allModels = Enum.GetValues( typeof( VehicleHash ) ).Cast<VehicleHash>().ToArray();

Why not :)

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.