Editing Useful Scripts

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
[[category:Scripting]]
= GECK =
= GECK =
==Gender Unlock==
Script Type:Object
<small>To be placed on an [[door]], or [[container]], Uses your gender (Male, Female) to [[unlock]] a the door, container.</small>
<pre>
ScriptName VaultGenderUnlock
Begin Gamemode
If Player.GetIsSex gender ;Place male,female where it says Gender. Can't be both.
  Unlock
endif
End
</pre>


==Timed Doors==
==Timed Doors==
Line 323: Line 304:
</pre>
</pre>


==Simulating Global Functions in your Mod==
==Water Purifier==
Global functions, or behavior that acts as though it's a global function can be simulated through the use of a shared script (i.e. a Quest script) and setting properties on it as though it were a state machine.
Script Type: Object


It must be understood that scripts execute all the way through, each tick, and
<small>A very simple script, with an example of using an activator to manipulate items in the player's inventory. You can pick up some basics from this script. Based loosely on the House Nuka-Cola machine script in game, this is for use on an activator that purifies bottles of dirty water in the player's inventory.</small>
many times the result from a function call won't be readable until the next tick has occurred. Some parts in this example use NVSE (FOSE works as well for Fallout3).


The first script is called ExampleScript and is a Quest type script for the Quest called Example. Note that referencing variables in a script from outside of the script must be done by referencing the Quest name, not the Script name. (i.e. Example.Initialized instead of ExampleScript.Initialized).
<pre>
scn AAAwpscript


If you have any questions, email me at nyteshade.geck@gmail.com.
;This script is designed to handle a Water Purifier
<pre> 
;This script is attached to the Water Purifier I have added in the player's megaton house
    ScriptName ExampleScript
;Basically all it does is check to see how many dirty waters the player is carrying, it removes them all and adds purified waters instead


    Short Initialized
short DirtyOnMe      ;declare a variable to store the number of dirty waters the player has


    Short Msg_FnSum
begin OnActivate      ;starts the script when the purifier is activated
    Short Msg_FnSum_Done
    Short Msg_FnProduct
    Short Msg_FnProduct_Done


    Short Param1 ; best to name these something better
if ( IsActionRef Player == 1 )
    Short Param2 ; if you are not going to share them
;checks to make sure you are the player
    Short ReturnValue
if ( Player.GetItemCount WaterUnpurified >= 1 )
;checks to make sure you actually have some dirty water on you
ShowMessage AAAWPdirtywith     
;displays a message that tells the player what the machine does
set DirtyOnMe to ( Player.GetItemCount WaterUnpurified )
;sets DirtyOnMe to however many Dirty Waters the player has
Player.RemoveItem WaterUnpurified DirtyOnMe     
;removes all of the player's dirty water from the invent.
player.AddItem WaterPurified DirtyOnMe     
;adds the purified water - same number as dirt waters removed
elseif ( Player.GetItemCount WaterUnpurified < 1 )     
;if the player has no dirty water in their invent
ShowMessage AAAWPdirtywithout     
;display a message telling the player they need more dirty water
endif
endif


    Begin GameMode
end
      If Initialized == 0 || GetGameLoaded || GetGameRestarted ; last two are from NVSE
        Set Initialized to 1
        Set Param1 to 0
        Set Param2 to 0
        Set ReturnValue to 0
        Set Msg_FnSum to 0
        Set Msg_FnSum_Done to 0
        Set Msg_FnProduct to 0
        Set Msg_FnProduct_Done to 0
      EndIf


      If Msg_FnSum != 0
        Set ReturnValue to Param1 + Param2
        Set Msg_FnSum to 0
        Set Msg_FnSum_Done to 1
      ElseIf Msg_FnProduct != 0
        Set ReturnValue to Param1 * Param2
        Set Msg_FnProduct to 0
        Set Msg_FnProduct_Done to 1
      EndIf
    End
</pre>
</pre>


