On-Ground Traps: a way to make them

Discussion in 'Assorted Tech' started by Agetian, Jun 28, 2006.

Remove all ads!
  1. Agetian

    Agetian Attorney General Administrator

    Joined:
    Aug 14, 2004
    Messages:
    2,526
    Likes Received:
    0
    I'll have some time today and I'll probably spend it working on the core code for an abstract trap. I'll try to outline the very basic trap code that will execute on a map and see if it works. Then I'll publish it here for everyone to see and use in further trap research. ;)

    - Agetian
     
  2. Agetian

    Agetian Attorney General Administrator

    Joined:
    Aug 14, 2004
    Messages:
    2,526
    Likes Received:
    0
    OK guys, here's something to think about and to work with. This post has an attached script called 'trap_code.py', which contains a very basic outline of a working trap code. The code is far from perfect and is meant for demo purposes, as well as it's meant to serve as a foundation and basis for further trap research.

    What this code does:
    This code sets up a real trap in the rectangle (505,457)-(508,459). The code merely does the following: whenever any object enters this rectangle, it is dealt 1d10 cold damage. Damage will only be done once per tile (so standing in the rectangle won't keep the damage coming and coming until you die). If you advance to another trapped tile you'll get the damage dealt to you again.

    By default the trap fires multiple times. If you set TRAP_SINGLE_USE to "1" in the code, the trap will only fire once (as soon as it's set off, it is no more).

    A quick way to test the code:
    Load the Co8 5.0.0 mod with this script (the script requires co8.py which is only available in Co8 5.0.0), then type the following in your console:

    from trap_code import *
    game.timeevent_add(trap_core, (), 10)

    Then, try walking in the starting room. Eventually you'll hit the trapped area and will start getting damage.

    The way I implemented the once-per-tile behavior:
    The following part of the code in 'trap_on_activate' (the activation event) uses the object's otherwise unused padding fields in order to store the last pair of X,Y coordinates where the object got damaged:

    Code:
    def trap_on_activate(activation_list):
        for i in activation_list:
            x, y = location_to_axis(i.location)
            last_x = i.obj_get_int(obj_f_critter_pad_i_4)  # last X
            last_y = i.obj_get_int(obj_f_critter_pad_i_5)  # last Y
            if (x != last_x) and (y != last_y):
                i.damage(i, D20DT_COLD, dice_new("1d10")) # deal damage
                i.obj_set_int(obj_f_critter_pad_i_4, x)  # set last X
                i.obj_set_int(obj_f_critter_pad_i_5, y)  # set last Y
    
    Whenever a trap is activated, the damage is dealt only in case the current coordinates are not the same as the last coordinates where the trap fired for this object; then, the padding fields are set accordingly to reflect the "new" last X,Y coords.
    NOTE: The variable "i" is used for iteration through the activation_list which contains all objects that are within the activation rectangle. Therefore, it'll contain party member objects that have entered the activation rectangle.

    A check for trap detection (trap_on_detect) and activation (trap_on_activate) is made every 100ms by default, but it can be changed by changing TRAP_CHECK_SPEED; although I don't recommend anything above 100ms since the trap will start to get unresponsive). With 100ms and one trap I experienced absolutely no slowdown. Hopefully we can make a few more traps per map without getting the game laggy (my tests have shown that it's very much possible).

    Things to do:
    - Implement the detection code (in this code, detection happens whenever the player is TRAP_DETECTION_RADIUS tiles away from the activation rectangle (TRAP_AREA), and the routine that is executed in this case is called trap_on_detect; although right now it does absolutely nothing).
    - Implement the real trap object (an invisible object which stores all info about the trap, instead of using the global variables like TRAP_AREA, and which initiates the dialog with the player party if the detection was successful, etc.).
    - Implement the actual way of detecting such traps (through an extra object or just by making checks from the trap_core)
    - Way more to go. ;)

    I hope this can get you guys started. And remember, this particular trap code is not meant for direct practical usage, it has been optimized only for the clarity of code so you can understand how exactly you can get yourself started on the way of creating an on-ground trap or another event.

    If you have any questions about the code, don't hesitate to ask.
    - Agetian
     

    Attached Files:

    Last edited: Jul 1, 2006
  3. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    Seems you have thought of everything Ag. :clap: I will try to give this a workout when I have a chance.
     
  4. krunch

    krunch moving on in life

    Joined:
    Aug 9, 2005
    Messages:
    3,280
    Likes Received:
    0
    ooo - That kind of trap code with a one-time fire would be great to spawn a monster as an event.
     
  5. Agetian

    Agetian Attorney General Administrator

    Joined:
    Aug 14, 2004
    Messages:
    2,526
    Likes Received:
    0
    Yup, it can compensate quite well for the lack of tile-based events in the game. :)
    I hope you find it useful.

    - Agetian
     
  6. Lord_Spike

    Lord_Spike Senior Member Veteran

    Joined:
    Mar 25, 2005
    Messages:
    3,151
    Likes Received:
    0
    Can it be tied to an item...?

    "To read this scroll would be a fools folly..."

    Followed immediately by dis-integration, of course.
     
  7. rufnredde

    rufnredde Established Member Veteran

    Joined:
    Apr 8, 2006
    Messages:
    266
    Likes Received:
    1
    Don't see why you couldn't trigger it that way if you wanted Spike.
     
  8. Agetian

    Agetian Attorney General Administrator

    Joined:
    Aug 14, 2004
    Messages:
    2,526
    Likes Received:
    0
    Yeah, events for items already exist in the game (san_use comes to mind) - there's no need to use an event code like this for it. This event code is specifically meant for tile-based action, traps, monster spawning, and the like.

    - Agetian
     
  9. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    It just struck me. The possibilities for this are endless! (By which I mean, there are several).

    We can have proper lava that burns you when you step on it (but may well be the shortest distance to travel from A to B).

    Cliffs you can step off, if u r stupid enough - byebye! :wave:

    Combined with some spell-effect cloud graphics, sleep fields, fire fields, poison fields! (Ultima, anyone?)

    Puzzle patterns on the floor - step on the right tiles or KABOOM.

    I'm excited! :D
     
  10. Kalshane

    Kalshane Local Rules Geek

    Joined:
    Aug 6, 2004
    Messages:
    1,650
    Likes Received:
    0
    Considering the brainless path-finding in this game, I would highly recommend against adding treacherous terrain. A trap on the floor in a dungeon is one thing. Watching one of my PCs fall off a cliff because I mis-clicked or the game decided to make him go the wrong way would put me off the game real quick.
     
  11. Agetian

    Agetian Attorney General Administrator

    Joined:
    Aug 14, 2004
    Messages:
    2,526
    Likes Received:
    0
    @ Kalshane: Well, some things like you mention can be problematic, but this doesn't stop us from trapping (or "laying tile events in", for the more proper word ;)) smaller corridors and other areas where ambiguous pathfinding is almost impossible.

    - Agetian
     
  12. Kalshane

    Kalshane Local Rules Geek

    Joined:
    Aug 6, 2004
    Messages:
    1,650
    Likes Received:
    0
    Like I said, I don't have a problem with a trapped floor tile in a dungeon. But Ted's post made it sound like he wanted to do things like allow people to fall off in the Air Node or fall into the lava in the Fire Node. Which I don't think would work very well with the way movement and path-finding is handled in ToEE.
     
  13. krunch

    krunch moving on in life

    Joined:
    Aug 9, 2005
    Messages:
    3,280
    Likes Received:
    0
    Stepping in to lava in the seam of a rock in the elemental fire node would be bad, that would be one thing to experience momentary, one-time damage and could cause damage from some tiles in the node. That's where wearing a ring of fire protection should come in handy...takes me back to the days of playing online D&D MUD.

    Falling off the edge of a rock and becoming, completely, submersed in to a river of lava would be certain death with nothing of a body left to resurrect. I think that would be too far be too much...that is, a trap that casts disintegrate on a character every round as long as a character is off the rock platform and is unrescued by the party. Again, a magic item could be made to be worn whereby making a river of lava as harmless as clean, still water.

    [EDIT] Basically, damaging or deathly effects could be done for each node, and magic items could entirely negate damaging effects. However, I will say for the record that I do like the idea of having several momentary, one-time damage tiles for each node and am in favor of the one-time damage tiles. And, please, let's remember this is D&D and is not an Indiana Jones game.
     
    Last edited: Jul 7, 2006
  14. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    The air node? I never even thought of that. Thanks Kalshane! :D

    Actually, the pathfinding would be simple enough, because we can make our own paths: players won't walk off cliffs unless there are paths set for them to walk off cliffs (THAT would be nasty!) The only time you would have to be uber-careful is in fights, if u went close to a cliff - but that makes sense, it is the moment u would be most likely to stumble off.

    But it will be used sparingly Kal, in fact I have no particular plans, especially since the first cliff-fall will have people posting "but he was a 14th lvl monk, he should have been able to drop 7000 feet and only take 2d6 damage!" I just like the possibilities. :)
     
  15. Kalshane

    Kalshane Local Rules Geek

    Joined:
    Aug 6, 2004
    Messages:
    1,650
    Likes Received:
    0
    I've seen my PCs do enough stupid movement in battle (taking the long way around instead of the direct route, provoking AOOs all the way) that even limiting cliffs and such to fights could still be frustrating.
     
Our Host!