How Far Away An Enemy Is

Post » Fri May 27, 2011 9:31 am

How could I script a spell that tells the player how far away the nearest enemy is? I'm going to use an AOE spell that records the distance of any nearby enemies, but I don't know how to then single out the shortest distance.

Any help?
User avatar
Marquis deVille
 
Posts: 3409
Joined: Thu Jul 26, 2007 8:24 am

Post » Fri May 27, 2011 1:23 am

Declare a variable in a quest script (quest called 'YourQuest', variable called 'Var' in the following), then use this as spell script

float distref mebegin scripteffectstartset me to getselfset dist to me.getdistance player  if YourQuest.Var == 0	set YourQuest.var to dist  elseif dist < YourQuest.Var 	set YourQuest.Var to dist  endifend


That should work. You need to set the quest variable back to 0 after the message has been displayed that tells the player how close the nearest enemy is. Or even better, start the quest only when the spell is active and stop it directly afterwards. That should reset all variables each time automatically.
User avatar
StunnaLiike FiiFii
 
Posts: 3373
Joined: Tue Oct 31, 2006 2:30 am

Post » Fri May 27, 2011 1:38 pm

That's perfect! Thank you very much!
User avatar
Tanya Parra
 
Posts: 3435
Joined: Fri Jul 28, 2006 5:15 am


Return to IV - Oblivion