Difference between revisions of "Useful Scripts"

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
imported>Qazaaq
(→‎Autoclosing door: shouldn't -> should (or change the script, this is how it works))
imported>Cipscis
(Optimised most of the scripts and made them a little more consistent.)
Line 1: Line 1:
==Karma Effects on Items==
==Karma Effects on Items==
Script Type: Object
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>
<pre>
scn KarmaEffect
ScriptName KarmaEffect
 
ref rWearer


Begin OnEquip
Begin ScriptEffectStart
    player.RewardKarma -650
set rWearer to GetSelf
if rWearer.GetIsReference player
RewardKarma -650
endif
End
End


Begin OnUnequip
Begin ScriptEffectFinish
    player.RewardKarma 650
if rWearer.GetIsReference player
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
RewardKarma -650
End
 
Begin OnUnequip player
player.RewardKarma 650
End
End
</pre>
</pre>
Line 24: Line 46:


Begin GameMode
Begin GameMode
    if closeDoor == 1
if closeDoor == 1
        if doorTimer > 0
if doorTimer > 0
            set doorTimer to doorTimer - getSecondsPassed
set doorTimer to doorTimer - getSecondsPassed
        else
elseif GetOpenState == 1 ; if the door is still open
      ;close the door
SetOpenState 0 ; close the door
            Activate
set closeDoor to 0
      ; Lock
endif
            set closeDoor to 0
endif
        endif
    endif  
End
End


Begin OnActivate
Begin OnActivate
    Activate
if GetOpenState == 3 ; if the door is closed
    if IsActionRef Player == 0  ;if it should work for the player remove this...
if IsActionRef Player == 0  ; if it should work for the player remove this...
        set doorTimer to 5
set doorTimer to 5
        set closeDoor to 1
set closeDoor to 1
    endif                      ;...and this
endif                      ; ...and this
endif
Activate
End
End
</pre>
</pre>
Line 103: Line 125:
Script Type:Object
Script Type:Object


<small>To be placed on an [[activator]], and [[Reference#Linked_Ref|linked]] to a light source or a x-marker [[Reference#Enable_Parent|parent]].</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>
scn LightSwitchScript
ScriptName LightSwitchScript


ref light
ref light
short toggle


begin onactivate
Begin OnActivate
    if light == 0
if light == 0
        set light to getlinkedref
set light to GetLinkedRef
    endif
endif
   
 
    if toggle == 0
if light.GetDisabled
        light.disable
light.Enable
        activate
else
        set toggle to 1
light.Disable
    else
endif
        light.enable
Activate
        set toggle to 0
End
        activate
    endif
end
</pre>
</pre>

Revision as of 17:28, 20 February 2009

Karma Effects on Items

Script Type: Effect
For armour, you can use a scripted Object Effect. This allows the armour to safely be equipped and unequipped via EquipItem and UnequipItem

ScriptName KarmaEffect

ref rWearer

Begin ScriptEffectStart
	set rWearer to GetSelf
	if rWearer.GetIsReference player
		RewardKarma -650
	endif
End

Begin ScriptEffectFinish
	if rWearer.GetIsReference player
		player.RewardKarma 650
	endif
End

Script Type: Object
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

ScriptName KarmaEffect

Begin OnEquip player
	RewardKarma -650
End

Begin OnUnequip player
	player.RewardKarma 650
End

Autoclosing door

Script Type: Object

Scriptname AutoClosingDoor

float doorTimer
short closeDoor

Begin GameMode
	if closeDoor == 1
		if doorTimer > 0
			set doorTimer to doorTimer - getSecondsPassed
		elseif GetOpenState == 1 ; if the door is still open
			SetOpenState 0 ; close the door
			set closeDoor to 0
		endif
	endif
End

Begin OnActivate
	if GetOpenState == 3 ; if the door is closed
		if IsActionRef Player == 0  ; if it should work for the player remove this...
			set doorTimer to 5
			set closeDoor to 1
		endif                       ; ...and this
	endif
	Activate
End

Pusheffect

Script Type: Effect

spell effect script for a weapon that knocks people far away and creates a trail of smoke or fire along the way.
NOTE - Only works correctly when the player has the weapon equipped.

scn CALFPeffectSCR

short ActorValue1
short ActorValue2
short ActorValue3
short DamageValue

Begin ScriptEffectStart
    
    ; places initial explosion when hit, just in case there's no specified explosion effect in the weapons projectile
    ; also useful if you'd want a melee weapon or fist to cause explosions on hit
    placeatme {ExplosionType}
    
    Player.PushActorAway Target 104
    
    ; this is the part of the script in which you can specify a certain damage formula
    ; the formula can be added to the base damage amount set in the weapons tab
    ; -or you can set the damage in the tab to zero and fully rely on the formula to calculate damage
    ; it can be the target NPC/creature's actor value or the player's
    ; it's also fine not to make a certain damage formula
    set ActorValue1 to Player.GetAv {ActorValue1}
    set ActorValue2 to Player.GetAv {ActorValue2}
    set ActorValue3 to Player.GetAv {ActorValue3}
    
    set Damage to -1 * ( {formula incorporating actor values} )
    ModAv Health DamageValue
    
    ; make the effect play a certain sound-you could also use the sound of the explosion and not specify a specific sound
    Playsound3D Play a certain sound
End


Begin ScriptEffectUpdate
    ; this is the part where you place a smoke effect on every axis the NPC/Creature is located
    ; it makes as if the smoke is always coming out of the target while the effect is taking place
    placeatme {smokeeffect}
    
    ; alternatively add a smoke actor effect on the character
    CastImmediateOnSelf {smoke actor effect}
End


begin ScriptEffectFinish
    ;if you used the above alternative, this segment removes the smoke effect from the character
    RemoveSpell {smoke actor effect}
end

Light switch

Script Type:Object

To be placed on an activator, and linked to a light source or x-marker Enable Parent.

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