I am battling with this problem as well, and I suppose many will be doing likewise in the future, so I humbly suggest adding this topic to the modding superthread.
I am trying to do a room with 3 slimes, so that when you kill them, the last one you kill always has a green gem item. I've simplified by isolating one of the slimes for testing purposes (the one to be killed last), and I've managed to build a functioning counter that will run a lua script entity on the map when you kill a slime. The script is then supposed to check if the counter equals 2 (in other words, 2 of the three slimes killed), and if it is so, it will place the green_gem item on the remaining slime. The thing is, the last part doesn't work, apparently. I don't know the reason. My codes are as follows.
The onDie function with the slime:
Code: Select all
onDie = function(self)
local s = slimekillcounter
local sl = givegemscript
s:increment()
sl:givegem()
end,
"slimekillcounter" is the counter on the map
"givegemscript" is the script entity.
This part seems to work correctly, but I am not entirely sure.
This is the script entity (simplified for testing, the final product would be threefold)
Code: Select all
function givegem()
if slimekillcounter == 2 then
if not findEntity("sewer_slime_1") and not findEntity("sewer_slime_2") then
sewer_slime_3:addItem("green_gem") else
nothing()
end
end
end
I killed the slimes using conventional means and I have verified the counter works as intended. The problem is probably in the latter part.