Lua:
local monsters = {
["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
}
local function doRemoveCorpse(pos, creature)
for i = 0, 255 do
pos.stackpos = i
tile = getTileThingByPos(pos)
if tile.uid > 0 and isCorpse(tile.uid) then
doRemoveItem(tile.uid)
end
end
local summon = doSummonCreature(creature, pos)
addEvent(removeCreature, 60000, summon) -- 60000 is 1 minute
end
@Xikini You are passing
creature argument, which is indeed a
var.next to a
doRemoveCorpse, in which it's accessible
, and your logic is actually
summoning and
removing the
creature.
Lua:
tile = getTileThingByPos(pos)
if tile.uid > 0 and isCorpse(tile.uid) then
doRemoveItem(tile.uid)
end
also, that's not a tile (not a biggie) and it should be local (
biggie)
Other than it's kinda messed up, it's exactly the same code that I edited - how came mine errored? These outdated engines are not my thing
Calm down lol.
I only added what op asked for. I didn't alter his original code, since that isn't what he wanted.
If we wanted to do this correctly, I'd simply make this an onDeath trigger, so we remove only the corpse of the summon, instead of all corpses on the tile.
regardless, you'd want to remove the corpses from the top down, instead of the bottom up, since you'd miss a few items the way it's currently setup.
--
I didn't have the time earlier to read through the entire thread and was face palming because it was an easy request, yet there was already 10+ replies.
The issue with your script is fairly simple to correct though.
You have
doSummonCreature(pos, monster.next)
Which should be
doSummonCreature(monster.next, pos)
which doesn't throw an error for not summoning, but your addEvent which relied upon that creature summoning error'd instead.
addEvent(doRemoveThing, 60*1000, summon.uid)
Without testing, I'm fairly certain the scripts reads it like this..
summon.uid.uid
because of old tfs logic.
So it's kind of a 3-fold issue.
Summon didn't spawn, so can't find it.
If summon did spawn, it can't find it, because of the
uid.uid
issue
and if the summon died before the addEvent went off, it'd throw an error because the summon no longer exists.
--
Anyway, here's the updated code based on how I'd do it.
Lua:
local monsters = {
["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}, removalDelay = 60000}
}
local function removeCreature(cid)
if isCreature(cid) then
doRemoveCreature(cid)
end
end
local function createTemporaryMonster(creatureName, position, removalDelay)
removalDelay = removalDelay or 60000 -- default to 60 seconds
local monster = doCreateMonster(creatureName, position)
addEvent(removeCreature, removalDelay, monster)
end
function onDeath(cid, corpse, deathList)
local monsterIndex = monsters[getCreatureName(cid)]
if monsterIndex then
if monsterIndex.chance <= math.random(100) then
local position = getThingPosition(cid)
addEvent(createTemporaryMonster, 0, monsterIndex.next, position, monsterIndex.removalDelay) -- require a nominal delay, so that creature can fully die and newly spawned creature takes it's place
doRemoveItem(corpse.uid) -- uid is required here, since it's an item.
doCreatureSay(cid, monsterIndex.msg[math.random(#monsterIndex.msg)], TALKTYPE_ORANGE_1)
end
end
return true
end