Quantcast

Jump to content

» «
Photo

My ScriptHook.Net / C# questions

9 replies to this topic
L0uNGeR
  • L0uNGeR

    Ya, that's what I said.

  • Members
  • Joined: 03 Dec 2008

#1

Posted 12 May 2011 - 09:47 PM Edited by L0uNGeR, 13 May 2011 - 09:57 PM.

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?
QUOTE
CODE
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.)
CODE
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)

L0uNGeR
  • L0uNGeR

    Ya, that's what I said.

  • Members
  • Joined: 03 Dec 2008

#2

Posted 12 May 2011 - 09:51 PM Edited by L0uNGeR, 13 May 2011 - 10:02 PM.

SOLVED/ANSWERED QUESTIONS


1: MetaData
QUOTE
How can I use MetaData without compiling my script?
Like this:
CODE
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
QUOTE (MulleDK19 @ May 13 2011, 13:26)
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
QUOTE
What's wrong with this?
I'm actually trying to use this native because __ World.Weather = Weather.Sunny; __ doesn't seem to work.
CODE
GTA.Native.Function.Call("FORCE_WEATHER_NOW", Weather.Sunny);
Error 2 Argument 2: cannot convert from 'GTA.Weather' to 'GTA.Native.Parameter[]'

Answer
QUOTE
QUOTE (MulleDK19 @ May 13 2011, 13:26)
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
CODE
   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);
       }
   }

MulleDK19
  • MulleDK19

    1337 Programmer

  • Members
  • Joined: 30 May 2009

#3

Posted 13 May 2011 - 11:26 AM

1: MetaData
QUOTE
Hoaw can I use MetaData without compiling my script?
Like this:
CODE
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?
QUOTE
CODE
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.)
CODE
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
QUOTE
What's wrong with this?
I'm actually trying to use this native because __ World.Weather = Weather.Sunny; __ doesn't seem to work.

CODE
GTA.Native.Function.Call("FORCE_WEATHER_NOW", Weather.Sunny);
Error 2 Argument 2: cannot convert from 'GTA.Weather' to 'GTA.Native.Parameter[]'
CODE
GTA.Native.Function.Call("SET_CHAR_MOVE_ANIM_SPEED_MULTIPLIER", pl, MySettings.CharSpeedMultiplier);
Works fine
CODE
GTA.Native.Function.Call("SET_PLAYER_MOOD_NORMAL", Player.Index);
Works fine
CODE
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.

L0uNGeR
  • L0uNGeR

    Ya, that's what I said.

  • Members
  • Joined: 03 Dec 2008

#4

Posted 13 May 2011 - 09:44 PM

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

QUOTE (MulleDK19 @ May 13 2011, 13:26)
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.

QUOTE (MulleDK19 @ May 13 2011, 13:26)
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.
CODE
           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.

QUOTE (MulleDK19 @ May 13 2011, 13:26)
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.


Donny78
  • Donny78

    Zombie

  • Members
  • Joined: 18 Jul 2008

#5

Posted 14 May 2011 - 09:38 AM

CODE

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:

CODE

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.

MulleDK19
  • MulleDK19

    1337 Programmer

  • Members
  • Joined: 30 May 2009

#6

Posted 14 May 2011 - 10:52 AM

QUOTE (L0uNGeR @ May 13 2011, 21:44)
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).

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

L0uNGeR
  • L0uNGeR

    Ya, that's what I said.

  • Members
  • Joined: 03 Dec 2008

#7

Posted 14 May 2011 - 01:57 PM

@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?

MulleDK19
  • MulleDK19

    1337 Programmer

  • Members
  • Joined: 30 May 2009

#8

Posted 14 May 2011 - 05:21 PM

QUOTE (L0uNGeR @ May 14 2011, 13:57)
@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.



QUOTE (L0uNGeR @ May 14 2011, 13:57)
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.



QUOTE (L0uNGeR @ May 14 2011, 13:57)
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();

L0uNGeR
  • L0uNGeR

    Ya, that's what I said.

  • Members
  • Joined: 03 Dec 2008

#9

Posted 14 May 2011 - 06:42 PM

QUOTE (MulleDK19 @ May 14 2011, 19:21)
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?


QUOTE (MulleDK19 @ May 14 2011, 19:21)
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.


QUOTE (MulleDK19 @ May 14 2011, 19:21)
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.

L0uNGeR
  • L0uNGeR

    Ya, that's what I said.

  • Members
  • Joined: 03 Dec 2008

#10

Posted 15 May 2011 - 08:46 PM

QUOTE (MulleDK19 @ May 14 2011, 12:52)
QUOTE (L0uNGeR @ May 13 2011, 21:44)
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users