# Making a trap

**URL:** https://discourse.cataclysmdda.org/t/making-a-trap/1149
**Category:** The Toolbox
**Created:** [May 7, 2013, 9:51pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149 "2013-05-07T21:51:55Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 7, 2013, 9:51pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/1 "2013-05-07T21:51:55Z")

</div>

Okay, for the past few days (few hours, really), I’ve been working on getting a mod up and running. Currently I am working on adding a few new traps.

I’ve already created them in trapdef, created the effects in trapfunc, created them in itypedef, and updated iuse( don’t quote me on that one). It lets me “place” the trap, but it is invisible (or simply not there), and when I walk on it it shows a sssssss in the announcement box and sometimes spawns shadow snakes.

Any ideas on what is happening here?

---

<div class="post-metadata">

### Author: ![GlyphGryph](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/glyphgryph/32/847_2.png) [@GlyphGryph](https://discourse.cataclysmdda.org/u/GlyphGryph)
#### Post date: [May 8, 2013, 1:57am UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/2 "2013-05-08T01:57:51Z")

</div>

It sounds like your pointing to the wrong trapfunc, honestly. Can you paste your trapdef and trapfunc code snippets here?

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 8, 2013, 11:07am UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/3 "2013-05-08T11:07:00Z")

</div>

trap def

`keys.clear();
id++;
keys.push_back("tape_trap");
traps.push_back(new trap(id, "TAPETRAP", "tape trap", c_dkgray, '_', 1, 6,
    0, &trapfunc::tape, &trapfuncm::tape, keys));;`

[code]void trapfunc::tape(game \*g, int x, int y)  
{  
g-\>add\_msg(“You get tangled in tape!”);  
g-\>u.moves -=150;  
}

trap func  
void trapfuncm::tape(game \*g, monster \*z, int x, int y)  
{  
if (g-\>u\_see(z))  
g-\>add\_msg(“The %s gets tangled in tape!”, z-\>name().c\_str());  
z-\>moves -= 150;  
}[/code]

For some reason they are just defaulting to snakes.

---

<div class="post-metadata">

### Author: ![Weyrling](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@Weyrling](https://discourse.cataclysmdda.org/u/Weyrling)
#### Post date: [May 8, 2013, 9:27pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/4 "2013-05-08T21:27:05Z")

</div>

[quote=“drake1storm, post:3, topic:1149”]`keys.clear();
id++;
keys.push_back("tape_trap");
traps.push_back(new trap(id, "TAPETRAP", "tape trap", c_dkgray, '_', 1, 6,
    0, &trapfunc::tape, &trapfuncm::tape, keys));;`

[code]void trapfunc::tape(game \*g, int x, int y)  
{  
g-\>add\_msg(“You get tangled in tape!”);  
g-\>u.moves -=150;  
}

void trapfuncm::tape(game \*g, monster \*z, int x, int y)  
{  
if (g-\>u\_see(z))  
g-\>add\_msg(“The %s gets tangled in tape!”, z-\>name().c\_str());  
z-\>moves -= 150;  
}[/code][/quote]  
I added your tape functions to trap.h and trapfuncs.cpp, and then applied them to the bubblewrap in trapdef.cpp. I spawned in a Zombie Brute and it sent the correct “tangled in tape” message and slowed it down a turn or so.  
I’m not familiar enough with CDDA to figure out how the adding of stuff works yet, I’m guessing you failed to initialize/include something, somewhere.

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 8, 2013, 10:24pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/5 "2013-05-08T22:24:33Z")

</div>

[quote=“Weyrling, post:4, topic:1149”][quote=“drake1storm, post:3, topic:1149”]`keys.clear();
id++;
keys.push_back("tape_trap");
traps.push_back(new trap(id, "TAPETRAP", "tape trap", c_dkgray, '_', 1, 6,
    0, &trapfunc::tape, &trapfuncm::tape, keys));;`

[code]void trapfunc::tape(game \*g, int x, int y)  
{  
g-\>add\_msg(“You get tangled in tape!”);  
g-\>u.moves -=150;  
}

