Hello
I'm attempting to put together a small script to spawn several different events around the player. I've been reading other peoples' code and trying to make sense of how spawning and assigning tasks and all that sort of good stuff works; I'm finally getting the hang of it. However no matter what I do, the script is producing some rather annoying issues (note: I have the latest scripthook, scripthook.net and advanced script hook installed), I've been searching around the internet for answers to these issues for a while and haven't found anything. There doesn't seem to be much documentation out there for GTAIV scripting (I've got the ScriptHook documentation and using the Object viewer, but they lack examples and whilst a good resource, aren't enough for a newb) I simply cannot get these fixed so I'm posting here for some assistance:
The first issue is quite complicated to explain; somehow the script appears to be causing GTA:EFLC (also note it's the most recent version, 1.1.2.0) to intermittently switch between "Not responding" and apparently loading very slowly when starting up. I've always had to close the game when this happens, the furthest I can get it to go is the TBOG/TLAD menu screen, but the intermittent hanging prevents making any selection. This seems to happen only on installations with scripthook installed (I have several backups, clean one still works). A restart fixes it. Sometimes clearing the settings folder from App Data fixes it, sometimes minimizing the game and re-opening whilst it's loading fixes it. Sometimes calling it a swine fixes it. Truth be told I don't know what's causing this and I don't know exactly how to fix it (bar restarting my computer which is just a pain). It would appear to happen after I've had to close the game due to the game freezing because of - I suspect - my script. It's extremely frustrating though, it makes for a hard time just trying to get in-game to test the script. Anyone have any ideas why this would happen?
The second issue is more related to the script (once the game stops messing around and loads up). It will not stop giving me the following error:
| QUOTE |
Error during Tick in script 'Policing.Policing': System.NullReferenceException: Object reference not set to an instance of an object. at Policing.Policing.PolicingTick(Object sender, EventArgs e) at GTA.Script.TryTick() at GTA.Script.DoTick() at GTA.ScriptThread.OnTick()
|
What causes this error? I've tried everything to fix it, I've tried a straight copy paste of other working scripts to removing everything from my script and ONLY running the following (sometimes the script is fine until I 'reloadscripts' then the error starts appearing):
| CODE |
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using GTA;
namespace Policing { public class Policing : Script {
Ped Person = null; Blip PersonMarker = null; AnimationSet Anim1 = new AnimationSet("amb@bum_c"); AnimationSet Anim2 = new AnimationSet("amb@drunk"); AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09 | AnimationFlags.Unknown06;
Blip CreateMarker(Ped person, BlipIcon icon, string name) { Blip blip = person.AttachBlip(); blip.Icon = icon; blip.Name = name; return blip; }
private static void DeleteBlip(Blip blip) { blip.Delete(); }
public int random_num(int min, int max) { Random random = new Random(); return random.Next(min, max); }
public Policing() { Game.DisplayText(" Running Policing script by Braveheart", 7000); Interval = 30000; this.Tick += new EventHandler(this.Policing_Tick); }
public void Policing_Tick(object sender, EventArgs e) { Person = World.GetRandomPed(Player.Character.Position, 8.0f);
if (Person != null && Person.Exists() && Person.isAlive && Person.Position.DistanceTo(Player.Character.Position) <= 500.0f) {
Game.DisplayText("Event 1", 999);
PersonMarker = CreateMarker(Person, BlipIcon.Misc_Revenge, "Suspected D&I");
while (!Person.isInCombat && Person.isAlive) { Person.Task.PlayAnimation(new AnimationSet("amb@bum_c"), "walkcycle_drunk_b", 1.0f, animflags); } } } } }
|
That is only a section of the code there's quite a lot of it, but the error appears to stem from something in there. Sometimes the game will freeze completely and no error is present in the log. I initially thought one of the following was the cause:
Wait()
PlayAnimation
Animation.WaitUntilFinished
World.GetRandomPed
But even after removing all of the above and ONLY having a tick with nothing inside of it, I still get the error.
So then, anyone have any ideas on the first issue? What about the script error, where does it come from and how should I look to fix it? When using World.GetRandomPed, what's the largest float radius I can (or should) use?
Thanks in advance for any assistance you can provide.
This post has been edited by Braveheartuk on Saturday, Jun 2 2012, 21:23