A gag I thought I would share
Posted: Fri Apr 01, 2005 3:22 pm
I wrote these routines to deal with a notorious sniper spot on top of a very high crane we had in one of our custom made maps. It gives away the fact that a sniper is hiding up there but also allows him the chance to get back down in a safe manner to escape... well sometimes LOL 
Anyway I thought it might be an idea to share em around, maybe they can be good for more ideas, also for newer scripters to learn how to combine different triggers to achieve desired outcomes.
Note because I am adjusting gravity it might be a good idea not to do this too close the edge of maps, otherwise players can fly out of the map if the player clip is not high enough. Enjoy!
EDIT === I thought I should add more comments to explain in more detail what is going on, I remember when I first started scripting that reading scripts without comments was like trying to read Hyroglyphics (sp)
Grassy
Anyway I thought it might be an idea to share em around, maybe they can be good for more ideas, also for newer scripters to learn how to combine different triggers to achieve desired outcomes.
Note because I am adjusting gravity it might be a good idea not to do this too close the edge of maps, otherwise players can fly out of the map if the player clip is not high enough. Enjoy!
EDIT === I thought I should add more comments to explain in more detail what is going on, I remember when I first started scripting that reading scripts without comments was like trying to read Hyroglyphics (sp)
Code: Select all
//call the thread (put this under level waittill spawn)
thread crane_gag
//------------------------
crane_gag:
//------------------------
//spawn a corona placed at the top of the crane
local.corona = spawn script_model
local.corona model "fx/corona_red_bright.tik"
local.corona.origin = ( -1310 -2564 1800 )
local.corona notsolid
//make it bigger, due to height the default size was too small
local.corona scale 3
local.corona targetname "cranelight"
$cranelight show
waitframe
//spawn a trigger multiple on top of the crane
//give it a setthread so it will call the thread Trigger1 below
local.trig = spawn trigger_multiple setthread Trigger1
local.trig.origin = ( -1310 -2564 1916 )
local.trig setsize ( -20 -20 -20 ) ( 20 20 20 )
//set a message for the player to see
local.trig message "Press USE if you want to jump off safely"
local.trig wait 2 // How often the trigger repeats itself.
local.trig delay 0 // How long before trigger acts.
end
//------------------------
Trigger1:
//------------------------
//this is the thread that the trigger_multiple calls if a player touches it
local.player=parm.other
//add a new variable to the local.player, this acts like a switch to stop
//the trigger running the thread more than once.
//On the first run of this thread the variable isTrigger1 will = 0 so it
// wont end then the variable is set to 1 so the trigger wont activate
//the whole thread again. Then at the end of the thread the variable is
//reset back to 0 again
if (local.player.isTrigger1==1)
end
local.player.isTrigger1=1
//now we spawn a trigger_use that the player can activate if he wishes
local.trig2 = spawn trigger_use
local.trig2.origin = local.player.origin
local.trig2 setsize ( -40 -40 -40 ) ( 40 40 80 )
local.trig2 targetname "chute_trig"
//start a new thread to monitor the new trigger_use
//note how the thread is called, here we are passing two parameters
//to the thread, the trigger (becomes self in new thread) and local.player
//so we can grab the coordinates of the player in the new thread
$chute_trig thread setup_chute local.player
//here is a checkpoint, while the player is still in the trigger_multiple
//the corona will flash on and off to give him away :-)
while ((local.player isTouching self) && (isAlive local.player))
{
$cranelight show
wait 2
$cranelight hide
wait 2
}
//The local.player has either died or has left the trigger now,
//lets hope he pressed the use key before he did :-)
//so we make the light stop flashing and reset the variable isTrigger1
wait 5
$cranelight show
local.player.isTrigger1=0
end
//------------------------
setup_chute local.player:
//------------------------
//wait for player to press USE key
self waittill trigger
//now disable the trigger so it only works once
self nottriggerable
waitframe
//spawn a script_model that is used to glue to the player, we also
//bind the chute to this object a bit later on.
//I found it much smoother to do it this way rather than glue or bind
//the chute directly to the player
local.mover1 = spawn script_model model "fx/dummy.tik"
local.mover1.origin = local.player.origin
local.mover1 notsolid
local.mover1 rendereffects "+dontdraw" //saves a small amount of engine work
local.mover1 glue local.player
//now reduce the gravity of the player so he floats slowly down
//and wont get hurt when he hits the ground
local.player gravity 0.3
local.player iprint "Ok you can jump now, you have 10 seconds to get your feet on the ground"
//another checkpoint, while the player is still on the crane we wait here
while(local.player isTouching self)
waitframe
//Now the player has left the trigger (ie, jumped off the crane)
//so we spawn a parachute with an offset so the shoulder straps
//line up with the players shoulders
local.chute = spawn script_model model "static/army_parachute.tik"
local.chute.origin = local.player.origin + ( 0 0 76 )
local.chute.angles = local.player.angles
local.chute targetname "para1"
local.chute notsolid
//bind the chute to the script_model, using bind will not alter the position
//of either the chute or the script_model (origins are maintained)
//but using glue to stick two objects together will move them to the
//center of each object unless you specify a bone like a players head
local.chute bind local.mover1
local.timeout=10
//give the player a stopwatch to keep track of time for the decent
local.player stopwatch local.timeout
local.timer=0
//while the player is alive increment the variable "timer" by 1 until
//it is equal to the value of variable "timeout" (10)
while(isAlive local.player)
{
local.timer++
wait 1
//both variables are equal so reset the players gravity back to normal
//and delete the trigger_use, the script_model and the parachute
//The player is still alive and made a safe landing (hopefully) or he
//ran out of time and dropped like a lead balloon :-)
if(local.timer==local.timeout)
{
local.player gravity 1
self delete
local.mover1 delete
$para1 delete
}
}
end