The calling script can be anything really. You will notice in this script, the calling of the Msg_FnSum and Msg_FnProduct occur in separate time ticks than the Msg_FnSum_Done and Msg_FnProduct_Done code. The entire script is ready every tick but the conditions triggered by the code in the ExampleScript will not have taken place in the first pass.
<pre>
    ScriptName Other
    Short SumValue
    Short ProductValue
    Begin GameMode
      If SomeCondition == 1
        ; Let's call function Sum
        Set Example.Param1 to 2        ; Set parameter 1
        Set Example.Param2 to 5        ; Set parameter 2
        Set Example.Msg_FnSum to 1      ; Call Msg_FnSum on next tick
      ElseIf SomeCondition == 2
        ; Let's call function Product
        Set Example.Param1 to 2        ; Set parameter 1
        Set Example.Param2 to 5        ; Set parameter 2
        Set Example.Msg_FnProduct to 1  ; Call Msg_FnProduct on next tick
      EndIf
      ; Occurs in a later 'tick' than the calling code
      If Example.Msg_FnSum_Done == 1
        ; Do something with the value
        ; The value of Example.ReturnValue is now 7
        Set Example.ReturnValue to 0    ; Clean up return value (be nice)
        Set Example.Msg_FnSum_Done to 0 ; Prevent this code block from executing next tick
      ElseIf Example.Msg_FnProduct_Done == 1
        ; Do something with the value
        ; The value of Example.ReturnValue is now 10
        Set Example.ReturnValue to 0        ; Clean up return value (be nice)
        Set Example.Msg_FnProduct_Done to 0 ; Prevent this code block from executing next tick
      EndIf
    End
</pre>


= + [[Fallout Script Extender|FOSE]] =
= + [[Fallout Script Extender|FOSE]] =
Line 477: Line 413:
endif
endif
endif
endif
End
</pre>
Note: Your attached <b>Quest</b> should have a small <b>script Processing delay</b>, otherwise the key event may not work.
== Iterating through multiple lists ==
Script Type: Object
;Script requires the [[Fallout Script Extender]].
This is a good technique for making simulated 2 dimension arrays in tes script
There are a few technically unnecessary variables but this loop is setup to be used as part of a series.
To use in series, just copy everything from ";Main Loop" to the last "EndIf". The only thing you need to change is the value of "MainList".
If you use this on any list that may be empty it is a good idea to surround any use of CurrentRef with an if block checking if the ref == 0
Sorry for any errors, I'm writing this from memory
<pre>
scn Test2Dim
; Counter vars
long Count1
long Count2
; Max Count vars
long MaxCount1
long MaxCount2
; Label vars
short Label1
short Label2
; Lists
ref MainList
ref CurrentList
ref CurrentRef
Begin onActivate
; setup counters
Set Label1 To 0
Set Label2 To 1
;Main Loop
Set MainList To TopLevelListHere
Set Label1 To Label1 + 2 ; 2 Because its the number af labels
Set Label2 To Label2 + 2
Set Count1 To 0
Set MaxCount1 To ListGetCount MainList
Label Label1
Set Count2 To 0
Set CurrentList To ListGetNthForm MainList Count1
Set MaxCount2 To ListGetCount CurrentList
Label Label2
Set CurrentRef To ListGetNthForm CurrentList Count2
; Use CurrentRef here
If Count2 < MaxCount2
Set Count2 To Count2 + 1
GoTo Label2
EndIf
If Count1 < MaxCount1
Set Count1 To Count1 + 1
GoTo Label1
EndIf
End
</pre>
== Iterate Through Disabled Objects==
Script Type: Object
;Script requires the [[Fallout Script Extender]].
<small>To be placed on an [[Activator]], and linked to a reference.
Usage involves linking the activator to a disabled reference. The disabled reference is linked in a loop with several other disabled references. Each activation will disable the previous reference and enable the next reference.</small>
<pre>
ScriptName LoopThroughReferences
ref currentRef
ref previousRef
ref nextRef
Begin OnActivate player
set previousRef to getSelf
Label 1
set currentRef to previousRef.getLinkedRef
set nextRef to currentRef.getLinkedRef
if currentRef.getDisabled == 0
currentRef.disable
nextRef.enable
else
set previousRef to currentRef
goto 1
endif
End
End
</pre>
</pre>

Please note that all contributions to the Fallout3 GECK Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see GECK:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)