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. Support

    3. Suggestions

My ScriptHook.Net / C# questions


L0uNGeR
 Share

Recommended Posts

I will use this topic to keep track of the questions I might have and will update the post with solutions.

Thanks to anyone who is trying to help!

Solved questions will be moved to the second post, if you still have any info to add, just reply.

 

2: CreatePed() limitation?

 

World.CreatePed()

 

A lot of times this spawns less peds than I want, or spawns no peds at all, is there some sort of restriction in the ScriptHook, or in the game engine?

Sometimes it also gives an error, which has something to do with CurrentRoom it seems.

(After using World.CreatePed() I use p.CurrentRoom = pl.CurrentRoom;, so it should be ok.)

 

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.  at NativeInvoke.Invoke<int,int,int>(SByte* name, Int32 p1, Int32 p2)  at Scripting.?A0x5984d89a.SetRoomForCharByKey(Int32 , Int32 )  at GTA.Ped.set_CurrentRoom(Room value)

 

Edited by L0uNGeR
Link to comment
Share on other sites

SOLVED/ANSWERED QUESTIONS

 

 

1: MetaData

 

How can I use MetaData without compiling my script?

Like this:

 

p.Metadata.StuffWasDone = true;if (p.Metadata.StuffWasDone)   Game.DisplayText("Stuff was done!");

This works fine when I compile my script into a DLL.

But when I use a plain script, it keeps whining about Microsoft.CSharp.RuntimeBinder.Binder, which I cannot seem to find/include/use.

I must be missing something in my Visual C#...

Answer

 

This is most likely a limitation of using plain scripts with the .NET Script Hook.

The only thing you can do, is either compile it yourself, or wait for an update for .NET Script Hook.

 

3: Changing weather

 

What's wrong with this?

I'm actually trying to use this native because __ World.Weather = Weather.Sunny; __ doesn't seem to work.

 

GTA.Native.Function.Call("FORCE_WEATHER_NOW", Weather.Sunny);

Error 2 Argument 2: cannot convert from 'GTA.Weather' to 'GTA.Native.Parameter[]'

Answer

 

Function.Call does not support GTA.Weather. Try Convert.ToInt32(Weather.Sunny).

Also, weather sometimes takes some time to change. Try using World.Weather, and just wait a little.

I waited a long time but it never changed to what I wanted.

Fortunately, the Convert.ToInt32() works, the weather changes instantly!

