Trigger on Death?

Post » Fri May 27, 2011 7:17 am

I need a script that will trigger a trap on the death of an npc. The Original trap Script is as follows:

scn ARTrapGasEmitter01SCRIPT

; spurt gas on activation

short init
float timer
short next
ref mySelf
ref myParent

float fTrapDamage
float fLevelledDamage
float fTrapPushBack
float fTrapMinVelocity
short bTrapContinuous

begin onActivate

if init == 0
set mySelf to getSelf
set myParent to getParentRef
set init to 1
endif

if isActionRef player == 0 && isActionRef mySelf == 0

set init to 2

; set up the damage values
set fTrapDamage to 10
set fTrapPushBack to 0
set fLevelledDamage to 0.125
set fTrapMinVelocity to 20
set bTrapContinuous to 1

set timer to 8
set next to 1
playgroup forward 1

endif

end

begin gameMode

;daisy-chain
if next == 1 && timer <= 7
set next to 0
myParent.activate mySelf 1
endif

if timer <= 0 && init == 2

playgroup forward 1
set timer to 10

endif

if timer > 0
set timer to timer - getSecondsPassed
endif

end

--Thanks
-MNPred
User avatar
Lou
 
Posts: 3518
Joined: Wed Aug 23, 2006 6:56 pm

Post » Thu May 26, 2011 11:39 pm

Give the trap a unique RefId (like DeathTrapRef or something) and make it a persistent reference. The attach a script to your NPC that will activate the trap. It should look something like:

scn DeathTrapActivateScriptBegin OnDeathActivate DeathTrapRefEnd

User avatar
Eileen Müller
 
Posts: 3366
Joined: Fri Apr 13, 2007 9:06 am

Post » Fri May 27, 2011 4:57 am

Please use CODE tags around code to preserve white-space; it makes it massively easier to read and debug.
scn ARTrapGasEmitter01SCRIPT; spurt gas on activationshort initfloat timershort nextref mySelfref myParentfloat fTrapDamagefloat fLevelledDamagefloat fTrapPushBackfloat fTrapMinVelocityshort bTrapContinuousbegin onActivate	if init == 0		set mySelf to getSelf		set myParent to getParentRef		set init to 1	endif	if isActionRef player == 0 && isActionRef mySelf == 0				set init to 2		; set up the damage values		set fTrapDamage to 10		set fTrapPushBack to 0		set fLevelledDamage to 0.125		set fTrapMinVelocity to 20		set bTrapContinuous to 1				set timer to 8		set next to 1		playgroup forward 1			endifendbegin gameMode	;daisy-chain	if next == 1 && timer <= 7		set next to 0		myParent.activate mySelf 1	endif	if timer <= 0 && init == 2				playgroup forward 1		set timer to 10	endif	if timer > 0		set timer to timer - getSecondsPassed	endifend


Anyway, you're never getting to set init to 2, because you're checking IsActionRef player == 0 - meaning this won't work when the player activates it. Plus you have IsActionRef MySelf == 0 for no reason; this can't activate itself. This will activate its parent (which is a little odd, but I think I see where you're going with that). Change that line to IsActionRef player || IsActionRef (my-child), and it should work, I think. Or just don't bother checking who the action ref is, since it's very unlikely to be anyone but the player or the reference's child.
User avatar
cutiecute
 
Posts: 3432
Joined: Wed Sep 27, 2006 9:51 am


Return to IV - Oblivion