Ive been stuck on this question for a while now, so I hope someone can answer it. How can I code it so that, for instance, if a mob enters a turf such as a spike trap that occasionally shoots out spikes from a hole in the ground, that if the spikes shoot up while the mob is standing on it, the mob takes damage, rather than just having the spikes move up and do nothing.
Thanx in advance, Rein
ID:170292
Feb 18 2005, 8:33 am
|
|
Feb 18 2005, 8:43 am
|
|
if(mob/M in src)?
|
Reinhartstar wrote:
Ive been stuck on this question for a while now, so I hope someone can answer it. How can I code it so that, for instance, if a mob enters a turf such as a spike trap that occasionally shoots out spikes from a hole in the ground, that if the spikes shoot up while the mob is standing on it, the mob takes damage, rather than just having the spikes move up and do nothing. You would do something like this. Note that in the following code, it is assumed that the icon, Spike Trap.dmi, has four icon_states: "spikes up", "spikes down", "spikes upward", "spikes downward". The latter two states would be animations, while the former two would be still: "spikes upward" would be an animation that transitions from "spikes down" to "spikes up", while "spikes downward" would be the opposite. turf/Spike_Trap Of course, you would have to define takeDamage() yourself. |
In response to Wizkidd0123
|
|
Wizkidd0123 wrote:The Code
> turf/Spike_Trap Building on what wiz wrote now you can create the trap/thingy turf/Spike_Trap Please tell me if you find any errors or if I can do it more efficiently. AI-('Artificial Intelligence')Nothings real.lifs ust one good game. :) |
In response to Angel_Inc
|
|
Angel_Inc wrote:
Please tell me if you find any errors or if I can do it more efficiently. Well, frankly, you probably shouldn't be using a boolean variable to check if the spikes are up or down: you can just check the current icon_state. Also, instead of sleep(10) each time, which, by the way, is far too short: you should either have a global loop that opens and shuts each spike at the same time as needed, and if you don't want that, then let each spike have its own turf/Spike_Trap/var/speed, and then sleep(speed). Of course, it would be alot more efficient and less processor-intensive, if you're using the latter method, to "stagger" the delay. That basically means that instead of having each Spike_Trap with the same speed toggle between open and closed at the same time, you would, perhaps instead do something like, sleep(speed+rand(((speed/4)*-1),(speed/4))). That way, each loop isn't being run at the exact same time. All in all, if you don't need each Spike_Trap to have its own speed, then it would be much better to just run a global loop through everything, toggling the Spike_Traps as needed. An alternate method would be to have a global loop run through the world, and, using world.time, check if enough time has elapsed to open or close the spike. In other words, use a trap timer. This may be the best method, because that way, you maintain the speed of a global, as opposed to trap-specific, loop, while still allowing each Spike_Trap to have a speed: turf/Spike_Trap |