Spoiler
Scriptname WIDeadBodyCleanupScript extends Actor;**** This should ONLY BE USED ON UNIQUE ACTORS!!! ****;This script cleans up dead actors, enables a container (ie grave/crypt) and moves all their inventory, after it Loads/unloads after a certain period of time.;If you need to temporarily stop someone from being cleaned up, put them in the WINoBodyCleanupFaction faction.;please do not modify this script without talking to jduvallWIFunctionsScript Property WI Auto ;(10){Pointer to WIFunctionsScript attached to WI quest. You MUST set this or things will be broken.}float Property DaysBeforeCleanUp = 0.5 Auto{Default = 0.5: What's the minimum amount of time (in days) that the body should stick around before being cleaned up. (Clean up happens during while loop.)}ObjectReference Property DeathContainer Auto{Container to move all the items the actor has in his inventory when cleaned up.}actor SelfRef ;used to keep me persistent so I get UnLoad events while I exist; (20)state Dead ;do nothing Event OnDeath(Actor akKiller) EndEventEndStateEvent OnDeath(Actor akKiller); (30) GoToState("Dead") if DeathContainer bool cleanedUp = false while cleanedUp == false; debug.trace("WIDeadBodyCleanupScript" + self + "OnDeath() In While Loop, will try cleaning up after waiting " + DaysBeforeCleanUp) utility.waitGameTime(DaysBeforeCleanUp * 24) ; (40) cleanedUp = checkForCleanup() endWhile else; debug.trace("WIDeadBodyCleanupScript" + self + " WARNING: NO DeathContainer!", 2) endif; (50)EndEventbool function checkForCleanup() if IsInFaction(WI.WINoBodyCleanupFaction); debug.trace("WIDeadBodyCleanupScript" + self + "In Faction WINoBodyCleanupFaction so NOT cleaning up body.", 1) ;do nothing return true ;bail out of while loop; (60) Elseif Is3DLoaded() == False; debug.trace("WIDeadBodyCleanupScript" + self + "Cleaning up body.") cleanUpBody() return true Else; debug.trace("WIDeadBodyCleanupScript" + self + "Not cleaning up body, because my 3D is loaded.") EndIf return false; (70)endfunctionfunction cleanUpBody(); debug.trace("WIDeadBodyCleanupScript" + self + "cleanUpBody() moving to WIDeadBodyCleanupCellMarker in WIDeadBodyCleanupCell and Calling RemoveAllItems() to DeathContainer, and enabling it:" + DeathContainer) ;Disable() ;*** It has been decided it's safer to move them to a holding cell, for quests that might be filling allowing for dead actors but not allowing checking for disabled actors MoveTo(WI.WIDeadBodyCleanupCellMarker); (80) DeathContainer.SetActorOwner(GetActorBase()) DeathContainer.Enable() RemoveAllItems(DeathContainer)EndFunctionI added the ; (10) through ; (80) to make it easier to find the lines I am talking about, they were not a part of the original script.
Line 1 starts with - Scriptname WIDeadBodyCleanupScript extends Actor - From my understanding of the wiki, this is how one must start each script were WIDeadBodyCleanupScript is the name of the script and Actor is the type of script it is used on.
Line 3 starts with a semicolon. I am guessing (though have no confirmation) that lines starting with semicolons are comment lines.
In all honesty I have no idea what Line 10 is. My guess is that it is declaring a variable called "WI" of type WIFunctionsScript and the it is a special type of variable used in papyrus called a property and the property is an "auto". This doesn't make much sense to me because I am used to working with variables like int, float, long, bool and so forth, not WIFunctionsScript. Also I don't competely understand properties.
I have to assume that Line 11 is also a comment, and that you can comment stuff out by putting them in braces.
Line 13 is easier to understand than Line 10 but similar. It is declaring a float variable called DaysBeforeCleanUp and initializing it to .5. It is also a property of type auto.
Line 16 is also easier to understand. It declares another variable called DeathContainer of type ObjectReference. I assume that we are going to set it to the Form ID of the container we want to use? It is also a property of type auto.
Line 19 also confuses me. It looks like you are declaring an actor called "SelfRef" or maybe its calling a function called "SelfRef" but it doesn't use the actor and I wasn't able to find the function on the wiki (I assume it would be in either this script or the script it extends, the actor script).
Line 21-26 looks like it does nothing. It creates a state called "Dead" (but doesn't set the actor to the state?), and then does nothing when the actor is killed. Why do we need this?
Line 29-51 is a special type of function called an event. It receives data for an actor an sets it to the actor variable akKiller (which this function doesn't use). The event starts on the death of the actor the script is attached to. It puts the actor into the new state called "Dead". It then starts an if statement that is unlike what I usually see. I assume it reads a non zero value as true, but we haven't set "DeathContainer" to anything yet (so I was under the impression it can be anything since it hasn't be initialized). Assuming that "DeathContainer" is true, it creates a bool variable called "cleanedUp" and sets it to false. Then starts a while statement that while "cleanedUp" is equal to false, it launches a function from the utility script called waitGameTime (found on the wiki, pauses script for the arguments time in hours). The argument is 24 times a float variable we set to .5 earlier in the script. Line 42 sets cleanedUp to the return of the function checkForCleanup() in order to get out of the loop. Assuming that "DeathContainer" is false, nothing happens.
Line 38, 47, 57, 62, 66 and 74 also confuse me. If a semi colon marks a comment line, why is the comment written codelike?
Line 54-71 defines a function called checkForCleanup() that wants a bool in return. (do functions not need prototypes?). First it checks if the actor attached to this script is in the faction "WINoBodyCleanupFaction" (why do they use WI.WINoBodyCleanupFaction and not just WINoBodyCleanupFaction as the argument). If true it returns true. Else it checks that the actor is not loaded. If true it calls the function cleanUpBody() and returns true. Else it returns false.
Line 73-85 looks like it moves the actor to a marker defined by "WIDeadBodyCleanupCellMarker", that is probably in another script called WI? Then it uses DeathContainer (its still undefined right?) and sets its owner to the actor attached to this script (SetActorOwner and GetActorBase are on the wiki). It then Enables the DeathContainer, and removes all items from DeathContainer (we never added anything to it though right? How is this removing the items from the actor?)
That is my basic understanding of this script. If anyone could help clear up some of my confusion and tell me what I am getting right and help me out, I would be grateful. Thanks for your time!
