LUA Script to access dropped item name

  • #1, z OrlixWednesday, 08. June 2016, 18:27 hodinky 9 years ago
    Hi,

    Is there any LUA script to access the name of a dropped item object? Or even the object himself?

    Thanks
    Orlix

    Bažant

    20 Posts


  • #2, z sebastianWednesday, 08. June 2016, 18:33 hodinky 9 years ago
    do you mean the item which got dragged or the object the item was dropped to?

    Kapitán

    2346 Posts

  • #3, z OrlixWednesday, 08. June 2016, 18:40 hodinky 9 years ago
    Yes, the item which got dragged.

    Bažant

    20 Posts

  • #4, z sebastianWednesday, 08. June 2016, 18:47 hodinky 9 years ago
    game.UsedItem
    

    contains the currently used (dragged) item .
    You could do stuff with it like this:

    local itm = nil
    if not game.UsedItem:isEmpty() then
      if game.UsedItem:getName() ~= itm then
        itm = game.UsedItem:getName(); 
    -- put lua stuff here when there is an item 
    
      end
     elseif game.UsedItem:isEmpty() and itm ~= nil then
     itm = nil; 
    -- put lua stuff here when there is no item 
    
     end
    

    Kapitán

    2346 Posts

  • #5, z afrlmeWednesday, 08. June 2016, 19:04 hodinky 9 years ago
    You don't have to do everything with pure Lua script either. You can mix & match... so create your query with Lua & then you can call a "called by other action" you created in the editor. It depends on the situation, as not everything is accessible via Lua script at the minute.

    Imperátor

    7285 Posts

  • #6, z OrlixWednesday, 08. June 2016, 19:46 hodinky 9 years ago
    Thanks mates,

    But for some reason the script

    game.UsedItem
    


    is returning nil. I have no idea why. I have the "Object name" set in both scenes and in Item menu. but when i drag the object, he appears normally but that variable don´t. I have inserted a print to figure what value is coming in that variable but nothing is there roll

    Why i keep trying to do this with LUA?
    Well, the idea is to move the dragged object, from the object where it will be dragged (the table) to a specific location in the scene after the drag action using the move object function AFRLme create here:

    https://wiki.visionaire-tracker.net/wiki/MoveObj_(CMS)

    The reason i need to do this is because i don´t know what object will be dragged, could be one of the 20 about items i have, so i need to get the object name in runtime and move the object by script.


    Bažant

    20 Posts

  • #7, z afrlmeWednesday, 08. June 2016, 19:55 hodinky 9 years ago
    game.UsedItem should be the currently held item (from your inventory) whether it's dragged (display item as cursor) or manually set with the set item action part.

    Are you dragging it to something in the scene or another inventory slot?

    If nothing is held then it will return nil. If something is held then it should return the object & id. You can also ammend :getName() at the end of it, but that only returns the name of the held object or nil.

    By the way I see you are using a tail app for your message, is it any good? I use an open source one called SnakeTail, which does the trick.

    Quick question: just re-read what you wrote. You want to drag move the scene object without placing it in your inventory first? That should be possible with the moveObj function, which will also move the object polygon & interaction position along with it. However I'm not keen on that function as it works based on offset from the default position. The best thing to do is place the object at 0,0 to begin with & then use Lua to reposition it, then you can simply tell it to move to object position + mouse cursor position or a position you specified in some values.

    Imperátor

    7285 Posts

  • #8, z OrlixWednesday, 08. June 2016, 20:28 hodinky 9 years ago
    Well the idea is to drop an item from hero inventory to the table, then move object to position above other image (to simulate the other character inventory).

    You can see what i´m trying to do in the follow video:
    http://screencast.com/t/htoiqXotm

    Actions applied to table object are in the screenshot below (ss2.png).

    The difference to what you saw, is that i don´t want to use the "Move object" action on table because i don´t know what object will be dragged, and the idea is to call a script that process this movement getting the dragged object.

    As you can see in the "Item dropped" execution type, i have a simple script just to print the object name

    print(game.UsedItem:getName())
    


    This script is the first action to be called, and the value is empty.

    Are you dragging it to something in the scene or another inventory slot?

    I´m dragging to another object in the scene (the table).


    By the way I see you are using a tail app for your message, is it any good?

    Yes, this is Bare Tail Pro which is a payed version provided by the company where i work, but you also have a free version or a demo trial of pro version if you are willing to test.

    You want to drag move the scene object without placing it in your inventory first?

    No, i wan´t to me the scene object from the inventory.

    Thanks mate.

    Bažant

    20 Posts

  • #9, z afrlmeWednesday, 08. June 2016, 20:50 hodinky 9 years ago
    Sorry... usually when you drop an item on a object & it returns successful it clears the object from your hand instantly before executing the actions. At least it does if I remember correctly - I don't use dragged item option myself as I prefer using custom created mouse cursors for each item.

    Besides the name it seems to be working more or less, no? Not sure what's up with the crazy character position jump though. grin

    Imperátor

    7285 Posts

  • #10, z sebastianWednesday, 08. June 2016, 20:54 hodinky 9 years ago
    I guess because you dropped the item already on the object, the game:UsedItem is nil when you print it to the console.

    Kapitán

    2346 Posts

  • #11, z sebastianWednesday, 08. June 2016, 21:01 hodinky 9 years ago
    Alrighty tighty lets get this done...
    Did i understand it right that it could be any item which can be dropped on the table or is only this bread successfull placeable?
    Must the moving from the placed item to this second inventory be animated or was it just to visualize where it should go?

    Kapitán

    2346 Posts