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

Lua Lua function onEquip bug 0.3.6pl1

rsdsebek

C++/LUA coder
Joined
Oct 8, 2008
Messages
128
Reaction score
30
Hi
I wrote small script in order to check onEquip lua function:
Code:
function onEquip(cid, item, slot)
	print(0)
	return true
end

function onDeEquip(cid, item, slot)
	print(1)
	return true
end
When I deEquip item console writes:
Code:
1
but when I Equip item console writes:
Code:
0
0
OnEquip function makes all things two times. What's the reason of this? I made second script for adding skillTry every one second. If I login it adds skillTry properly, but when I deEquip and Equip it's adding double skillTry.

Best
 
You should try this way. I think it's better than edit in source code.
LUA:
function onEquip(cid, item, slot)
    if getCreatureStorage(cid, slot) >= 0 then
        return true
    end

    -- here you paste your code
    -- print(0)

    doCreatureSetStorage(cid, slot, 0)
    return true
end


function onDeEquip(cid, item, slot)
    -- here you paste your code
    -- print(1)

    doCreatureSetStorage(cid, slot, -1)
    return true
end
 
Sorry, found a way to fix the problem before your post, and I think passing the problem is not the best solution. I've seen about three posts with the same problem - I will post solution here.
Problem is conditional instruction in player.cpp
Code:
if(!g_moveEvents->onPlayerEquip(const_cast<Player*>(this), const_cast<Item*>(item), (slots_t)index, true))
			return RET_CANNOTBEDRESSED;
It's checking if item returns true, but also is calling function onPlayerEquip - and that's the problem. I guess I will comment this lines with // and problem will be solved. This problem occurs also in newest Mystic Spirit.

Regards
 
Back
Top