• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved confusing crash, where can I find problem?

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
I have been trying hours to figure out why it causing me crash. Perhaps someone here can help me look to right direction.

What happens is: when my monster precast spells and monster himself is removed after that, server crashes.

Before my latest update. Only thing what changed was: The channeling spell damage came from no source.
With the latest update I added: Spell can have multiple startpoints and spell can change target(s)/and positions.
Monster AI now uses same functions to check what does spellCasting use, to check if there is any point to cast spell (finds target if required)

*change stance removes the caster and creates new monster. (thats why the monster is removed in first place.)

error picture:
dbpn9y.png

Line 743 = print(spellName.." by: "..monster:getName().." has been executed")
Code:
function castSpell(monster, spellName)
if not monster then
print("caster puudub WTF?? IN castSpell()")
return true end
if not monster:getName() then print("did i make it happen?")
return true end

print(spellName.." and caster is: "..monster:getName())
local spell = ultimateSpellTable[spellName]
local positionTable = spell["position"]
local targetTable = spell["target"]
local targetList = {}

    if not positionTable then
        local newTargets = ultimateTargetList(monster, targetTable)
     
        for x=1, #newTargets do
            table.insert(targetList, newTargets[x])
        end
        ultimateCastSpell(monster, spell, targetList, nil, nil, spell.spellInterval)
    else
        local spellStartPos, positions = ultimateCreatePositions(monster, positionTable)
     
        for x=1, #spellStartPos do
            local newTargets = ultimateTargetList(monster, targetTable, positions[x])
     
            for n=1, #newTargets do
                table.insert(targetList, newTargets[n])
            end
            ultimateCastSpell(monster, spell, targetList[x], positions[x], spellStartPos[x], spell.spellInterval)
        end
    end
if not monster then print("did i make it happen2/!?")
return true end
print(spellName.." by: "..monster:getName().." has been executed")
end

and part of monster AI what channels spell AKA makes premade spells
Code:
                        if spellTable.interval then
                            local duration = spellTable.interval
                            while spellTable.spellLockCooldown*1000 > duration do
                                addEvent(castSpell, duration-spellTable.interval, monster, spellName)
                                duration = duration+spellTable.interval
                            end
                        else castSpell(monster, spellName)
                        end
 
Last edited:
The script is just a mess so im not even gonna look at it haha.
You must also miss alot of files here, since the errors don't match with what you posted.

If you do not want to post your full scripts, do a print on each function.
Code:
print("start")

doSmth()
print("1")

doSmthElse()
print("2")

print("end")
 
The script is just a mess so im not even gonna look at it haha.
You must also miss alot of files here, since the errors don't match with what you posted.

If you do not want to post your full scripts, do a print on each function.
Code:
print("start")

doSmth()
print("1")

doSmthElse()
print("2")

print("end")
i did it, i made it so:
if not monster:getId() then
print("error in functionName()")
return false
end

Still crashed hard.

Im not even sure why should that even be a problem..
I though crashes come because addEvent srarts an addEvent what never ends or loop what never ends.

if something is conflicting then only client crashes.

But right now, all i can think of is:
when userdata used passed for function and when the real monster stops existing then it should only give error.. but instead it crashes..
 
Last edited:
You should construct the Monster userdata object in the addEvent callback instead of passing it directly (since it's unsafe to pass userdata to addEvent), and you should enable warnUnsafeScripts in config.lua if you haven't done that already.
 
I'm not sure what are you trying to say here.

The function addEvent creates a scheduled event, if you know what that means you should also know that a userdata value is only valid till the player logout / dies etc etc.
So what Ninja said is that you are pushing a userdata value (that can be removed) insted of pushing the uid of the monster.

To then get the new functions to work with the uid you have to create the userdata value, via the function Monster(uid), just like Player(cid).
The uid value stands for unique id, in this case the unique id value of the monster that you are trying to index.
You do it the same way as in 1.0.
Code:
local monster = Monster(uid)
if(not monster) then
     return false
end

If you need to find functions like this you should look in your source code, eg. luascript.cpp.
You asked how to create a userdata value for a monster => serach for "monster" - since all Lua functions are registerd as strings.


Hope that was enough details haha.
 
Didn't know its called constructing a userdata xD (afterall I didn't learn LUA by book, I learned from code examples what I found in OTLand or by people who explained the problems I had)

