Difference between revisions of "Useful Scripts"

1,620 bytes added ,  20:38, 6 March 2009
Changed order of scripts, added →‎Forced Relative Orientation: (not sure about name)
imported>Cipscis
m (Fixed a syntax mistake)
imported>Cipscis
(Changed order of scripts, added →‎Forced Relative Orientation: (not sure about name))
Line 1: Line 1:
==Karma Effects on Items==
==Light switch==
Script Type: Effect<br />
Script Type:Object
<small>For armour, you can use a scripted Object Effect.  This allows the armour to safely be equipped and unequipped via [[EquipItem]] and [[UnequipItem]]</small>
 
<small>To be placed on an [[activator]], and [[Reference#Linked_Ref|linked]] to a light source or x-marker [[Reference#Enable_Parent|Enable Parent]].</small>


<pre>
<pre>
ScriptName KarmaEffect
ScriptName LightSwitchScript


ref rWearer
ref light


Begin ScriptEffectStart
Begin OnActivate
set rWearer to GetSelf
if light == 0
if rWearer.GetIsReference player
set light to GetLinkedRef
RewardKarma -650
endif
endif
End


Begin ScriptEffectFinish
if light.GetDisabled
if rWearer.GetIsReference player
light.Enable
RewardKarma 650
else
light.Disable
endif
endif
Activate
End
End
</pre>
</pre>


Script Type: Object<br />
==Forced Relative Orientation==
<small>For weapons, you'll have to use an Object Script"Weapon" type Object Effects are applied to that weapon's target, and are therefore unsuitable for applying effects to the wielder</small>
Script Type: Quest, Object or Effect
<small>For a Quest or Object script, use a [[GameMode]] blockFor an Effect script, use a [[ScriptEffectUpdate]] block.<br />In order to use the EditorRefID of your reference in a script like this, it must be a persistent reference.</small>
 
<pre>float fAngleZ
float fRelativePos
 
Begin GameMode
 
set fRelativePos to player.GetPos z + <Z OFFSET>
myREF.setPos z fRelativePos
 
set fAngleZ to player.GetAngle Z + <ANGLE OFFSET>
myREF.SetAngle Z fAngleZ


<pre>ScriptName KarmaEffect
set fRelativePos to player.GetPos Y + <PLAYER OFFSET> * cos fAngleZ
myREF.SetPos Y fRelativePos


Begin OnEquip player
set fRelativePos to player.GetPos X + <PLAYER OFFSET> * sin fAngleZ
player.RewardKarma -650
myREF.SetPos X fRelativePos
End


Begin OnUnequip player
player.RewardKarma 650
End
End
</pre>
</pre>
<ul>
<li><Z OFFSET> determines the reference's z offset from the player's feet.  The higher this is, the further above the player's feet the reference will appear.
</li>
<li><ANGLE OFFSET> determines the reference's position relative to the players.  As <ANGLE OFFSET> increases, the reference's position will move around the player in an anti-clockwise direction.  When <ANGLE OFFSET> is 0, the reference will appear directly in front of the player.</li>
<li><PLAYER OFFSET> determine's the horizontal distance between the reference and the player.  As <PLAYER OFFSET> increases, the reference appears further and further from the player</li>
</ul>
The player can be substituted for any other reference here and the script will still work.  Note that the reference may appear to move through solid objects, especially when <PLAYER OFFSET> is set to a particularly large value.


==Autoclosing door==
==Autoclosing door==
Line 64: Line 84:
endif
endif
Activate
Activate
End
</pre>
==Karma Effects on Items==
Script Type: Effect<br />
<small>For armour, you can use a scripted Object Effect.  This allows the armour to safely be equipped and unequipped via [[EquipItem]] and [[UnequipItem]]</small>
<pre>
ScriptName KarmaEffect
ref rWearer
Begin ScriptEffectStart
set rWearer to GetSelf
if rWearer.GetIsReference player
RewardKarma -650
endif
End
Begin ScriptEffectFinish
if rWearer.GetIsReference player
RewardKarma 650
endif
End
</pre>
Script Type: Object<br />
<small>For weapons, you'll have to use an Object Script.  "Weapon" type Object Effects are applied to that weapon's target, and are therefore unsuitable for applying effects to the wielder</small>
<pre>ScriptName KarmaEffect
Begin OnEquip player
player.RewardKarma -650
End
Begin OnUnequip player
player.RewardKarma 650
End
End
</pre>
</pre>
Line 120: Line 177:
end
end


</pre>
==Light switch==
Script Type:Object
<small>To be placed on an [[activator]], and [[Reference#Linked_Ref|linked]] to a light source or x-marker [[Reference#Enable_Parent|Enable Parent]].</small>
<pre>
ScriptName LightSwitchScript
ref light
Begin OnActivate
if light == 0
set light to GetLinkedRef
endif
if light.GetDisabled
light.Enable
else
light.Disable
endif
Activate
End
</pre>
</pre>
Anonymous user