Here's a working example that I made wink.gif

 

    public class AlwaysSunny : Script   {       public AlwaysSunny()       {           Interval = 10000;           //if (MySettings.EnableAlwaysSunny)               this.Tick += new EventHandler(AlwaysSunny_Tick);       }       internal void AlwaysSunny_Tick(object sender, EventArgs e)       {           //if (!MySettings.AlwaysSunnyEnabled) return;           int weather = Convert.ToInt32(Weather.ExtraSunny);           GTA.Native.Function.Call("FORCE_WEATHER_NOW", weather);       }   }

 

Edited by L0uNGeR
Link to comment
Share on other sites

1: MetaData

 

Hoaw can I use MetaData without compiling my script?

Like this:

 

p.Metadata.StuffWasDone = true;if (p.Metadata.StuffWasDone)   Game.DisplayText("Stuff was done!");

 

This works fine when I compile my script into a DLL.

But when I use a plain script, it keeps whining about Microsoft.CSharp.RuntimeBinder.Binder, which I cannot seem to find/include/use.

I must be missing something in my Visual C#...

This is most likely a limitation of using plain scripts with the .NET Script Hook.

The only thing you can do, is either compile it yourself, or wait for an update for .NET Script Hook.

 

2: CreatePed() limitation?

 

World.CreatePed()

 

A lot of times this spawns less peds than I want, or spawns no peds at all, is there some sort of restriction in the ScriptHook, or in the game engine?

Sometimes it also gives an error, which has something to do with CurrentRoom it seems.

(After using World.CreatePed() I use p.CurrentRoom = pl.CurrentRoom;, so it should be ok.)

 

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.  at NativeInvoke.Invoke<int,int,int>(SByte* name, Int32 p1, Int32 p2)  at Scripting.?A0x5984d89a.SetRoomForCharByKey(Int32 , Int32 )  at GTA.Ped.set_CurrentRoom(Room value)

 

Peds are not spawned if your game settings does not allow it. Increase your video settings.

The exception you're getting is most likely because the Ped doesn't actually exist in-game. Use Game.Exists to verify before use.

 

3: Changing weather

 

What's wrong with this?

I'm actually trying to use this native because __ World.Weather = Weather.Sunny; __ doesn't seem to work.

 

 

GTA.Native.Function.Call("FORCE_WEATHER_NOW", Weather.Sunny);

Error 2 Argument 2: cannot convert from 'GTA.Weather' to 'GTA.Native.Parameter[]'

 

GTA.Native.Function.Call("SET_CHAR_MOVE_ANIM_SPEED_MULTIPLIER", pl, MySettings.CharSpeedMultiplier);

Works fine

 

GTA.Native.Function.Call("SET_PLAYER_MOOD_NORMAL", Player.Index);

Works fine

 

GTA.Native.Function.Call("SET_CHAR_CAN_BE_SHOT_IN_VEHICLE", pl, false);

Works fine

 

Function.Call does not support GTA.Weather. Try Convert.ToInt32(Weather.Sunny).

Also, weather sometimes takes some time to change. Try using World.Weather, and just wait a little.

Link to comment
Share on other sites

Hi mate, thanks for helping out (again wink.gif)!

 

 

1: MetaData

This is most likely a limitation of using plain scripts with the .NET Script Hook.

The only thing you can do, is either compile it yourself, or wait for an update for .NET Script Hook.

Thanks, I'll set that one to solved.

 

 

2: CreatePed() limitation?

Peds are not spawned if your game settings does not allow it. Increase your video settings.

The exception you're getting is most likely because the Ped doesn't actually exist in-game. Use Game.Exists to verify before use.

I have my PedDensity almost always on x3, I have many peds all the time.

For checks I use !null && Ped.Exist(), shouldn't that be enough?

I'll just paste the whole thing.

 

            Ped p, pl = Player.Character;           Vector3 spawnPosition;           float offsetY;           int i, spawned = 0;           for (i = 0; i < 6; i++)           {               if (pl.isInVehicle())               {                   offsetY = 20 + (i * 3.5f);                   spawnPosition = World.GetGroundPosition(pl.CurrentVehicle.GetOffsetPosition(new Vector3(0f, offsetY, 0f)));                   p = World.CreatePed(spawnPosition, Gender.Female);               }               else               {                   p = World.CreatePed(pl.Position.Around(4f), Gender.Female);               }               if (p != null && p.Exists())               {                   p.CurrentRoom = pl.CurrentRoom;                   p.AlwaysDiesOnLowHealth = true;                   p.RelationshipGroup = RelationshipGroup.Civillian_Female;                   p.SetPathfinding(true, true, true);                   p.NoLongerNeeded();                   spawned++;               }           }

 

I don't see what's wrong with this.

 

 

3: Changing weather

Function.Call does not support GTA.Weather. Try Convert.ToInt32(Weather.Sunny).

Also, weather sometimes takes some time to change. Try using World.Weather, and just wait a little.

I waited a long time but it never changed to what I wanted.

Fortunately, the Convert.ToInt32() works, the weather changes instantly!

I'll set this one to solved too.

 

 

Link to comment
Share on other sites

 

p.NoLongerNeeded();

 

 

Seems wrong to me, you're telling the game it no longer needs the ped you've just created (I've never used that function so could be wrong).

 

Also add debug prints in your code like so:

 

 

if (p != null && p.Exists()){   Game.DisplayText("Ped created, spawned count is: " + spawned.ToString());   // rest of code

 

 

And clear the Ped variable, "p = null" after each itteration so the loops code isn't trying to use the last created ped, if both "CreatePed" functions have failed on this itteration then it should be null not the previous peds id.

Link to comment
Share on other sites

I have my PedDensity almost always on x3, I have many peds all the time.

There's your problem. The game denies the spawn because there's already too many peds.

 

Set it to 1.

 

 

 

Also, use Game.Exists(object). It's a lot easier. From the script itself, you can even just do Exists(object).

 

 

if(Exists(ped)){   //Whatever}

 

Link to comment
Share on other sites

@Donny78:

 

NoLongerNeeded() is pretty important, it makes sure the game doesn't "keep" them. This means that when you DONT use NoLongerNeeded(), the peds (or vehicles) will stay in your map forever, we don't want that unless you need to do something special to them.

 

I already have a code that tells me the amount of peds that are spawned, it's actually after the loop and uses the "spawned" integer.

 

The "null" part seems useful, indeed I forgot to set it to "null" again.

 

 

@MulleDK19

 

I will try setting the peds lower (which is actually what I DONT want).

 

About the Game.Exists(), I couldn't get that on my setup....

I guess it's different from "Ped.Exist()" like I use at the moment?

Link to comment
Share on other sites

 

@Donny78:

NoLongerNeeded() is pretty important, it makes sure the game doesn't "keep" them. This means that when you DONT use NoLongerNeeded(), the peds (or vehicles) will stay in your map forever, we don't want that unless you need to do something special to them.

No need to call NoLongerNeeded(). Spawned peds are already marked as "No longer needed".

 

Unless you use BecomeMissionCharacter() or set isRequiredForMission to true, there's no need to call it.

 

 

 

 

I will try setting the peds lower (which is actually what I DONT want).

Well, unless you have sky rocketing amounts of video memory, it's a limit you're gonna have to live with.

 

 

 

 

About the Game.Exists(), I couldn't get that on my setup....

I guess it's different from "Ped.Exist()" like I use at the moment?

 

If you haven't used the "using GTA;" directive, then you'll need to access it by GTA.Game.Exists.

 

Game.Exists(ped), simply does return ped != null && ped.Exists();

Link to comment
Share on other sites

 

No need to call NoLongerNeeded(). Spawned peds are already marked as "No longer needed".

 

Unless you use BecomeMissionCharacter() or set isRequiredForMission to true, there's no need to call it.

If I don't use "NoLongerNeeded()", peds will exist forever in my game, it's suppose to do this.

I saw HazardX using it on vehicles, why would the function be useless on peds?

 

 

 

Well, unless you have sky rocketing amounts of video memory, it's a limit you're gonna have to live with.

Yeh, I guess so...

I'll do some tests tonight to find the proper balance.

 

 

 

If you haven't used the "using GTA;" directive, then you'll need to access it by GTA.Game.Exists.

 

Game.Exists(ped), simply does  return ped != null && ped.Exists();

Of course I use the GTA directive wink.gif

My bad, "Exists()" derived from GTA.Game does exist in my environment.

Link to comment
Share on other sites

I have my PedDensity almost always on x3, I have many peds all the time.

There's your problem. The game denies the spawn because there's already too many peds.

 

Set it to 1.

I did some tests on this, and this is most likely the cause.

Lowering the PedDensity to 0.0 makes my script spawn a lot more, still not EVERY time though.

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

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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