Spike trap script help
Posted: Tue Apr 14, 2015 12:36 am
I'm setting up a spawned spike trap system and have run into a roadblock with the damage. This is what I have so far. I have the room where the spikes are, and a lever that activates and deactivates the spike trap script. I then have hidden pressure plates put down at the spot where the spike traps are and when a player/monster walks over them they take damage. Here's the problem: when a monster takes damage it crashes the game and produces an error "attempt to index a nil value". I know I could disable the traps from triggering when a monster walks over it, but I actually want monsters to take damage via the traps.
Here's the related scripts:
Spike trap activation/deactivation
spike trap damage
My testing has revealed that this only happens when a monster crosses that tile, and it does not matter what type of monster; even custom monsters will cause the crash. Player characters take damage as normal. The error itself is being produced on the DamageTile line itself. My guess is that since I have all the spikes activating the damage even if that tile doesn't have anything on it; the blank tiles are causing the error as there's no entity to damage; but if that was true why does it not crash when a player crosses over it? Any advice would be great!
Here's the related scripts:
Spike trap activation/deactivation
SpoilerShow
-- spawns spike traps and despawns them with lever press
function spiketrap()
if lever_4:getLeverState() == "activated" then
spawn("dm_spikes_floortrap", 1, 11, 8, 0, "spikes1")
spawn("dm_spikes_floortrap", 1, 12, 8, 0, "spikes2")
spawn("dm_spikes_floortrap", 1, 13, 8, 0, "spikes3")
spawn("dm_spikes_floortrap", 1, 11, 10, 0, "spikes4")
spawn("dm_spikes_floortrap", 1, 12, 10, 0, "spikes5")
spawn("dm_spikes_floortrap", 1, 13, 10, 0, "spikes6")
spawn("dm_spikes_floortrap", 1, 11, 9, 0, "spikes7")
spawn("dm_spikes_floortrap", 1, 13, 9, 0, "spikes8")
playSound("pressure_plate_pressed")
else
if lever_4:getLeverState() == "deactivated" then
spikes1:destroy()
spikes2:destroy()
spikes3:destroy()
spikes4:destroy()
spikes5:destroy()
spikes6:destroy()
spikes7:destroy()
spikes8:destroy()
playSound("pressure_plate_released")
else
return false
end
end
end
function spiketrap()
if lever_4:getLeverState() == "activated" then
spawn("dm_spikes_floortrap", 1, 11, 8, 0, "spikes1")
spawn("dm_spikes_floortrap", 1, 12, 8, 0, "spikes2")
spawn("dm_spikes_floortrap", 1, 13, 8, 0, "spikes3")
spawn("dm_spikes_floortrap", 1, 11, 10, 0, "spikes4")
spawn("dm_spikes_floortrap", 1, 12, 10, 0, "spikes5")
spawn("dm_spikes_floortrap", 1, 13, 10, 0, "spikes6")
spawn("dm_spikes_floortrap", 1, 11, 9, 0, "spikes7")
spawn("dm_spikes_floortrap", 1, 13, 9, 0, "spikes8")
playSound("pressure_plate_pressed")
else
if lever_4:getLeverState() == "deactivated" then
spikes1:destroy()
spikes2:destroy()
spikes3:destroy()
spikes4:destroy()
spikes5:destroy()
spikes6:destroy()
spikes7:destroy()
spikes8:destroy()
playSound("pressure_plate_released")
else
return false
end
end
end
SpoilerShow
-- spike damage script
function spikedamage()
local spikes = findEntity("spikes1");
if (spikes ~= nil) then
damageTile(1, 11, 8, 0, 6, "physical", 30)
damageTile(1, 12, 8, 0, 6, "physical", 30)
damageTile(1, 13, 8, 0, 6, "physical", 30)
damageTile(1, 11, 10, 0, 6, "physical", 30)
damageTile(1, 12, 10, 0, 6, "physical", 30)
damageTile(1, 13, 10, 0, 6, "physical", 30)
damageTile(1, 11, 9, 0, 6, "physical", 30)
damageTile(1, 13, 9, 0, 6, "physical", 30)
else
return false
end
end
function spikedamage()
local spikes = findEntity("spikes1");
if (spikes ~= nil) then
damageTile(1, 11, 8, 0, 6, "physical", 30)
damageTile(1, 12, 8, 0, 6, "physical", 30)
damageTile(1, 13, 8, 0, 6, "physical", 30)
damageTile(1, 11, 10, 0, 6, "physical", 30)
damageTile(1, 12, 10, 0, 6, "physical", 30)
damageTile(1, 13, 10, 0, 6, "physical", 30)
damageTile(1, 11, 9, 0, 6, "physical", 30)
damageTile(1, 13, 9, 0, 6, "physical", 30)
else
return false
end
end