Jump to content

help with script FindClosestReferenceOfAnyTypeInListFromRef


firepower02

Recommended Posts

My script is

 

ObjectReference ClosestMarker = Game.FindClosestReferenceOfAnyTypeInListFromRef(IdleList, Caster, Distance)

while (closestMarker == none)
ClosestMarker = Game.FindClosestReferenceOfAnyTypeInListFromRef(IdleList, Caster, Distance)
endwhile

 

but it can't seem to find an object reference in the formlist. It returns none. Does the while statement suppose to make it keep looking until it finds one?

 

 

Link to comment
Share on other sites

Based on your script you will be stuck in the while loop until ClosestMarker finds something. I would do a few things to alter your code to help you debug a little. This will let you know if you entered the loop and what your function is finding. Also make sure that you capitalize the C in closestMarker in your while loop. Your variable name must be consistent throughout your code. If you find you are not entering the loop try it without the while loop and see if you can get FindClosestReferenceOfAnyTypeInListFromRef to return something. Once you have that figured out then add the while loop back in.

 

while (ClosestMarker==none)
ClosestMarker = Game.FindClosestReferenceOfAnyTypeInListFromRef(IdleList, Caster, Distance)

debug.notification("ClosestMarker"+ClosestMarker+".")
endwhile

 

Here is my script that uses that same function maybe you can use it as a reference.

scriptName WeaponThrow extends ActiveMagicEffect
import game
import debug
formlist property WeaponList auto
float RadiusToFindWeapon = 2000.0
objectreference WeaponFound 
;objectreference property Target auto 

Event Oneffectstart(Actor akTarget, Actor akCaster)
WeaponFound = game.FindClosestReferenceOfAnyTypeInListFromRef(WeaponList, akCaster, RadiusToFindWeapon)
debug.notification("Weapon Found "+WeaponFound)
debug.notification("akTarget "+akTarget)
;Target.moveto(akTarget,0,0,5,true)
WeaponFound.applyhavokimpulse(0,0,1,50)
;WeaponFound.translatetoref(game.getplayer(),100)
Endevent
Edited by erratichippo
Link to comment
Share on other sites

I have a formlist of all the chairs in game. Adding that line, it will keep saying closestmarker is none. It will keep saying it, so it entered the while loop, but did not find anything. I have placed a chair beside me, still none. Maybe the game does not recognize formlists, I tried using formlist for something else, and it did not understand it.

Link to comment
Share on other sites

This command will always return the object from your form list. If you want to clear the variable ClosestMarker you will have to set it equal to none/0 after it has found the closest object. If you are trying to find multiple objects you are doing it the wrong way. If you want to find multiple objects I would first count the objects in your radius then I would use a for loop to iterate the loop the exact number of times needed. Inside the loop I would try and put the objects inside an array variable.

Link to comment
Share on other sites

I am actually having that very same issue. In my script above I am trying to find a weapon closest to the caster then hurl that weapon toward an enemy. All but one of the functions that relate to object movement dont seem to work in my script. The only thing that seems to work is the function applyhavokimpulse. The other functions moveto, translatetoref,translateto, or pushactoraway dont seem to work on the weapon objects I am finding. Maybe they will work for you give them a try. If you want to try pushactoraway you will need to cast the object reference as an actor. Google casting a variable in papyrus to learn how to do this. If you figure out how to get this to work let me know. I know its possible because I have seen other scripts do it. I just dont know how they did it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...