Hi all,
Currently working on a Draynor willow tree chopper and banker just as an easy project to fill in time. I'm looking for people's thoughts on the best way to figure out if my current player is chopping or not, the obvious choice is using the player's model ID and this is where I'm having issues.
The problem: My player's model ID is obtained fine, and this is checked roughly every 1000ms when I've started to chop a tree to make sure it doesn't match the model ID of my player when it's idle. However if I let my script run for a while (at most two hours) this will eventually be the thing that breaks my script, for some reason it will error out:
The code:
Simba Code:
function getPlayerModel():uint32;
var
pModel:glModelArray;
begin
playerBox := intToBox(screenCentre.X-113, screenCentre.Y-100, screenCentre.X-109, screenCentre.Y-80); //My TBox co-ordinates
pModel := ogl.getModels(playerBox); //playerBox is just a TBox around my players feet where the model ID of my player is located
result := pModel[high(pModel)].id; //The line causing the below error (line 214)
end;
The error:
Code:
Error: Access violation at line 214
Execution failed.
The following bitmaps were not freed: [0]
The cause: I can only assume that my player's model ID can't be found in the TBox I've supplied for some reason. This is strange because like I said, the script can work for a few hours before the error occurs. I've made the TBox the exact length I believe it needs to be, if it's any bigger it starts to retrieve models of other players/objects.
My other thought was maybe sometimes my script searches for my player's model ID just at the second the ID changes (from idle to animated) and perhaps at the second it checks/the ID changes there isn't a model to return and causes it to crash, is this possible?
The solution: This is where I need suggestions, have I done this the most efficient way? Is there a better way to be looking for my players model, or is this the best way to figure out if my player is chopping a tree in general?
I have two thoughts at the moment, 1) I saw Obscurity's (I think) post/function which is used to shift a model to a different position, I thought maybe if I shift the model ID of my player from being on the ground/character's feet to in the middle of my character's body I might be able to increase the TBox size a bit (if the TBox size is the issue). Although I'm not sure how to implement this...
Other more obvious thought was to stop the script just erroring out when this occurs and instead implement a failsafe. My issue is it happens so infrequently and I don't really know what the cause of it is so I don't really know where to begin with debugging and then implementing. Does the above just look like the array might be empty? And if so I would assume a simple check of the length of the array before assigning the value of it to my function could fix the issue?
Sorry for the long post but I hope I can get some good feedback/suggestions.
Thanks!