• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

problem with variables and addEvent

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Reaction score
65
Location
with Taiga
Hello guys, I want to use in second function(the one called with addEvent) variables getting value in the first one.
But dunno how to make it
Can anyoune help me with it?
Tried even making these variables global...
EDIT, ok its almost done, just don't want to remove item
Code:
local monsters = {
        ["Deathless Dragon"] = {
                body = 6306,
                effect1 = 0, -- 0 for no effects.
				effect2= 0,
				time = 5000
                }
}

local function wstan(parameters)
	doRemoveThing(parameters.corpse)
	doCreateMonster(parameters.monster, parameters.pos)
	doSendMagicEffect(parameters.pos, parameters.effect2)
	return TRUE
end

function onKill(cid, target)
	local select = monsters[getCreatureName(target)]
	if select ~= nil then
		local pos = getCreaturePosition(target)
		local monster = getCreatureName(target)
		doRemoveThing(target)
		local corpse = doCreateItem(select.body, pos)
		local effect2 = select.effect2
		local parameters = {pos = pos, corpse = corpse, monster = monster, effect2 = effect2}
		addEvent(wstan, select.time, parameters)
		doSendMagicEffect(pos, select.effect1)
		return TRUE
	end
return TRUE
end
and
Code:
[12/12/2009 12:37:16] Lua Script Error: [CreatureScript Interface] 
[12/12/2009 12:37:16] in a timer event called from: 
[12/12/2009 12:37:16] data/creaturescripts/scripts/kill2.lua:onKill

[12/12/2009 12:37:16] luaDoRemoveItem(). Item not found
For me code looks ok, but it don't want to work ;f
 
Last edited:
You can't preserve uids for the events because they change on every function callback. You'll have to use getTileItemById/getThingfromPos in your event.
 
hmm, in second from is lowcase? Anyway I tried it and the same error ;f
At least I know why this method doesn't work
you mean that
Code:
doRemoveThing(getThingfromPos(parameters.pos))
?
It doesn't work.:/

EDIT: ok, I made it working, needed some examples of getTileItemById usage,
heres the code if someone wants it
Code:
local monsters = {
        ["Deathless Dragon"] = {
                body = 6306,
                effect1 = -1, --   -1 for no effects.
				effect2= 13,
				time = 5000
                }
}

local function wstan(parameters)
	doRemoveThing(getTileItemById(parameters.pos, parameters.body).uid, 1)
	doCreateMonster(parameters.monster, parameters.pos)
	if (parameters.effect2 > -1) and (parameters.effect2<68) then
		doSendMagicEffect(parameters.pos, parameters.effect2)
	end
	return TRUE
end

function onKill(cid, target)
	local select = monsters[getCreatureName(target)]
	if select ~= nil then
		local pos = getCreaturePosition(target)
		local monster = getCreatureName(target)
		doRemoveThing(target)
		local corpse = doCreateItem(select.body, pos)
		local effect2 = select.effect2
		local parameters = {pos = pos, corpse = corpse, monster = monster, effect2 = effect2, body = select.body}
		addEvent(wstan, select.time, parameters)
		if (select.effect1 > -1) and (select.effect1<68)then
			doSendMagicEffect(pos, select.effect1)
		end
		return TRUE
	end
return TRUE
end
 
Last edited:

Similar threads

Back
Top