Page 1 of 1
getMouseItem
Posted: Wed Feb 28, 2018 9:23 pm
by RayB
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.
Re: getMouseItem
Posted: Wed Feb 28, 2018 9:35 pm
by Zo Kath Ra
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
Posted: Wed Feb 28, 2018 10:03 pm
by RayB
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?
Re: getMouseItem
Posted: Wed Feb 28, 2018 10:24 pm
by zimberzimber
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?
Exactly what Zo Kath Ra posted
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.
Re: getMouseItem
Posted: Wed Feb 28, 2018 10:31 pm
by RayB
Thanks again!
Re: getMouseItem
Posted: Wed Feb 28, 2018 10:32 pm
by Isaac
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?
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.
Re: getMouseItem
Posted: Wed Feb 28, 2018 11:04 pm
by Zo Kath Ra
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?
If you don't want to use a definition, you can instead put this code in a script entity:
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
Posted: Thu Mar 01, 2018 1:04 am
by Isaac
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.