void trapfuncm::tape(game \*g, monster \*z, int x, int y)  
{  
if (g-\>u\_see(z))  
g-\>add\_msg(“The %s gets tangled in tape!”, z-\>name().c\_str());  
z-\>moves -= 150;  
}[/code][/quote]  
I added your tape functions to trap.h and trapfuncs.cpp, and then applied them to the bubblewrap in trapdef.cpp. I spawned in a Zombie Brute and it sent the correct “tangled in tape” message and slowed it down a turn or so.  
I’m not familiar enough with CDDA to figure out how the adding of stuff works yet, I’m guessing you failed to initialize/include something, somewhere.[/quote]

So it works with bubblewrap, eh?

Hmm, give me a minute. I might be able to fix this if that is true.

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 8, 2013, 11:21pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/6 "2013-05-08T23:21:56Z")

</div>

This is really odd. Everywhere bubblewrap is, my trap stuff is as well. I double checked, and everything is using my trap functions.

Oddly, though, all existing traps can use my trap functions, but anything that uses tr\_tapetrap seems to default to the snake function. I tried changing it over to using tr\_bubblewrap, but then it simply became bubble wrap.

This is very odd.

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 11, 2013, 9:28pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/7 "2013-05-11T21:28:20Z")

</div>

So then devs… no ideas, or is this going to be one of the things pumped out to a json, thus making any fixes here obsolete?

---

<div class="post-metadata">

### Author: ![Soron](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/soron/32/885_2.png) [@Soron](https://discourse.cataclysmdda.org/u/Soron)
#### Post date: [May 12, 2013, 9:21pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/8 "2013-05-12T21:21:48Z")

</div>

No ideas, it looks like everything should be in order. Maybe post larger chunks of code, possibly inside spoiler tags (for space reasons) or on pastebin?

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 12, 2013, 9:35pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/9 "2013-05-12T21:35:14Z")

</div>

I’m planning on trying to plug it all back together again after the latest git version is up. Chances are high the things they are changing will break any trap modifications I come up with.

---

<div class="post-metadata">

### Author: ![Soron](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/soron/32/885_2.png) [@Soron](https://discourse.cataclysmdda.org/u/Soron)
#### Post date: [May 12, 2013, 10:05pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/10 "2013-05-12T22:05:28Z")

</div>

I don’t think the current wave of changes is going to directly affect traps, at least not to the extent that things break catastrophically. The traps files haven’t been touched in… 8 days in one case, 19 days in another. And although we ARE moving lots of items to JSON, the original macro definitions are still present, albeit deprecated (mostly because random pseudo-items use some of those macros).

Is there anything in particular that you think will end up breaking stuff for you?

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 12, 2013, 10:09pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/11 "2013-05-12T22:09:19Z")

</div>

Just seems like moving the trap items themselves out to a json would be the next logical step, considering what has been done so far. If not, I guess I’d better download the latest (hopefully working) source code tomorrow and start putting up the various updates and tests items I’ve got collecting dust.

---

<div class="post-metadata">

### Author: ![Soron](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/soron/32/885_2.png) [@Soron](https://discourse.cataclysmdda.org/u/Soron)
#### Post date: [May 12, 2013, 11:00pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/12 "2013-05-12T23:00:19Z")

</div>

The in-inventory trap items should already have been moved over, just like all the other tools. The trap definitions, on the other hand, aren’t on any immediate list for conversion.

So, yeah, the current code should be more-or-less stable with regards to traps, at least for a little while.

---

<div class="post-metadata">

### Author: ![drake1storm](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@drake1storm](https://discourse.cataclysmdda.org/u/drake1storm)
#### Post date: [May 12, 2013, 11:14pm UTC](https://discourse.cataclysmdda.org/t/making-a-trap/1149/13 "2013-05-12T23:14:02Z")

</div>

Ok, guess I have a plan for what to do tommorrow:

1. Wake up and take my last AP exam
2. Pass out until the school day is over
3. Get these bleeding things working (which is well overdue).
