• 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 i can use item to get an addon i alrdy have

mattehj

Member
Joined
Oct 8, 2009
Messages
85
Reaction score
16
So, I actually manage to make my own script to get full addon when click on item, But If i use the item again, I get lighting effect and it remove my item, instead of saying You own no premium account or already own this outfit part


Lua:
local config = {

         -- Racoon
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE},

}

local addons = Action()

function addons.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local useItem = config[item.itemid]
    if not useItem then
        return true
    end

    local looktype = player:getSex() == PLAYERSEX_FEMALE and useItem.female or useItem.male

    if useItem.addon then
    
        player:addOutfitAddon(useItem.female, useItem.addon)
        player:addOutfitAddon(useItem.male, useItem.addon)
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)

        
        item:remove()
        
    else
        if not player:isPremium() or player:hasOutfit(looktype) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You own no premium account or already own this outfit part.')
            return true
        end

        player:addOutfit(useItem.female)
        player:addOutfit(useItem.male)
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
        item:remove()
    end
    return true
end

addons:id(40869)
addons:register()
 
Solution
So, I actually manage to make my own script to get full addon when click on item, But If i use the item again, I get lighting effect and it remove my item, instead of saying You own no premium account or already own this outfit part


Lua:
local config = {

         -- Racoon
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE},

}

local addons = Action()

function addons.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local useItem = config[item.itemid]
    if not useItem then
        return true
    end

    local looktype = player:getSex() == PLAYERSEX_FEMALE and useItem.female or useItem.male

    if useItem.addon then
 
        player:addOutfitAddon(useItem.female, useItem.addon)...
So, I actually manage to make my own script to get full addon when click on item, But If i use the item again, I get lighting effect and it remove my item, instead of saying You own no premium account or already own this outfit part


Lua:
local config = {

         -- Racoon
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE},

}

local addons = Action()

function addons.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local useItem = config[item.itemid]
    if not useItem then
        return true
    end

    local looktype = player:getSex() == PLAYERSEX_FEMALE and useItem.female or useItem.male

    if useItem.addon then
 
        player:addOutfitAddon(useItem.female, useItem.addon)
        player:addOutfitAddon(useItem.male, useItem.addon)
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)

 
        item:remove()
 
    else
        if not player:isPremium() or player:hasOutfit(looktype) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You own no premium account or already own this outfit part.')
            return true
        end

        player:addOutfit(useItem.female)
        player:addOutfit(useItem.male)
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
        item:remove()
    end
    return true
end

addons:id(40869)
addons:register()
Add in the begining of the function
Lua:
if player:hasOutfit(useItem.female) or player:hasOutfit(useItem.male) then
    return true
end

Full script edited:
Lua:
local config = {
         -- Racoon
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE},
}

local addons = Action()

function addons.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local useItem = config[item.itemid]
    if not useItem then
        return true
    end

    if not player:isPremium() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You own no premium account.')
        return true
    end

    if player:hasOutfit(useItem.female) or player:hasOutfit(useItem.male) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You already own this outfit part.')
        return true
    end

    if player:getSex() == PLAYERSEX_FEMALE then
        player:addOutfit(useItem.female)
        player:addOutfitAddon(useItem.female, useItem.addon)
    else
        player:addOutfit(useItem.male)
        player:addOutfitAddon(useItem.male, useItem.addon)
    end

    player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    item:remove()

    return true

end

addons:id(40869)
addons:register()
 
Last edited:
Solution
A little more arranged the script:

Lua:
local outfits = {
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE}
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local outfit = outfits[item:getId()]
    if not outfit then
        return true
    end

    if not player:isPremium() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You own no premium account.')
        return true
    end

    if player:hasOutfit(outfit.female, outfit.addon) and player:hasOutfit(outfit.male, outfit.addon) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already own this outfit.")
        return true
    end

    player:addOutfitAddon(outfit.female, outfit.addon)
    player:addOutfitAddon(outfit.male, outfit.addon)
    player:getPosition():sendMagicEffect(outfit.effect)
    item:remove(1)
    return true
end

for _, id in pairs(outfits) do
    action:id(id)
end
action:register()

then now all itemIds of the outfit list will be registered
 
Add in the begining of the function
Lua:
if player:hasOutfit(useItem.female) or player:hasOutfit(useItem.male) then
    return true
end

Full script edited:
Lua:
local config = {
         -- Racoon
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE},
}

local addons = Action()

function addons.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local useItem = config[item.itemid]
    if not useItem then
        return true
    end

    if not player:isPremium() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You own no premium account.')
        return true
    end

    if player:hasOutfit(useItem.female) or player:hasOutfit(useItem.male) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You already own this outfit part.')
        return true
    end

    if player:getSex() == PLAYERSEX_FEMALE then
        player:addOutfit(useItem.female)
        player:addOutfitAddon(useItem.female, useItem.addon)
    else
        player:addOutfit(useItem.male)
        player:addOutfitAddon(useItem.male, useItem.addon)
    end

    player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    item:remove()

    return true

end

addons:id(40869)
addons:register()
Thanks =)
Post automatically merged:

A little more arranged the script:

Lua:
local outfits = {
    [40869] = {female = 1372, male = 1371, addon = 3, effect = CONST_ME_GIANTICE}
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local outfit = outfits[item:getId()]
    if not outfit then
        return true
    end

    if not player:isPremium() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You own no premium account.')
        return true
    end

    if player:hasOutfit(outfit.female, outfit.addon) and player:hasOutfit(outfit.male, outfit.addon) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already own this outfit.")
        return true
    end

    player:addOutfitAddon(outfit.female, outfit.addon)
    player:addOutfitAddon(outfit.male, outfit.addon)
    player:getPosition():sendMagicEffect(outfit.effect)
    item:remove(1)
    return true
end

for _, id in pairs(outfits) do
    action:id(id)
end
action:register()

then now all itemIds of the outfit list will be registered
It get error code cause of duplicate id 0 it says in console
 
Back
Top