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

Does not add item to player TFS 1.3

Marko999x

999x era
Premium User
Joined
Dec 14, 2017
Messages
2,854
Solutions
82
Reaction score
1,956
Location
Germany
heyo
as the title says
people does not get the item for some reason
I do not have any errors + I tried to fix it by myself but at this point im kinda lost now
what im doing wrong?
a explain would be awesome what I did wrong ( Trying to learn )
Script:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52003) == -1 then
        player:setStorageValue(52003, 1)
        elseif
        player:getVocation() == 1 then
        player:addItem(7958, 1)
        elseif
        player:getVocation() == 2 then
        player:addItem(2184, 1)
        elseif
        player:getVocation() == 3 then
        player:addItem(7438, 1)
        elseif
        player:getVocation() == 4 then
        player:addItem(2451, 1)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You alredy got your reward.')
        player:getPosition():sendMagicEffect(3)
    end
    return true
end
 
Solution
pls dont write it like that
Lua:
local rewards = {
    [1] = 7958,
    [2] = 2184,
    [3] = 7438,
    [4] = 2451
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52003) == -1 then
        local reward = rewards[player:getVocation():getId()]
        if reward then
            player:setStorageValue(52003, 1)
            player:addItem(reward, 1)
        else
            print(debug.traceback('Reward not found'))
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You already got your reward.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
Try this one, Also wrong section.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52003) == -1 then
        player:setStorageValue(52003, 1)
        elseif
        player:getVocation():getID() == 1 then
        player:addItem(7958, 1)
        elseif
        player:getVocation():getID() == 2 then
        player:addItem(2184, 1)
        elseif
        player:getVocation():getID() == 3 then
        player:addItem(7438, 1)
        elseif
        player:getVocation():getID() == 4 then
        player:addItem(2451, 1)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You alredy got your reward.')
        player:getPosition():sendMagicEffect(3)
    end
    return true
end
 
pls dont write it like that
Lua:
local rewards = {
    [1] = 7958,
    [2] = 2184,
    [3] = 7438,
    [4] = 2451
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52003) == -1 then
        local reward = rewards[player:getVocation():getId()]
        if reward then
            player:setStorageValue(52003, 1)
            player:addItem(reward, 1)
        else
            print(debug.traceback('Reward not found'))
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You already got your reward.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
 
Solution
pls dont write it like that
Lua:
local rewards = {
    [1] = 7958,
    [2] = 2184,
    [3] = 7438,
    [4] = 2451
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(52003) == -1 then
        local reward = rewards[player:getVocation():getId()]
        if reward then
            player:setStorageValue(52003, 1)
            player:addItem(reward, 1)
        else
            print(debug.traceback('Reward not found'))
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You already got your reward.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
The script is fine, but won't be missing the reward, if a player has promotion?
 
Back
Top