• 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 Add storage to use

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
201
Reaction score
15
Hello, can someone help me with this script that I was doing but I want you to only be able to use these items if you have this storage

Storage: 69812
i used otbr tfs 1.3


Lua:
local addcustom1 = Action()

function addcustom1.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getStorageValue(9240) == 1 then
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You have already used it.")
        return true
    end
    
  Item(item.uid):remove(1)
  player:removeItem(38911, 1)
  player:addOutfitAddon(1323, 1)
  player:addOutfitAddon(1322, 1)
  player:setStorageValue(9240, 1)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")

      player:getPosition():sendMagicEffect(75)
      
    return true
end
addcustom1:id(38911)
addcustom1:register()
 
Solution
Thanks for the help but none have worked for me, I think I did not explain well ..

These items should be used only if you have storage 69812, this storage gives it to you when killing the boss, because if the script does not ask for storage, any player level 8 can obtain this outfit simply by clicking on the items.

I want to avoid that low level players can use it, that they can only use these items having the storage 69812
Lua:
local config = {
    itemId = 38911,
    requiredStorage = 69812,
    addons = 1,
    lookTypes = {
        [PLAYERSEX_FEMALE] = 1323, -- Revenant female
        [PLAYERSEX_MALE] = 1322 -- Revenant male
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if...
Somerhing like this
Lua:
local addcustom1 = Action()

function addcustom1.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(69812) == -1 then
        return true
       
    elseif player:getStorageValue(9240) == 1 then
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You have already used it.")
        return true
    end
   
  Item(item.uid):remove(1)
  player:removeItem(38911, 1)
  player:addOutfitAddon(1323, 1)
  player:addOutfitAddon(1322, 1)
  player:setStorageValue(9240, 1)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")

      player:getPosition():sendMagicEffect(75)
     
    return true
end
addcustom1:id(38911)
addcustom1:register()
 
Last edited:
Lua:
    if player:getStorageValue(69812) > 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can't use it.")
        return true
    end
 
Hello, can someone help me with this script that I was doing but I want you to only be able to use these items if you have this storage

Storage: 69812
i used otbr tfs 1.3


Lua:
local addcustom1 = Action()

function addcustom1.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getStorageValue(9240) == 1 then
        doPlayerSendTextMessage(player, MESSAGE_EVENT_ADVANCE, "You have already used it.")
        return true
    end
  
  Item(item.uid):remove(1)
  player:removeItem(38911, 1)
  player:addOutfitAddon(1323, 1)
  player:addOutfitAddon(1322, 1)
  player:setStorageValue(9240, 1)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")

      player:getPosition():sendMagicEffect(75)
    
    return true
end
addcustom1:id(38911)
addcustom1:register()
To make it easier to edit it for other outfits.
data/scripts/example.lua
Lua:
local config = {
    itemId = 38911,
    storage = 69812,
    addons = 1,
    lookTypes = {
        [PLAYERSEX_FEMALE] = 1323, -- Revenant female
        [PLAYERSEX_MALE] = 1322 -- Revenant male
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have already used it.")
        return true
    end

    player:addOutfitAddon(config.lookTypes[PLAYERSEX_FEMALE], config.addons)
    player:addOutfitAddon(config.lookTypes[PLAYERSEX_MALE], config.addons)
    player:setStorageValue(config.storage, 1)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")
    player:getPosition():sendMagicEffect(75)
    item:remove(1)
    return true
end

action:id(config.itemId)
action:register()
 
Thanks for the help but none have worked for me, I think I did not explain well ..

These items should be used only if you have storage 69812, this storage gives it to you when killing the boss, because if the script does not ask for storage, any player level 8 can obtain this outfit simply by clicking on the items.

I want to avoid that low level players can use it, that they can only use these items having the storage 69812
 
With this script, you can now define a boss, and when the player kills the boss, it grants them a storage, so after eliminating the boss for the first time, then the player can already use the item and claim their outfit
Lua:
local config = {
    itemId = 38911,
    storage = 69812,
    addons = 1,
    lookTypes = {
        [PLAYERSEX_FEMALE] = 1323, -- Revenant female
        [PLAYERSEX_MALE] = 1322 -- Revenant male
    },
    bossName = "Demon"
}

local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local storage = player:getStorageValue(config.storage)
    if storage == -1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You must kill the %s boss in order to use this item.", config.bossName))
    elseif storage == 1 then
        player:addOutfitAddon(config.lookTypes[PLAYERSEX_FEMALE], config.addons)
        player:addOutfitAddon(config.lookTypes[PLAYERSEX_MALE], config.addons)
        player:setStorageValue(config.storage, 2)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")
        player:getPosition():sendMagicEffect(75)
        item:remove(1)
       elseif storage == 2 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have already used it.")
    end
    return true
end
action:id(config.itemId)
action:register()

local bossEventName = string.format("RewardOutfitBoss%s", config.bossName)
local creatureEvent = CreatureEvent(bossEventName)
function creatureEvent.onKill(player, target)
    if target:getName() == config.bossName then
        player:setStorageValue(config.storage, 1)
        player:unregisterEvent("BossDeath0001")
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You can now use %s to claim a outfit.", ItemType(config.itemId):getName()))
    end
    return true
end
creatureEvent:register()

local creatureEvent = CreatureEvent(string.format("RewardOutfitLogin%s", config.bossName))
function creatureEvent.onLogin(player)
    if player:getStorageValue(config.storage) == -1 then
        player:registerEvent(bossEventName)
    end
    return true
end
creatureEvent:register()
 
Thanks for the help but none have worked for me, I think I did not explain well ..

These items should be used only if you have storage 69812, this storage gives it to you when killing the boss, because if the script does not ask for storage, any player level 8 can obtain this outfit simply by clicking on the items.

I want to avoid that low level players can use it, that they can only use these items having the storage 69812
Lua:
local config = {
    itemId = 38911,
    requiredStorage = 69812,
    addons = 1,
    lookTypes = {
        [PLAYERSEX_FEMALE] = 1323, -- Revenant female
        [PLAYERSEX_MALE] = 1322 -- Revenant male
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.requiredStorage) == -1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have not completed a required quest to use this item.")
        return true
    end
   
    if player:hasOutfit(config.lookTypes[PLAYERSEX_FEMALE], config.addons) and player:hasOutfit(config.lookTypes[PLAYERSEX_MALE], config.addons) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have already obtained this addon.")
        return true
    end
   
    player:addOutfitAddon(config.lookTypes[PLAYERSEX_FEMALE], config.addons)
    player:addOutfitAddon(config.lookTypes[PLAYERSEX_MALE], config.addons)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")
    player:getPosition():sendMagicEffect(75)
    item:remove(1)
    return true
end

action:id(config.itemId)
action:register()
 
Solution
Lua:
local config = {
    itemId = 38911
    requiredStorage = 69812,
    addons = 1,
    lookTypes = {
        [PLAYERSEX_FEMALE] = 1323, -- Revenant female
        [PLAYERSEX_MALE] = 1322 -- Revenant male
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.requiredStorage) == -1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have not completed a required quest to use this item.")
        return true
    end
   
    if player:hasOutfit(config.lookTypes[PLAYERSEX_FEMALE], config.addons) and player:hasOutfit(config.lookTypes[PLAYERSEX_MALE], config.addons) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have already obtained this addon.")
        return true
    end
   
    player:addOutfitAddon(config.lookTypes[PLAYERSEX_FEMALE], config.addons)
    player:addOutfitAddon(config.lookTypes[PLAYERSEX_MALE], config.addons)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Obtained first addon Revenant.")
    player:getPosition():sendMagicEffect(75)
    item:remove(1)
    return true
end

action:id(config.itemId)
action:register()
Perfect, thank you all, the only thing missing is the comma in the itemid

Lua:
itemId = 38911
 
Back
Top