find random actor in script (Any help :)

Post » Sun Nov 18, 2012 7:38 am

I am not sure how to do this but in a script fragment on a quest dialogue I want to search for actors around the player and the actor who is part of the quest and the actor would be speaking with.
Id like to exclude finding the player and the actor who is speaking and grab any one else in the cell...


Any examples would be blessed.
User avatar
Bethany Watkin
 
Posts: 3445
Joined: Sun Jul 23, 2006 4:13 pm

Post » Sun Nov 18, 2012 12:02 am

http://www.creationkit.com/FindRandomActor_-_Game
http://www.creationkit.com/FindRandomActorFromRef_-_Game


Oh and/or:
http://www.creationkit.com/FindClosestActor_-_Game
http://www.creationkit.com/FindClosestActorFromRef_-_Game
http://www.creationkit.com/FindClosestReferenceOfAnyTypeInList_-_Game
http://www.creationkit.com/FindClosestReferenceOfAnyTypeInListFromRef_-_Game
http://www.creationkit.com/FindClosestReferenceOfType_-_Game
http://www.creationkit.com/FindClosestReferenceOfTypeFromRef_-_Game



All of which are part of ... http://www.creationkit.com/Game_Script


(that's many blessing, then?! ;))
User avatar
FoReVeR_Me_N
 
Posts: 3556
Joined: Wed Sep 05, 2007 8:25 pm

Post » Sun Nov 18, 2012 5:28 am

Yeah I still need more, The above will return the player of akspeaker in my script. I want a loop which will cover say a cell and grab some actor who is not the game.player() and is not the akspeaker.

I guess I am not good with scripting a loop ? I know all the if then stuff, and what a command is suppose to do... of course find random actor can return the player if its run on the player... which isn't what I want.

h4vent: You will get a temple next :)
User avatar
chirsty aggas
 
Posts: 3396
Joined: Wed Oct 04, 2006 9:23 am

Post » Sun Nov 18, 2012 12:43 am

http://www.creationkit.com/FindRandomActor_-_Game

1. AFAIK, will NOT return the player (because, I assume, you use the player-location as the center of the search radius
2. But that function should - by the sound of it - do exactly what you want?

Well, almost exactly ...

a) You'll need to IF test so that random-guy != akSpeaker
:cool: But I think your problem is that the function might return NONE? Obviously you could find that there is no random, out in the wilds somewhere, if you keep the search-radius too small ...

So I think you are asking how to do a loop that - if the function returns akSpeaker OR returns NONE - calls the function again, until it does return something valid (increasing the search-radius as you go, I assume)?

If the "loop" is your problem, then take a look at this:

http://www.creationkit.com/Complete_Example_Scripts#Cycle_Through_a_List_of_Objects_and_Perform_an_Action_on_Each_Object.28FormLists.29

So you will need to set a top limit for how many tries you are willing to make (iIndex, in the example) ... Just set a value for it, doesn't need to be the number in a list or anything like that ... So 20 will give you twenty tries to find a random

So something like:

int iIndex = 21 ; max number of times we will search (actually, we'll search only 20 times ... )int myRadius = 5 ;search radius stepsActor randomActor ;variable used to test if a random existsActor myRandomGuyIs ;variable to put the guy in when we found him (optional, is already a variable ... I just do stuff this way!)While(iIndex > 0)		iIndex -= 1			Actor randomActor = Game.FindRandomActorFromRef(Game.GetPlayer(), myRadius)		If randomActor != None				;we found someone!				;but is it akSpeaker?					   if randomActor == akSpeaker					   ;no good, extend search radius					   myRadius = myRadius + 5					   ;loop will now rerun					   else					   ;ALL GOOD - This random will do!					   iIndex = -1					   myRandomGuyIs = randomActor					   endIf		Else				;we found no one, so increase the search radius				myRadius = myRadius + 5				;then just continue with the loop		EndIfEndWhile;now finally test whether we got someoneif myRandomGuyIs != None;WooHoo!  Do stuff here ... start a quest or whateverelse;sadly, after 20 tries, we still found no one :(  Try to handle the error somehow ...endIf


Is that what you mean??!
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Sun Nov 18, 2012 1:31 pm

Awesome script layout... Very well done... Great teaching tool... Thanks a million for this...
User avatar
Nancy RIP
 
Posts: 3519
Joined: Mon Jan 29, 2007 5:42 am


Return to V - Skyrim