• 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 Segmentation Fault onEquip

GhostWD

I'm in love with the var_dump()
Joined
Jan 25, 2009
Messages
185
Solutions
6
Reaction score
29
Hello OTLanders,
I have problem with my script or maybe engine cause when I use this script and I create item with /i 797 without having helmet or using chest with that item
error occurs Segmentation Fault

<movevent type="Equip" itemid="797" slot="head" event="script" value="frozenhelmet.lua"/>
<movevent type="DeEquip" itemid="797" slot="head" event="script" value="frozenhelmet.lua"/>
Lua:
local rateAdded = 0.15


function onEquip(cid, item, slot)
local rateNow = getPlayerRates(cid)[SKILL__LEVEL]
    if getPlayerSlotItem(cid, slot).itemid == item.itemid then
        doPlayerSetExperienceRate(cid, rateNow+rateAdded)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have equipped frozen helmet")
        return true
    end
   
return true
end


function onDeEquip(cid, item, slot)
local rateNow = getPlayerRates(cid)[SKILL__LEVEL]

        doPlayerSetExperienceRate(cid, rateNow-rateAdded)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have deequipped frozen helmet")
   

return true
end
Thank you for reply
 
Code:
if getPlayerSlotItem(cid, slot).itemid == item.itemid then
getPlayerSlotItem can be nil.
 
so i'm back it really wont work properly i still get segfault even without line onDeEquip that happens only when using quest chest without helmet on or using command /i without helmet
Lua:
function onEquip(cid, item, slot, boolean)
    if boolean ~= nil then
  
    if not boolean and slot == CONST_SLOT_HEAD and isPlayer(cid) then
            local rateAdded = 0.15
        local rateNow = getPlayerRates(cid)[SKILL__LEVEL]
        doPlayerSetExperienceRate(cid, rateNow+rateAdded)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have equipped frozen helmet")
      
    end end
  
return true
end



function onDeEquip(cid, item, slot)

        local rateNow = getPlayerRates(cid)[SKILL__LEVEL]
        doPlayerSetExperienceRate(cid, rateNow-rateAdded)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have deequipped frozen helmet")
  
return true
end
 
If you add an item via command or chest and it goes directly into the helmet slot then it gives you the segfault because it doesn't properly execute the onEquip but tries to hook the script. This is an error in your source code
 
If you add an item via command or chest and it goes directly into the helmet slot then it gives you the segfault because it doesn't properly execute the onEquip but tries to hook the script. This is an error in your source code
Honestly he should be able to fix it by doing this, no?
Lua:
function onEquip(cid, item, slot, boolean)
   if boolean == false then
       if slot == CONST_SLOT_HEAD then -- I honestly have no idea what this line is trying to accomplish.. unless you can equip helmets in the rope slot or something.. zzz
           local rateAdded = 0.15
           local rateNow = getPlayerRates(cid)[SKILL__LEVEL]
           doPlayerSetExperienceRate(cid, rateNow+rateAdded)
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have equipped frozen helmet")
       end
   end
   return callFunction(cid, item.uid, slot, boolean)
end

function onDeEquip(cid, item, slot)
   if boolean == false then
       local rateNow = getPlayerRates(cid)[SKILL__LEVEL]
       doPlayerSetExperienceRate(cid, rateNow-rateAdded)
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You have deequipped frozen helmet")
   end
   return callFunction(cid, item.uid, slot, boolean)
end
 
Back
Top