• 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!

Solved What is wrong? Lua

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
I using this addEvent and got error on screen (but works)

addEvent(EventOrsha.spawnMonster, 2 * 1000, getPlayerPosition(cid), cid, item_monsters)

error:

luaAddEvent(). Argument #4 is unsafe
stack traceback:
[C]: in function 'addEvent'
 
Solution
there is no argument 4.
but if the 2nd argument maybe is creature userdata
do this line before
Code:
cid = type(cid) == "userdata" and cid:getId() or cid
there is no argument 4.
but if the 2nd argument maybe is creature userdata
do this line before
Code:
cid = type(cid) == "userdata" and cid:getId() or cid
 
Solution
there is no argument 4.
but if the 2nd argument maybe is creature userdata
do this line before
Code:
cid = type(cid) == "userdata" and cid:getId() or cid
that is argument 4 of addEvent

I using this addEvent and got error on screen (but works)

addEvent(EventOrsha.spawnMonster, 2 * 1000, getPlayerPosition(cid), cid, item_monsters)

error:

luaAddEvent(). Argument #4 is unsafe
stack traceback:
[C]: in function 'addEvent'
can you post the EventOrsha.spawnMonster function?
you have to pass creature id through the function and recreate the creature object with the creature id
 
that is argument 4 of addEvent


can you post the EventOrsha.spawnMonster function?
you have to pass creature id through the function and recreate the creature object with the creature id
Sure (thanks):

Code:
EventOrsha.spawnMonster = function (pos, cid, monsters)
print("teste 1.")
if ( isPlayer(cid) ) then
local getTime = getPlayerStorageValue(cid, 59556)
if ( getTime >= os.time() ) then
for _, monsterName in ipairs(monsters) do
Game.createMonster(monsterName, pos)
end
--addEvent(EventOrsha.spawnMonster, 60 * 1000, pos, cid ,monsters) -- I marked here for spawn 1x only
print("teste 2.")
end
end
return true
end
 
ah, idk why though arguments start from 3rd paramater of addEvent xD
It doesn't start from 3. It starts from 1st argument of addEvent and not 1st argument of callback function. The error is related to the addEvent and not to the callback, thus it's more logical to count the arguments of addEvent and not the callback itself.
 
Back
Top