Updated August 13, 2006
HOME PAGE > AUTHORS > PROSPERO > BOD PYTHON SCRIPTING (17)
Tut 17. Traps
Bit of a cop out here.
There are lots of traps in the game and most are quite complicated.
To explain them all is not really practical. Best course of action is to find one in the game that you would like and copy/adapt the code to suit your own map.
It
may take time and a lot of head-scratching but by the time you have finished you
will be an expert trap maker.![]()
---------------------------------------------------------------------
Tutorial on traps. (Submitted by Raptor.
)
By the
way it looks, you might say that making a trap is very difficult (strange code
and stuff). Nevertheless, it really is relatively easy. As a start, you should
decide what type of trap you would like to use and where to place it. For
example, you might want one of those balls style "Indiana Johnes" that would
squeeze the player as this one gets to the sector that would activate the ball.
You also might want a sector that breaks as the player walks on it, making him
fall on lava, water or "pinchos".
Balls.
To
make rolling balls, I would say, it is te easiest trap one could make.
Basically, we can create a place somewhat similar to this one:
1. This is the place where the ball will be held before
this one gets activated. It isn't neccesary to make a sector like this one since
when you create an entity, this one stays in it's place (floating in the air
) only if it isn't assigned the parameter o.Impulse(0,0,0) (Strongly
not recommended to use in a ball)
2. This is the slope that is
needed to make the ball roll and kill the player that enters it's territory (a
trigger sector). It isn't neccesary to make a slope nor it is recommended since
you can easily make the ball roll horizontally, but this one will stop somewhere
in the sector it is rolling as the strength of the push decreases. By creating a
slope, the ball will roll on it and it will not stop until it crashes against a
wall or falls into a deep hole.
3. This will be the trigger sector
that will make the ball roll down the slope. This one can be connected to a
room, door, etc. tat will lead the player to this trigger sector, therefore
activating the trap.
4. This is the hole where the ball will fall
after rolling over the slope. It isn't neccesary to make it, but remember that
if you don't create a place where the ball will be stored after it finishes
rolling, the player will not be able to enter or exit from this sector since the
ball will be blocking the way. If you decide to create a hole for tha ball,
remember to make it deep enough so that if the player falls through it, he would
die (to avoid getting trapped
)
Having
this information in mind, now let's create our ball:
import Bladex
import stone
import heavyObjects
#################
# OUR BALL
#################
p=3000,5000,4000 #Coordinates of the ball
r=0.707107,0.707107,0.000000,0.000000 #Orientation of the ball (not neccesary)
s=1.0 #Scale of the ball (default)
bola1=heavyObjects.CreateHeavyObject("Bola1","BoladePiedra",p,r,s,heavyObjects.StoneHitEvent)
stone.lock("Bola1",stone.DROPBROWNDUST,0,1100,0.0,0.2,20.0,stone.STONESOUND,0.1) # Sounds and
# dust, the arg just before the stone.STONESOUND is the time the sound will be played (20 secs).
# The last arg (0.1) is the volume.
bola1Sector=Bladex.GetSector(41000,-12000,-17500) #Trigger sector
bola1Sector.OnEnter= DropBola1
Function that will activate the ball
import stone
def DropBola1(sector,entity):
if entity == "Player1":
stone.drop("Bola1",-9999999,0,0)
bola1Sector.OnEnter= ""
else:
pass


import Bladex
import Ontake
MESSAGE_START_WEAPON=7
#SOUNDS
sonidoroturahueco=Bladex.CreateSound("..\\..\\Sounds\\single-boulder-impact.wav", "SonidoRoturaHueco")
sonidopinchosaliendo=Sounds.CreateEntitySound("..\\..\\Sounds\\blunt-impact3.wav", "SonidoPinchoSaliendo")
pinchosgolpeando1=Sounds.CreateEntitySound("..\\..\\Sounds\\golpe-metal-mediano.wav", "PinchosGolpeando1")
#PINCHOS
pincho1=Bladex.CreateEntity("Pincho1","PinchoManuel",5753.8,1945,-22769.8,"Weapon")
pincho1.Scale=1.6
pincho1.Orientation=0.707,0.0,0.0,0.707
pincho1.Frozen=1
pincho1.Solid=1
pincho1din=Objects.CreateDinamicObject("Pincho1")
#TRIGGER
pincho1activate=Bladex.GetSector(5000,0,-24000) #Trigger sector that activates the pincho
pincho1activate.OnEnter=ActivatePincho1
pincho1deactivate=Bladex.GetSector(3000,0,14000) #Trigger sector that deactivates the pincho
pincho1deactivate.OnEnter=DeactivatePincho1
import Objects
Pinchoactivated = 0
def ActivatePincho1(sector,entity):
if entity == "Player1":
global Pinchoactivated
Pinchoactivated = 1
Pincho1Sube()
pincho1activate.OnEnter=""
def DeactivatePincho1(sector,entity):
if entity == "Player1":
global Pinchoactivated
Pinchoactivated = 0
pincho1deactivate.OnEnter=""
def Pincho1Baja():
displacement=(1150,1150)
vectors=(0.0,1.0,0.0),(0.0,1.0,0.0)
vel_init=(15000,15000)
vel_fin=(15000,15000)
whilesnd=("","")
endsnd=("","")
Objects.NDisplaceObject(pincho1din,displacement,vectors,vel_init,vel_fin,(),whilesnd,endsnd)
Bladex.AddScheduledFunc(Bladex.GetTime()+0.5,Pincho1Sube,())
def Pincho1Sube():
global Pinchoactivated
if Pinchoactivated == 1:
displacement=(1150,1150) #Displacement of the Pincho (2300 total)
vectors=(0.0,-1.0,0.0),(0.0,-1.0,0.0)
vel_init=(15000,15000) #Initial speed of movement
vel_fin=(15000,15000) #Final speed of movement
whilesnd=(sonidopinchosaliendo,"") #While sound
endsnd=("",pinchosgolpeando1) #End sound
pincholabder.MessageEvent(MESSAGE_START_WEAPON,0,0)
Objects.NDisplaceObject(pincho1din,displacement,vectors,vel_init,vel_fin,(),whilesnd,endsnd)
Bladex.AddScheduledFunc(Bladex.GetTime()+0.5,Pincho1Baja,())
else:
pass



