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

Item give Wings

DarkRUSH

New Member
Joined
Dec 15, 2018
Messages
21
Reaction score
2
Hello, I have a problem, I would like to get wings after using the item, I am using a script
Lua:
local config1 = {
        [9020] = {wingId = 1, name = "WING NAME"},
    }

local wings_on_click = Action()
function wings_on_click.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   

    local wings = config1[item.itemid]

    if not wings then
        return true
    end

    if not player:hasWing(wings.wingId) then
        player:addWings(wings.wingId)
        player:getPosition():sendMagicEffect(31)
        player:say("You have gained: "..wings.name..".", TALKTYPE_MONSTER_SAY)
        item:remove(1)
    else
        player:sendTextMessage(19, "You already have this wing.")
    end
    return true
end

for k,_ in pairs(config1) do
  wings_on_click:id(k)
end
wings_on_click:register()

I get an error in the console i have tfs 1.3

Code:
Lua Script Error: [Scripts Interface]
C:\Users\xxxx\OneDrive\Pulpit\forgottenserver\data\scripts\wings.lua:callback
...g\OneDrive\Pulpit\forgottenserver\data\scripts\wings.lua:15: attempt to call method 'hasWing' (a nil value)
stack traceback:
        [C]: in function 'hasWing'
        ...g\OneDrive\Pulpit\forgottenserver\data\scripts\wings.lua:15: in function <...g\OneDrive\Pulpit\forgottenserver\data\scripts\wings.lua:6>
 
I have that for mounts
You can use it
XML:
<action itemid="4848" script="mounts.lua" />
Lua:
local mountItems = {
    [4848] = 9020,
 
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageKey = mountItems[item.itemid]
    if storageKey then
        if player:getStorageValue(storageKey) ~= 1 then
            local storageValue = 1
            player:setStorageValue(storageKey, storageValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received storage " .. storageKey .. " with value " .. storageValue .. ".")
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this mount storage.")
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "This item cannot be used to receive a mount storage.")
    end
    return true
end

your script test
Lua:
local config1 = {
    [9020] = {wingId = 1, name = "WING NAME"},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config1[item.itemid]

    if not wings then
        return false
    end

    if not player:hasFlag(wings.wingId) then
        player:addFlag(wings.wingId)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:say("You have gained: "..wings.name..".", TALKTYPE_MONSTER_SAY)
        item:remove(1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this wing.")
    end
    return true
end

for k,_ in pairs(config1) do
    registerCreatureEvent(k, "onUse")
end
 
I have that for mounts
You can use it
XML:
<action itemid="4848" script="mounts.lua" />
Lua:
local mountItems = {
    [4848] = 9020,
 
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageKey = mountItems[item.itemid]
    if storageKey then
        if player:getStorageValue(storageKey) ~= 1 then
            local storageValue = 1
            player:setStorageValue(storageKey, storageValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received storage " .. storageKey .. " with value " .. storageValue .. ".")
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this mount storage.")
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "This item cannot be used to receive a mount storage.")
    end
    return true
end

your script test
Lua:
local config1 = {
    [9020] = {wingId = 1, name = "WING NAME"},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config1[item.itemid]

    if not wings then
        return false
    end

    if not player:hasFlag(wings.wingId) then
        player:addFlag(wings.wingId)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
        player:say("You have gained: "..wings.name..".", TALKTYPE_MONSTER_SAY)
        item:remove(1)
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this wing.")
    end
    return true
end

for k,_ in pairs(config1) do
    registerCreatureEvent(k, "onUse")
end
Was about to ask for mounts thanks
 
Code:
<wing id="1" clientid="905" name="Widow Queen" speed="20" StorageId="1" StorageValue="1" />
Lua:
local mountItems = {
    [9020] = 1,
 
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageKey = mountItems[item.itemid]
    if storageKey then
        if player:getStorageValue(storageKey) ~= 1 then
            local storageValue = 1
            player:setStorageValue(storageKey, storageValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received storage " .. storageKey .. " with value " .. storageValue .. ".")
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this mount storage.")
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "This item cannot be used to receive a mount storage.")
    end
    return true
end
and its not working
 
attempt to call method 'hasWing' (a nil value)

You don't have that function.
Do you even have the addWing function?
 
Lua:
local mountItems = {
    [4848] = 90501,
    [9112] = 90502
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageKey = mountItems[item.itemid]
    if storageKey then
        if player:getStorageValue(storageKey) ~= 1 then
            local storageValue = 1
            player:setStorageValue(storageKey, storageValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received storage " .. storageKey .. " with value " .. storageValue .. ".")
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this mount storage.")
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "This item cannot be used to receive a mount storage.")
    end
    return true
end
XML:
<action itemid="4848" script="mounts.lua" />
<action itemid="9112" script="mounts.lua" />
Test this without any changes
For example in mounts
<mount id="1" clientid="368" name="Widow Queen" speed="20" premium="no" />
To use id 1
storage must 90501 for mount id 10 storage must 90510
I don't know what about wings storage
 
Lua:
local mountItems = {
    [4848] = 90501,
    [9112] = 90502
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storageKey = mountItems[item.itemid]
    if storageKey then
        if player:getStorageValue(storageKey) ~= 1 then
            local storageValue = 1
            player:setStorageValue(storageKey, storageValue)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received storage " .. storageKey .. " with value " .. storageValue .. ".")
            item:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You already have this mount storage.")
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "This item cannot be used to receive a mount storage.")
    end
    return true
end
XML:
<action itemid="4848" script="mounts.lua" />
<action itemid="9112" script="mounts.lua" />
Test this without any changes

What is this script supposed to do
I can't even see a function which add the player a mount or a wing
 
What is this script supposed to do
I can't even see a function which add the player a mount or a wing
It works well in my server add storage I could change them to mounts, but I'm lazy xD
Post automatically merged:

Lua:
local config1 = {
    [9020] = {wingId = 1, name = "WING NAME"},
}

local wings_on_click = Action()
function wings_on_click.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local wings = config1[item.itemid]

    if not wings then
        return true
    end

    if item.itemid == 9020 then  -- Check the item ID here
        if not playerHasWing(player, wings.wingId) then
            -- Found the required ID and player doesn't have the wing
            player:addWings(wings.wingId)
            player:getPosition():sendMagicEffect(31)
            player:say("You have gained: "..wings.name..".", TALKTYPE_MONSTER_SAY)
            item:remove(1)
        else
            -- Player already has the wing
            player:sendTextMessage(19, "You already have this wing.")
        end
    else
        -- The used item doesn't have ID 9020
        return true
    end

    return true
end

function playerHasWing(player, wingId)
    return player:hasWings(wingId)
end

-- Register the action
for k,_ in pairs(config1) do
    wings_on_click:id(k)
end
wings_on_click:register()
 
Last edited:
Back
Top