I can get the mouse item alright if I put getMouseItem() into a function and call it with a button or pressure plate (after picking the item up, of course).
Is there any way I can trigger the call to the function by picking up the item?
What I am trying to do (for testing) is to pick up an item and have its name and id print to the screen.
getMouseItem
- Zo Kath Ra
- Posts: 931
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: getMouseItem
Put this into one of your script files, like "init.lua":
Code: Select all
defineObject{
name = "party",
baseObject = "party",
components = {
{
class = "Party",
onPickUpItem = function (self, item)
hudPrint("item name = " .. item:getUiName() .. " / item id = " .. item.go.id)
end
}
}
}
Re: getMouseItem
Thanks, works great!
But, looking at the following in the scripting reference:
PartyComponent.onPickUpItem(self, item)
I thought it might be able to be used in a dungeon script. Is the above confined to a definition?
But, looking at the following in the scripting reference:
PartyComponent.onPickUpItem(self, item)
I thought it might be able to be used in a dungeon script. Is the above confined to a definition?
Last edited by RayB on Wed Feb 28, 2018 10:28 pm, edited 1 time in total.
- zimberzimber
- Posts: 432
- Joined: Fri Feb 08, 2013 8:06 pm
Re: getMouseItem
Exactly what Zo Kath Ra postedRayB wrote:Thanks, works great! But, out of curiosity, what on earth would one do with the party component:
PartyComponent.onPickUpItem(self, item)
What is it used for and how would you use it?
As for usefulness, there are a lot of things you can do with it
Like if its a coin and you store coins outside of the inventory as a value somewhere, you could have the on pick up read that its a coin, remove it from the cursor, and increment the value.
My asset pack [v1.10]
Features a bit of everything!
Features a bit of everything!
Re: getMouseItem
It's a hook that triggers every time the player picks up an item. That means the script can inspect that item before the party gets it, alter it, or even nullify the attempt to pick it up.RayB wrote:Thanks, works great! But, out of curiosity, what on earth would one do with the party component:
PartyComponent.onPickUpItem(self, item)
What is it used for and how would you use it?
- Zo Kath Ra
- Posts: 931
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: getMouseItem
If you don't want to use a definition, you can instead put this code in a script entity:RayB wrote:Thanks, works great!
But, looking at the following in the scripting reference:
PartyComponent.onPickUpItem(self, item)
I thought it might be able to be used in a dungeon script. Is the above confined to a definition?
Code: Select all
function test()
party.party:addConnector("onPickUpItem", self.go.id, "pickup")
end
function pickup(self, item)
hudPrint("item name = " .. item:getUiName() .. " / item id = " .. item.go.id)
end
test()
Re: getMouseItem
With the caveat that the hooked action cannot be canceled, as it can in a definition.
It is also possible to call the script_entity from the defined hook, and pass along its arguments; even to return false based on the called script_entity.
It is also possible to call the script_entity from the defined hook, and pass along its arguments; even to return false based on the called script_entity.