Transform item when equipping using onEquip crashes the server
So I am writing a script which transforms an item when you equip it, when the part of the script reaches this aspect it crashes the server.
The Forgotten Server - Version 1.3
Compiled with GNU C++ version 5.4.0 20160609
Compiled on May 15 2017 10:22:33 for platform x64
A server developed by Mark Samman
Visit our forum for updates, support, and resources: http://otland.net/.
>> Loading config
>> Establishing database connection... MySQL 5.7.17
>> Running database manager
>> Loading vocations
>> Loading items
>> Loading script systems
>> Loading monsters
>> Loading outfits
>> Checking world type... PVP
>> Loading map
> Map size: 1000x1000.
> Map loading time: 1.215 seconds.
> Loaded house items in: 0.003 s
>> Initializing gamestate
>> Loaded all modules, server starting up...
>> Forgotten Server Online!
God has logged in.
As requested here is the stack trace. https://pastebin.com/Hc6dNHe9
This also seems to occur if I remove the item, item:remove() and then player:addItem... Could just be my code, i will try with a basic script, but for now here is the stack trace for that.
https://pastebin.com/8T3srgGe
I know what the problem was, since this item had conditions attached to it, when I removed it, it crashed the server. I didn't even think about this because I was using the same item to test the transformation.
Don't close the issue as it can be a bug, even if you found a fix around the crash. Could you provide steps to reproduce this crash?
I thought I gave the steps to reproduce the crash... I can't share the code because it isn't mine to share, technically it is mine because I am the one writing it but I can't publicly share it because I am being paid to write it.
I'll try to explain better.. The item is given a condition when it is equipped but also is transformed into another item, I've been working on this script for awhile now and its easy to overlook even the smallest things such as forgetting that x item has conditions assigned to it and then try to transform it into something else without properly removing the conditions.
Once I used a different item to test the transformation part, the script no longer crashed the server and even the conditions were applied to the transformed item. It was something I overlooked and I am glad I brought it up on otland and github because I probably would have never found a solution and just abandoned the idea all together.
I just tested a transform from Golden Legs to Demon Legs and the server didn’t crash, tested on the master.
Script
local event = MoveEvent()
function event.onEquip(player, item, slot, isCheck)
if not isCheck then
item:transform(2495) -- demon legs
end
return true
end
event:type("equip")
event:slot("legs")
event:id(2470) -- golden legs
event:register()
Using item:remove() followed by player:addItem(item) is not a desirable behavior. You should either clone the item before removing it, or simply move it directly to the player instead
I didn’t fully understand the issue with the condition, but if it’s related to the player, check the example below — it happens when switching between the Stealth Ring and the Life Ring.
local event = MoveEvent()
function event.onEquip(player, item, slot, isCheck)
if not isCheck then
item:transform(2165) -- stealth legs
end
return true
end
event:type("equip")
event:slot("ring")
event:id(2205) -- life legs
event:register()