script help - spikes hurting the player

Post » Thu Dec 24, 2009 6:15 am

hey there,

I have this script that is designed to the the player/npc who touches them but only once. Then after 10 seconds it resets so that if the player/npc touches them again they get hurt again and so forth.

but the script doesnt seem to work and I cannot see the problem, can anyone help please?

included in the code is ghostnulls origonal notes.

Begin sm_GN_Falmer_Spike_Script

; ATTACH THIS TO THE SPIKES

; This works as is. It hurts the player or NPC/Creature that touches
; the spikes. But, it only hurts whomever touched the spikes first and
; only once. The HurtTimer is there to keep the player or NPC/Creature
; from constantly getting damaged. It resets in roughly the same amount
; of time for the pit block to fully reset. Once again, the problem is
; that the spikes won't hurt the player or NPC/Creature at the same time.
; Suppose NPCS/Creatures could be immune, then you could use the
; ModCurrentHealth function to damage the player, which could then be
; further scripted to be "level-based" damage. Another thought is to just
; have two sets of spikes, one with a size scale set .01 lower than the other
; them script them seperately for players and NPC for damage

short HurtOnce

float HurtTimer

If ( HurtOnce == 0 )
Set HurtOnce to 1
Endif

If ( HurtOnce == 1 )
If ( GetCollidingActor == 1 )
HurtStandingActor 100
Set HurtOnce to 2
Endif
Endif

If ( HurtOnce == 2 )
Set HurtTimer to ( HurtTimer + getsecondspassed )
If ( HurtTimer >= 10 )
Set HurtOnce to 0
Set HurtTimer to 0
Endif
Endif


End

User avatar
Your Mum
 
Posts: 3434
Joined: Sun Jun 25, 2006 6:23 pm

Post » Thu Dec 24, 2009 7:43 am

Try this. Note that this is untested.

Begin Spike_damagefloat timershort HurtOnceif ( HurtOnce == 1 )	set timer to ( timer + GetSecondsPassed )	if ( timer >= 10 )		set timer to 0		set HurtOnce to 0	endifendifif ( GetCollidingPC == 1 )	if ( HurtOnce == 0 )		Player->ModCurrentHealth -10		set HurtOnce to 1	endifelseif ( GetCollidingActor == 1 )	if ( HurtOnce == 0 )		HurtCollidingActor 10		set HurtOnce to 1	endifendifEnd

User avatar
Paula Rose
 
Posts: 3305
Joined: Fri Feb 16, 2007 8:12 am

Post » Thu Dec 24, 2009 3:56 pm

What is it with you and my scripts not working? They all worked when I was building the traps originally, making me look like an idiot :o :P

Even though I had HurtCollidingActor set to do 100 points of damage I think it really only did about 50. HurtCollidingActor doesn't seem to do all the damage at once but over time. For the player you could have "leveled" damage using something like this:

Begin Spike_damagefloat timershort HurtOnceif ( HurtOnce == 1 )	set timer to ( timer + GetSecondsPassed )	if ( timer >= 10 )		set timer to 0		set HurtOnce to 0	endifendifif ( GetCollidingPC == 1 )	if ( Player->GetLevel > 20 )		if ( Player->GetLevel <= 25 )			if ( HurtOnce == 0 )				Player->ModCurrentHealth -50				set HurtOnce to 1			endif		endif	elseif ( Player->GetLevel > 25 )		if ( Player->GetLevel <= 30 )			if ( HurtOnce == 0 )				Player->ModCurrentHealth -70				set HurtOnce to 1			endif		endif	elseif ( Player->GetLevel > 30 )		if ( Player->GetLevel <= 35 )			if ( HurtOnce == 0 )				Player->ModCurrentHealth -90				set HurtOnce to 1			endif		endif	elseif ( Player->GetLevel > 35 )		if ( Player->GetLevel <= 40 )			if ( HurtOnce == 0 )				Player->ModCurrentHealth -110				set HurtOnce to 1			endif		endif	endifelseif ( GetCollidingActor == 1 )	if ( HurtOnce == 0 )		HurtCollidingActor 100		set HurtOnce to 1	endifendifEnd


Based off Jac's with with "leveled damaged" added in, not tested either. You can change the values as needed.
User avatar
steve brewin
 
Posts: 3411
Joined: Thu Jun 21, 2007 7:17 am

Post » Thu Dec 24, 2009 1:42 pm

Even though I had HurtCollidingActor set to do 100 points of damage I think it really only did about 50. HurtCollidingActor doesn't seem to do all the damage at once but over time. For the player you could have "leveled" damage using something like this:


I think this has to do with the way the script engine works. The script is processed once every frame, but the value entered for HurtCollidingActor is a Damage/Sec rate. Therefore, the damage dealt can vary based on how many frames that block of code is active for. To get exactly how much damage as was entered into the function, the HurtCollidingActor command should run for one full second, like this:

if ( PerformHurt == 1 )     set HurtTimer to ( HurtTimer + GetSecondsPassed )     if ( HurtTimer < 1 )          HurtCollidingActor 10          Return     else          set HurtTimer to 0          set PerformHurt to 0     endifendif


Using a block in this manner means that regardless of frame rate, because the HurtCollidingActor line will execute every single frame for one second, the total damage dealt should add up to the enumerated value of ten. If you don't use a timer to regulate the command, then the damage amount will be unreliable.
User avatar
Sarah Evason
 
Posts: 3507
Joined: Mon Nov 13, 2006 10:47 pm

Post » Thu Dec 24, 2009 8:50 am

It's a finicky setup actually and Morrowind collision detection is to blame, Take a look at this http://img.photobucket.com/albums/v444/ghostnull/Morrowind/PitExample1.jpg in 3dsMax. The blue box is the collision box for the spikes. Collision had to be done this way otherwise a player wouldn't have been able to pass through the spikes or fall into them. If I didn't set the collision this way, the player would end up on top of the spikes when falling into the pit and that just would not have looked right. When setting up the pit trap, it's important that the pit block moves down enough to expose the very top of the spike's collision box, http://img.photobucket.com/albums/v444/ghostnull/Morrowind/PitExample2.jpg.

It can and will be hard to tell if the block is moving down enough. One thing you could do for testing is open up the .nif file for the spikes, find RootCollisionNode and make a copy of the NiTriShape with Copy Branch. Then just paste the NiTriShape into the same NiNode as the spikes and now you'll have a visual aid to determine if the block is moving far enough down to expose the collision box. After tweaking and making it work, just open the spike's .nif and remove the NiTriShape that you copied.

You'll still need two different sets of spikes because there will still be the problem of spikes only hurting one character at a time if both the player and a creature/NPC fall in the pit together. I stated this in the notes of the original script.
User avatar
Rebecca Clare Smith
 
Posts: 3508
Joined: Fri Aug 04, 2006 4:13 pm


Return to III - Morrowind