Post tutorial RSS Level Editing Scripting by Prospero. Part. 16

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.

Posted by on - Basic Client Side Coding

Tut 16. 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:

python code:
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

python code:
import stone

def DropBola1(sector,entity):
 if entity == "Player1":
  stone.drop("Bola1",-9999999,0,0)
  bola1Sector.OnEnter= ""
 else:
  pass

Ok, now we have the code needed to make our trap work. Let me explain how all of this works. If we don't add the "if entity == "Player1":" to the function, this one could be activated by anything, including wandering enemies, arrows, etc. By adding this command to the function, we arrange it so that it will only be activated by the player ("Player1"). And if other entities such as an ork enter the sector, we have our "else:" and "pass" that will ignore the entities entering the sector.

In "stone.drop("Bola1",-9999999,0,0)" The first value is the name of our ball and the three remaining are the coordinates of movement of the ball. In this case, the ball will move to the East. "stone.drop("Bola1",9999999,0,0)" would make the ball go West, "stone.drop("Bola1",0,-9999999,0)" would make it go uo. Oh, and "stone.drop("Bola1",0,0,-9999999)" would make the ball go North.
By adding bola1Sector.OnEnter= "" to the function, will make it only be activated once.

Now we know how to create our ball. Let's roll!

--------------------------------------------------------------------

Another opportunity to die in an interesting way from Raptor....

Spike Trap.

LED PROCESS
These are the things you should do in your map through the LED in order to have a nice and neat trap. First, make a hole that goes underground -1 LED unit, and it's length and width of 0.5. Note that if you make the hole too big, the player might fall in it. And also remember to put the trap in a narrow passageway so that the player won't go around it:

Again, the hole is not neccesary since objects can freely move wherever and through any thing they want . It will just look more convincing if you make the hole .
Now, with the EBrowser place a PinchoManuel inside the hole. It is located in the section "Arquitectura" (Arquitecture). Like this:

We're done with the LED. Now let's go to the code!

THE CODE
Create a new .py file (pinchos.py?) and add this code to it (Remember to change the values set in yellow in the code below with the values you got from the EBrowser):

python code:
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

Now add this on DefFuncs.py:

python code:
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

There it is! That's all you need to make your pincho trap. Now let's review how it works:

THE REVIEW
The player reaches a trigger sector:

The trap is started:

The player luckily makes it to the other side...:

...which is the trigger sector that deactivates the trap:

The pincho will move up and down every 0.5 seconds and it won't stop until it gets deactivated. If you want to make it move at a faster pace, just modify the numbers GetTime() +0,5,Pincho1Baja, in the code above .
Well, now you know how to make another trap. And if you notice that I add too much explanation is because it is easier! Like one man said (I don't know who): "I made this letter long because I didn't had the time to make it short"

Btw, I made a little map if you are having some trouble with the code: Click Here
Just put it in your ..\..\BODLoader\Maps folder and install it from Blade.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.