Please help me fix this script.

Post » Fri Sep 23, 2011 12:49 pm

I'm still new to scripting, so this could be completely wrong, I'm not sure.

What it's supposed to do is, if you're close to the NPC (I don't know how far away 200 is, but I saw it in an example somewhere so I just used it to test. GetPCCell didn't work either though, so I figure that's not the problem.) and you're being attacked, the NPC will escort you, until you're no longer under attack, and then return to is original location. (I'm just assuming escort will cause them to attack whatever is attacking you. I don't actually know. I added a messagebox in the same spot to test it though, and that never appeared, so the problem lies elsewhere.)

The "gettarget player" part is so the guards don't help you if you if you steal something/attack them or a civilian.
The extra else/return in GetDistance was to make sure the aitravel function doesn't happen constantly, because the player isn't usually going to be under attack. There's probably a better way to do that, but I never got far enough to figure that out.

Begin guardscriptfloat distanceshort attackedif ( GetDistance, player <= 200 )	set distance to 1else	returnendifif (GetTarget player == 1 )	returnendifif ( GetAttacked, player == 1 )	set attacked to 1endifif ( attacked == 0 )	AiTravel, 43754 18957 1707	returnendifif ( distance == 1 )if ( attacked == 1 )	AiEscort, player 0 0 0 0else	returnendifendifend


Edit: I've determined that GetAttacked is the part that isn't working, but I can't find another function that works in this situation. HitAttemptOnMe doesn't work either. I just need some way to check if the player is in combat... but it's getting late, and I'm too tired to keep thinking about it.
User avatar
Claire Lynham
 
Posts: 3432
Joined: Mon Feb 12, 2007 9:42 am

Return to III - Morrowind