How to check Storage in movevent event="AddItem"

Discussion in 'Support' started by lucastiond, Jan 11, 2017.

  1. lucastiond

    lucastiond New Member

    Joined:
    Jul 14, 2013
    Messages:
    25
    Hello guys.

    I would like to know how can I check if a player have one storage value in an onAddItem function.
    I'm using tfs 1.2

    My script is like this:

    Code:
    local trees = {Position(33205, 32537, 6)}
    
    function onAddItem(moveitem, tileitem, position)
        if moveitem.itemid ~= 2419 then
            return true
        end
    
    
        for i = 1, #trees do
            local scimitarItem = Tile(trees):getItemById(2419)
            local scimitarItem2 = Tile(trees):getItemById(5858)
    
            if not scimitarItem2 and Game.getStorageValue(46140) == 1 then
                Game.createItem(5858, 1, Position(33205, 32537, 6))
                trees:sendMagicEffect(CONST_ME_MAGIC_BLUE)
                scimitarItem:remove()
            end
        end
        return true
    end
    

    The problem is that i can't get this "getStorageValue" function to work.

    Thanks for your time.
     
    Last edited by a moderator: Jan 11, 2017
  2. Xeraphus

    Xeraphus the best

    Joined:
    Feb 14, 2015
    Messages:
    1,726
    where are you even using this script?
    in 1.2 the moveitem script should be in events/scripts/player.lua (@Player : onMoveItem)
    to check storage value there, use the keyword self since that's the object of the method (Player)
    self:getStorageValue
     
  3. Flatlander

    Flatlander Species Developer

    Joined:
    Feb 17, 2009
    Messages:
    2,253
    I think he wants to check a global storage value. (If I am understanding him correctly)
     
  4. Xeraphus

    Xeraphus the best

    Joined:
    Feb 14, 2015
    Messages:
    1,726
    oh oops i didnt even read the code, probably should have

    Game.getStorageValue(key)
    Game.setStorageValue(key, value)

    it should work if you set the same key to value 1 and get it afterwards
     
  5. lucastiond

    lucastiond New Member

    Joined:
    Jul 14, 2013
    Messages:
    25
    I did what you are suggesting Xeraphus, but it doesn't work.

    I checked if Game.getStorageValue(46140) == 1 , but nothing happens. When I test it in the game, i am able to do the script without the storage.

    What I am trying to do, as the script suggests, is to create the item with id 5858 on the given position when i put a scimitar on the tile. I am able to do that, but not checking the player storageValue.
     
  6. Xeraphus

    Xeraphus the best

    Joined:
    Feb 14, 2015
    Messages:
    1,726
    so wait are you trying to use player storage value or global?
    confused
     
  7. Beto06

    Beto06 Well-Known Member

    Joined:
    Jun 18, 2011
    Messages:
    694
    Just change
    Game.getStorageValue(46140) == 1
    to
    self:getStorageValue(46140) == 1 as Xeraphus said?
     
  8. lucastiond

    lucastiond New Member

    Joined:
    Jul 14, 2013
    Messages:
    25
    I want to check the player storage value. I thought that if i used the "game." function it would work, but I was wrong.

    I tried to do that @Beto06 but i get this error: attempt to index global 'self' (a nil value).

    I am trying to do this at movements scripts, so i am using function onAddItem(moveitem, tileitem, position)
     
  9. Xeraphus

    Xeraphus the best

    Joined:
    Feb 14, 2015
    Messages:
    1,726
    if you're wanting to check player storage value, use the method i said in the first post i made
     

Share This Page