Alright today in few hours I will test it out.
Also going to test if I don't use the spellCreator position creating function for Monster AI, what happens then. Maybe it makes some crashy variables float around.


Btw: what missing functions you are talking about? The console only gives 1 more "error" line - what spell was casted. This is simple print line at the end of Monster AI
But why you need this? This just says when the spell was made/generated
 
Didn't know its called constructing a userdata xD (afterall I didn't learn LUA by book, I learned from code examples what I found in OTLand or by people who explained the problems I had)

Alright today in few hours I will test it out.
Also going to test if I don't use the spellCreator position creating function for Monster AI, what happens then. Maybe it makes some crashy variables float around.


Btw: what missing functions you are talking about? The console only gives 1 more "error" line - what spell was casted. This is simple print line at the end of Monster AI
But why you need this? This just says when the spell was made/generated

You don't need a print if you don't want to - or did I not get you correctly?
That is the reason why I always tell ppl to not learn things here on OTLand.. All the tutorials here only learn the old scripting system + mainly only functions.
Some guy did one that explained loops, if statments etc but that can still not be compared to what you can learn via other pages / books.
 
You don't need a print if you don't want to - or did I not get you correctly?
eh you said this:
You must also miss alot of files here, since the errors don't match with what you posted.
But the only "error" what is not even an error and missing the line is simple print()

That is the reason why I always tell ppl to not learn things here on OTLand.. All the tutorials here only learn the old scripting system + mainly only functions.
Some guy did one that explained loops, if statments etc but that can still not be compared to what you can learn via other pages / books.
Well, I'm just learning things inside out. A bit more clunky way to do things, but progress is much faster to see :D

Ye, for some things I did take out Lua documentation to do some cool stuff, but most of the time I just go with the logic. And if my logic gives no results I come back to Support section :D

Besides lesson learned now and I can move forward until next problem comes along :p
 
eh you said this:

But the only "error" what is not even an error and missing the line is simple print()


Well, I'm just learning things inside out. A bit more clunky way to do things, but progress is much faster to see :D

Ye, for some things I did take out Lua documentation to do some cool stuff, but most of the time I just go with the logic. And if my logic gives no results I come back to Support section :D

Besides lesson learned now and I can move forward until next problem comes along :p

What I ment was that you dident upload all the related files, ex the full monster lib.
Missing a simple print? A print is not needed, it's used to print out things that you code, or to find out there a code stops working.
 
What I ment was that you dident upload all the related files, ex the full monster lib.
Missing a simple print? A print is not needed, it's used to print out things that you code, or to find out there a code stops working.
Umm, what is full monster lib? and why are these related to the current error?
 
i still don't follow though, So you are saying all the functions I created are called "lib", but they are still not really related to my error or wut?
problem was:
addEvent(castSpell, duration-spellTable.interval, monster, spellName)

and now I'm using: addEvent(castSpell, duration-spellTable.interval, monster:getId(), spellName)

because apparently
when i passed userdata and used something like userdata:getId() on nonexisting userdata, it crashed instead of giving me error.
 
i still don't follow though, So you are saying all the functions I created are called "lib", but they are still not really related to my error or wut?
problem was:
addEvent(castSpell, duration-spellTable.interval, monster, spellName)

and now I'm using: addEvent(castSpell, duration-spellTable.interval, monster:getId(), spellName)

because apparently
when i passed userdata and used something like userdata:getId() on nonexisting userdata, it crashed instead of giving me error.

Haha just nvm xD
 
Back
Top