Loop a script until the player is not present.

Post » Mon Nov 19, 2012 9:14 am

I have a quest in which you kill several bandits, thus liberating a small village. The player is thanked and the quest is completed, and the quest is secretly set to a new stage. In that stages fragment, I basically need a script that waits several ingame hours, then disables the dead bandits bodies, IF the player is not there. I know how to make it wait, and disable, but I'm not clear on how to check if the player is there, and how to make it look (Wait again, then check again) if the player is present.

I've never had to set up a loop before, so I need a quick walkthrough. It's my understanding that papyrus now has go to functions and loops and whatnot, which I think are what I need here?

Any pointers are appreciated. :)

AJV
User avatar
BethanyRhain
 
Posts: 3434
Joined: Wed Oct 11, 2006 9:50 am

Post » Mon Nov 19, 2012 6:02 am

you can't check with "GetPlayerLoc(CellName)" in an if function?
seam to recall i saw something like that in the scripting collection on the crationkit wiki... might just have been me that is tired :)
User avatar
Josh Sabatini
 
Posts: 3445
Joined: Wed Nov 14, 2007 9:47 pm

Post » Mon Nov 19, 2012 3:07 am

Looks like I can use http://www.creationkit.com/IsLoaded_-_Location to check if the location, which I'll attach to the village's cell, is loaded. So that part is solved.
User avatar
Sarah Edmunds
 
Posts: 3461
Joined: Sat Jul 08, 2006 8:03 pm

Post » Mon Nov 19, 2012 1:23 pm

Looks like I can use http://www.creationkit.com/IsLoaded_-_Location to check if the location, which I'll attach to the village's cell, is loaded. So that part is solved.
Yay!
User avatar
Chloe :)
 
Posts: 3386
Joined: Tue Jun 13, 2006 10:00 am

Post » Mon Nov 19, 2012 5:32 am

It's probably worth mentioning that a (non-native) function already exists for just this sort of thing - http://www.creationkit.com/IsNearPlayer_-_ObjectReference.

Spoiler
; Function to know if I'm near the player (whether I can be safely enabled or disabled)bool Function IsNearPlayer()	Actor player = Game.GetPlayer()	Cell targetCell = self.GetParentCell()	Cell playerCell = player.GetParentCell()		if (targetCell != playerCell)		; player and target are in different cells		if (targetCell && targetCell.IsInterior() || playerCell && playerCell.IsInterior())			; in different cells and at least one is an interior			;  -- we can safely enable or disable			return false		else			; both in an exterior -- no means of testing 			;  worldspace at the moment, so this will do.			if (player.GetDistance(self) > 3000)				; pretty darned far away -- safe				return false			else				; too close for comfort				return true			endif		endif	else		; in the same cell -- err on the side of caution		return true	endifendFunction

Cipscis
User avatar
i grind hard
 
Posts: 3463
Joined: Sat Aug 18, 2007 2:58 am

Post » Mon Nov 19, 2012 10:14 am

Kind of a simple question but, does non-native mean it's not in the engine and I'd have to reference another script? I don't need that amount of control, a simple 'is the player within a few cells (I.e. IsLoaded)' function.

The only part I need to figure out now is how to get it to loop until it suceeds.
User avatar
Nicole Kraus
 
Posts: 3432
Joined: Sat Apr 14, 2007 11:34 pm

Post » Mon Nov 19, 2012 9:02 am

Wait, could I just use http://www.creationkit.com/OnUnload_-_ObjectReference and an http://www.creationkit.com/IsDead_-_Actor check in a script ON the bandits to disable them whenever the player leaves the area and they are unloaded?
User avatar
Sweets Sweets
 
Posts: 3339
Joined: Tue Jun 13, 2006 3:26 am

Post » Mon Nov 19, 2012 6:49 pm

Non-native just means the function body is written in Papyrus, instead of being part of the engine. It gets called in exactly the same way as native functions, though.

I'm not sure about http://www.creationkit.com/OnUnload_-_ObjectReference, as I've never used it before. If it doesn't work, though, http://www.creationkit.com/OnCellDetach_-_ObjectReference might do the trick.

Cipscis
User avatar
Queen of Spades
 
Posts: 3383
Joined: Fri Dec 08, 2006 12:06 pm

Post » Mon Nov 19, 2012 7:12 am

Alright I'll try that.

Now, in the script on the bandits, how do I reference the bandit the script is attached to? I though it would be self, but I guess I'm mistaken?

This is the script section;

;once all bandits are dead and unloaded disable themEvent OnCellDetach()   If (FSSQ01.GetStage() >= 10) && ((Self as Actor).IsDead() == 1)	  Self.Disable()   EndIfEndEvent

But I get this error when trying to compile;

(16,40): cannot cast a fssq01banditscript to a actor, types are incompatible

What am I missing here?
User avatar
Vickytoria Vasquez
 
Posts: 3456
Joined: Thu Aug 31, 2006 7:06 pm

Post » Mon Nov 19, 2012 3:03 pm

You're right about using the "Self" special variable, but it sounds like your script doesn't extend Actor, so it can't be cast to Actor. Perhaps you've extended ObjectReference instead or something? If you've extended ReferenceAlias, then you'll need to use the http://www.creationkit.com/GetReference_-_ReferenceAlias function before casting to Actor.

Cipscis
User avatar
Marcia Renton
 
Posts: 3563
Joined: Fri Jan 26, 2007 5:15 am

Post » Mon Nov 19, 2012 11:13 am

Ah, but of course! I just changed it to extend Actor instead, as I don't think that will mess up anything else in the script. (Just some variable/quest stuff when they're killed) It compiled now, so this should work! If it doesn't or I have any other issues I'll post again.

Thanks! :)
User avatar
Lynette Wilson
 
Posts: 3424
Joined: Fri Jul 14, 2006 4:20 pm

Post » Mon Nov 19, 2012 9:43 am

Probably a bit late, but could you not have used the body cleanup script that some unique actors have? It doesn't actually matter if the actors are unique for that script to work.
User avatar
Nicholas
 
Posts: 3454
Joined: Wed Jul 04, 2007 12:05 am

Post » Mon Nov 19, 2012 11:32 am

Oh, probably. It's okay, the bandits already had a script on them for the involved village quests, so I just added this little event segment, which seems to be working. :)
User avatar
Dawn Farrell
 
Posts: 3522
Joined: Thu Aug 23, 2007 9:02 am


Return to V - Skyrim