getMouseItem

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

getMouseItem

Post 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.
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: getMouseItem

Post 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
        }
    }
}
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: getMouseItem

Post 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?
Last edited by RayB on Wed Feb 28, 2018 10:28 pm, edited 1 time in total.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: getMouseItem

Post 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.
My asset pack [v1.10]
Features a bit of everything! :D
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: getMouseItem

Post by RayB »

Thanks again!
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: getMouseItem

Post 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.
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: getMouseItem

Post 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()
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: getMouseItem

Post 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.
Post Reply