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

TFS 1.X+ Use item with uid x set storage id x

Raikou

Active Member
Joined
Jul 18, 2007
Messages
101
Solutions
2
Reaction score
33
I'm trying to do something simple, so at least i think. But can't get it to work.
I have an item(book) with uid 6600, as soon as a player reads(use) it player.storage 6600 needs to be set.

I thought I could do this with actionid 15000 (the standard reward box thing) but then I can't use the book anymore.
 
Solution
Try
actions/actions.xml
XML:
<action itemid="ITEM ID GOES HERE" script="myBook.lua"/>

actions/scripts/myBook.lua
Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    if not player then
        return true
    end
    
    if player:getStorageValue(6600) ~= 1 then
        player:setStorageValue(6600, 1)
    end
    
    return true
end

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
399
Solutions
18
Reaction score
71
Try
actions/actions.xml
XML:
<action itemid="ITEM ID GOES HERE" script="myBook.lua"/>

actions/scripts/myBook.lua
Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    if not player then
        return true
    end
    
    if player:getStorageValue(6600) ~= 1 then
        player:setStorageValue(6600, 1)
    end
    
    return true
end
 
Solution
OP
OP
R

Raikou

Active Member
Joined
Jul 18, 2007
Messages
101
Solutions
2
Reaction score
33
Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    if not player then
        return true
    end
    
    if player:getStorageValue(item.uid) ~= 1 then
        player:setStorageValue(item.uid, 1)
    end
    
    return true
end

I turned it a bit so it will be multi usable. But yes your code works. :)
 
Top