Effects on a trigger_hurt

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Effects on a trigger_hurt

Post by Grassy »

G'day all,
I am trying to create a small fx when a player touches a trigger_hurt that is on a long wire, it's supposed to be an electric fence.
The trigger_hurt works ok, but what I wanted was to spawn some sparks where the player touches the wire and play a sound.
Can the trigger_hurt also be a script_obj and call a setthread?

This is what I have tried so far with not much success :(

Code: Select all

//------------------------
wire_fx:
//------------------------
 
while (1)
{

  for ( local.i=1 ; local.i <= $player.size ; local.i++ )
  {
    if ( $player[local.i].dmteam != "spectator" )
    {
      if ( vector_length ( $player[local.i].origin - $elec_wire.origin ) < 40 )
      {
        local.org = ( vector_length ( $player[local.i].origin -$elec_wire.origin ) * .5 )
        local.fx = spawn script_model model "emitters/electric_arc.tik" "origin" local.org
        $player[local.i] playsound spark
        wait 1
        local.fx remove
      }
    }
  }
  
 waitframe
}

end
[/size]
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

Well this won't work

local.org = ( vector_length ( $player[local.i].origin -$elec_wire.origin ) * .5 )
local.fx = spawn script_model model "emitters/electric_arc.tik" "origin" local.org

local.org is the length between $player[local.i].origin and $elec_wire.origin so it is not a valid set of coords it would be more like this

local.org = $elec_wire.origin + (( $player[local.i].origin -$elec_wire.origin ) * .5 )

or

local.org = $elec_wire.origin + (( -$elec_wire.origin - $player[local.i].origin ) * .5 )

one of the two

How long is the wire ? The problem will be where to do the fx because you can only use the origins of the wire or trigger or player to find the coords of the sparks . You can't really just find the spot on the wire that the player touched unless you had a row of triggers or something .
Image
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post by Grassy »

How long is the wire ? The problem will be where to do the fx because you can only use the origins of the wire or trigger or player to find the coords of the sparks . You can't really just find the spot on the wire that the player touched unless you had a row of triggers or something .
Yeah thanks BD, that's what I was begining to suspect.. :( and the wire is pretty long and does a few turns as well..

Would .colisionent be any use ??
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

i dont see why you cant offset the origin of the palyer as opposed to the wire... why worry about org when you can make a bending trig around the thing and do a setthread to something sorta like the code, of course you can pull one of my stunts and predict where and how the script fires and do summat as such....

Code: Select all

[code]//------------------------ 
wire_fx: 
//------------------------ 
  
local.hitOrig = $player.origin += /* x y z values of the fence trigger on which side he hit, might want a couple trigs instead of bends*/

    if ( $player[local.i].dmteam != "spectator" ) 
        local.fx = spawn script_model model "emitters/electric_arc.tik" "origin" "local.hitOrig"
        $player[local.i] playsound spark 
        wait 1 
        local.fx remove 
      } 
} 
of course i do things quite differently than more experienced dudes, but they work fine for me.

one of the main things i took out was your while(1) loop, scripts for MP are bad enough, but making an infinite loop with only a frame of wait being distributed to up to 64 clients? uhmm... no. that'd cause some serious server lag.

so on that bit i got rid of the isTouching too...


ok so to clarify a bit, make a few trigs with the same $targetname and setthread around your wire, set in some .wait values in place of the waitframe. put in the second script, and oWn.
Moderator

۞
Abyssus pro sapientia
Olympus pro Ignarus
۞

AND STUFF™ © 2006
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post by Grassy »

lizardkid, yeah your thinking the same lines as I am now... :)
So what we have are the wire brushes, and over them we have a trigger_hurt, if we could make the hurt trigger call a setthread then it would be just a simple matter of showing the fx in the players field of view to get the desired effect. And as you say be kinder on the server, rather than it monitoring up 16 players positions relative to the wire.
So I suppose my next question is, can a trigger_hurt call a thread as well, this is Spearhead by the way, a trigger_hurt is all handled in the bsp, no scripting required for player damage.
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

I think any trigger that can be triggered can use setthread . You will have to do some kind of math to find out where to do the fx but it can be done what I said or ment was you will have to use the origins of the trigger and player to calculate where to do the fx . For example use the trigger's origin and minus the players x or y coord or maybe use the players x or y coord something like that . Then raise it up so the sparks are at wire level .
Image
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post by Grassy »

Well here we are again :) I spawned in a trigger_multiple for testing and this very simple routine works like a charm...
And because the player has to be close to the wire the sparks look near enough to be on the player and wire, it's not perfect but with the games limitations it's close enough :)

Code: Select all

//------------------------
wirefx_trig:
//------------------------
 local.trig = spawn trigger_multiple setthread wirefx1
 local.trig.origin = ( -943.86 1370.56 0.13 )
 local.trig setsize ( -100 -100 -20 ) ( 100 100 20 )
 local.trig message "Carefull - Electric wires are active!"
 local.trig wait 2    // wait between trigger repeats.
 local.trig delay 0  // delay before trigger acts.
end

//------------------------
wirefx1:  // called from bsp with setthread from the trigger_hurt triggers on the wires
//-----------------------
 self waittill trigger
 local.player=parm.other
 if(local.player.iswirefx1 == 1)
   end

 if((local.player.dmteam != "spectator") && (local.player.iswirefx1 != 1))
    {
        local.player.iswirefx1 = 1
        local.player iprint "WARNING High voltage!"
        local.org = ( local.player.origin + ( 0 0 120 ))
        local.fx = spawn script_model model "emitters/electric_arc.tik" "origin" local.org
        local.fx scale 1
        local.player playsound spark
        wait 2
        local.fx remove
        local.player.iswirefx1 = 0
    }
end
Post Reply