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: 119
Joined: Fri Mar 06, 2015 3:45 am

getMouseItem

Post by RayB » Wed Feb 28, 2018 9:23 pm

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.

Zo Kath Ra
Posts: 864
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: getMouseItem

Post by Zo Kath Ra » Wed Feb 28, 2018 9:35 pm

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: 119
Joined: Fri Mar 06, 2015 3:45 am

Re: getMouseItem

Post by RayB » Wed Feb 28, 2018 10:03 pm

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 » Wed Feb 28, 2018 10:24 pm

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: 119
Joined: Fri Mar 06, 2015 3:45 am

Re: getMouseItem

Post by RayB » Wed Feb 28, 2018 10:31 pm

Thanks again!

User avatar
Isaac
Posts: 2995
Joined: Fri Mar 02, 2012 10:02 pm

Re: getMouseItem

Post by Isaac » Wed Feb 28, 2018 10:32 pm

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.

Zo Kath Ra
Posts: 864
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: getMouseItem

Post by Zo Kath Ra » Wed Feb 28, 2018 11:04 pm

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: 2995
Joined: Fri Mar 02, 2012 10:02 pm

Re: getMouseItem

Post by Isaac » Thu Mar 01, 2018 1:04 am

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