• 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 Need Little Help with enchanting. Moonlight Crystals / Werewolf Amulet / Werewolf Helmet

Majster12

Member
Joined
Feb 20, 2009
Messages
134
Solutions
1
Reaction score
16
Tried to solve this by myself but without results.
If paladin or royal paladin use moonlight crystals on werewolf helmet he should receive enchanted werewolf helmet (paladin), but he always receive enchanted werewolf helmet (mage/druid).

Code:
local enchantableItems = {24716, 24718}
local moonlightcrystals = {24739}
local mageitems = {
    [24716] = {24717},
    [24718] = {24784}
}
local paladinitems = {
    [24716] = {24717},
    [24718] = {24772}
}
local knightitems = {
    [24716] = {24717},
    [24718] = {24783}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isInArray(moonlightcrystals, item.itemid) then
        if not isInArray(enchantableItems, target.itemid) then
            fromPosition:sendMagicEffect(CONST_ME_POFF)
            return true
        end

        local targetId = table.find(moonlightcrystals, item.itemid)
        if not targetId then
            return true
        end
       
    if getPlayerVocation(cid) == 1 or 5 or 4 or 6 then
        target:transform(mageitems[target.itemid][targetId])
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        item:remove(1)
        return true
    end
    if getPlayerVocation(cid) == 3 or 7 then
        target:transform(paladinitems[target.itemid][targetId])
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        item:remove(1)
        return true
    end
    if getPlayerVocation(cid) == 4 or 8 then
        target:transform(knightitems[target.itemid][targetId])   
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        item:remove(1)
        return true
    end
    end
    end

Code:
<item id="24739" ="moonlight crystals" />
<item id="24716" ="werewolf amulet">
<item id="24717" ="enchanted werewolf amulet">
<item id="24718" ="werewolf helmet">
<item id="24784" ="enchanted werewolf helmet (mage/druid)">
<item id="24772" ="enchanted werewolf helmet (paladin)">
<item id="24783" ="enchanted werewolf helmet (knight)">
 
Code:
local moonlightcrystals = {24739}
local items = { -- 1 and 2 is mage, 3 is paladin, 4 is knight, change if wrong
    [1] = {
        [24716] = {24717},
        [24718] = {24784}
    }
    [3] = {
        [24716] = {24717},
        [24718] = {24772}
    }
    [4] = {
        [24716] = {24717},
        [24718] = {24783}
    }
}
items[2] = items[1]

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation()%4
    voc = (voc > 0 and voc) or 4
    if isInArray(moonlightcrystals, item:getId()) then
        local toId = items[voc][item.itemid]
        if toId then
            target:transform(toId)
            item:remove(1)
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        else
            fromPosition:sendMagicEffect(CONST_ME_POFF)
            return true
        end
    end
end
try this, should work
your code didnt work because you had broken if statements,
if x == y or z or n then
this means if x == y it will continue, if z or n is "true" (true, number, anything not false/nil) it will continue, you can not do multiple checks like that
you have to do
if x == y or x == z or x == n then
i left in the
if isInArray(moonlightcrystals, item:getId()) then
check, but since you register the itemids, the action will never execute if its not those ids anyway, so it isnt really needed

i changed it so no matter what voc it gets it straight from the table at the vocation numbers index (voc%4 means modulo 4, e.g whats left after division is returned, 5%4 = 1, 6%4 = 2, etc)
then you dont need to find the items in table, can just get straight from id key
 
Code:
local moonlightcrystals = {24739}
local items = { -- 1 and 2 is mage, 3 is paladin, 4 is knight, change if wrong
    [1] = {
        [24716] = {24717},
        [24718] = {24784}
    }
    [3] = {
        [24716] = {24717},
        [24718] = {24772}
    }
    [4] = {
        [24716] = {24717},
        [24718] = {24783}
    }
}
items[2] = items[1]

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local voc = player:getVocation()%4
    voc = (voc > 0 and voc) or 4
    if isInArray(moonlightcrystals, item:getId()) then
        local toId = items[voc][item.itemid]
        if toId then
            target:transform(toId)
            item:remove(1)
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        else
            fromPosition:sendMagicEffect(CONST_ME_POFF)
            return true
        end
    end
end
try this, should work
your code didnt work because you had broken if statements,
if x == y or z or n then
this means if x == y it will continue, if z or n is "true" (true, number, anything not false/nil) it will continue, you can not do multiple checks like that
you have to do
if x == y or x == z or x == n then
i left in the
if isInArray(moonlightcrystals, item:getId()) then
check, but since you register the itemids, the action will never execute if its not those ids anyway, so it isnt really needed

i changed it so no matter what voc it gets it straight from the table at the vocation numbers index (voc%4 means modulo 4, e.g whats left after division is returned, 5%4 = 1, 6%4 = 2, etc)
then you dont need to find the items in table, can just get straight from id key

Really nice solution.
But i have this error:
Btw i added 2x"," line 6 and 10.
TsEs5RB.png
 
Back
Top Bottom