L0uNGeR Posted May 12, 2011 Share Posted May 12, 2011 (edited) 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 May 13, 2011 by L0uNGeR Link to comment Share on other sites More sharing options...
L0uNGeR Posted May 12, 2011 Author Share Posted May 12, 2011 (edited) 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 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 May 13, 2011 by L0uNGeR Link to comment Share on other sites More sharing options...
MulleDK19 Posted May 13, 2011 Share Posted May 13, 2011 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 More sharing options...
L0uNGeR Posted May 13, 2011 Author Share Posted May 13, 2011 Hi mate, thanks for helping out (again )! 1: MetaDataThis 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 weatherFunction.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 More sharing options...
Donny78 Posted May 14, 2011 Share Posted May 14, 2011 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 More sharing options...
MulleDK19 Posted May 14, 2011 Share Posted May 14, 2011 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 More sharing options...
L0uNGeR Posted May 14, 2011 Author Share Posted May 14, 2011 @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 More sharing options...
MulleDK19 Posted May 14, 2011 Share Posted May 14, 2011 @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 More sharing options...
L0uNGeR Posted May 14, 2011 Author Share Posted May 14, 2011 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 My bad, "Exists()" derived from GTA.Game does exist in my environment. Link to comment Share on other sites More sharing options...
L0uNGeR Posted May 15, 2011 Author Share Posted May 15, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now