Ask a simple question, get a simple answer

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!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

AndakRainor wrote:Is there any way to deactivate the throwing of mouse item ? I made a small window where I would like to drag and drop items, but when I click on it the mouse item is thrown.
How did you make the window?

Here is a simple option that restricts throwing, but not dropping; and calls a function when clicked.
SpoilerShow

Code: Select all

useTrigger = true     --auto-spawns a connected floor_trigger on the tile
windowActive = false  

function click_action(bool)
		if bool then
	--_________________________  Change script to suit
		
			local item = getMouseItem()
			if item then
				hudPrint("You clicked the window with a "..item.go.name..".")
			end
	--_________________________
		end	
end

_createWindow = function(context)
				if not context.mouseDown(2) and party.facing == self.go.facing 
				and party.x == self.go.x and party.y == self.go.y
				and party.elevation == self.go.elevation  --can be commented out
				then
						local dir, result = context.button(self.go.id.."window", 0, 0, context.width, context.height * .6)
						if result then
						 click_action(context.mouseDown(3))
						end
				end
			end	

function _setWindowActive(bool)
	windowActive = bool
	print(bool)
end

function activate()
	windowActive = true
end

function deactivate()
	windowActive = false
end

function toggleWindowActive()
	windowActive = not windowActive
end

if useTrigger then
	self.go:spawn('floor_trigger').floortrigger:addConnector('onToggle', self.go.id, "toggleWindowActive")
end

Code: Select all

defineObject{
	name = "party",
	components = {
		{
			class = "Party",
			onMove = function(self, dir)  end,
			onDrawGui = function(self, context) window2.script.createWindow(context) end,
		},
		{
			class = "Light",
			name = "torch",
			range = 12,
		},
	},
	editorIcon = 32,
	placement = "floor",
}
To use this, define onDrawGui (in a party definition, in objects.lua) to call the _createWindow function in the script_entity.
Then position and face the script _entity to indicate the tile and direction where the window is. Activate the effect
either via script using one of the setter functions, or via the built in trigger/plate (which is automatically spawned by default).
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

I use the onDrawInventory of the party to draw this panel. It is a panel I use to craft potions, similar to the mortar menu of grimrock 1, next to the inventory instead of over the hands of the champion.

I don't use context.button in my code but context.drawGuiItem2 and context.drawImage2. Is it this function that restricts throwing in your example ?
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

The script makes an invisible button that covers the upper half of the screen, and intercepts clicks that are on the button. The button covers the area where the engine detects left clicks to initiate throwing a weapon.

Also... I've found a far simpler (and better) way to do this. 8-)

Just define this object and place it.

Code: Select all

defineObject{
	name = "click_region",
	baseObject = "base_wall_decoration",
	components = {
		{
			class = "Clickable",
			offset = vec(0, 2.2, -1),
			size = vec(3, 3, .5),
			--debugDraw = true,
			onClick = function(self)
						local click_actions = findEntity("click_actions")
						local item = getMouseItem()
						if click_actions and click_actions.script[self.go.id] then
							click_actions.script[self.go.id]()
						elseif item then  
							hudPrint("You clicked the window with a "..item.go.name..".")
						end
					end
		},
	}
}
Change the onClick event to suit; or you can add a script_entity with the id 'click_actions', and with a function in it of the same name as your click_region object's id.

Example: place a "click_region_2" object, and add a script_entity named "click_actions"...

Code: Select all

--script name is click_actions
click_region_2 = function()
					playSound("secret")
					local item = getMouseItem()
					if item then							
						hudPrint("You clicked the window with a "..item.go.name..".")
					end
				end
You can place as many click_region objects as you like, and when clicked, they will each check the click_actions script for their own function to execute.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Is there a way to get the gfxIndexArmorSet value of an item ? I don't see the function for it in the scripting reference.
User avatar
TZO2k12
Posts: 50
Joined: Mon Apr 02, 2012 6:19 am

Re: Ask a simple question, get a simple answer

Post by TZO2k12 »

I've been hunting forever for a simple keyboard command ,list, specifically how do you duplicate an asset? :lol:
Assumptions are the practical logic of the ignorant.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

You mean the editor? Did you had a look at file/preferences? You can change the key-commands.

To duplicate an object just use ctrl-c and ctrl-v... The new object will lie over the old one, but it is selected and you can move it by using the arrow-keys... :mrgreen:
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: Ask a simple question, get a simple answer

Post by FeMaiden »

ignore me...i just had to comment on the irony. this thread is titled "....simple question...simple answer" and half of these scripts I see are like a whole nother league above my pay grade. I haven't even begun to understand the complexity...
I haven't gotten past bossfights hudPrints and the intro to "if then else".

but the double irony is that these probably really ARE simple, to the people that wrote them.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Well, what would you prefer? People answering the questions, or people saying "no, that question isn't simple enough for this thread, go away"?
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Ask a simple question, get a simple answer

Post by Azel »

FeMaiden wrote:ignore me...i just had to comment on the irony. this thread is titled "....simple question...simple answer" and half of these scripts I see are like a whole nother league above my pay grade. I haven't even begun to understand the complexity...
I haven't gotten past bossfights hudPrints and the intro to "if then else".

but the double irony is that these probably really ARE simple, to the people that wrote them.
I suppose then that we could say that "simple" is all a matter of perspective.

On one extreme, you have people who don't know much of anything about programming nor the Asset Pack and prefer to ask before trial n error; on the other end you have people (eg, minmay) who insist that you must memorize everything about LUA and Grimrock assets before you're allowed to speak; and somewhere in the middle are those of us who fumble through the pain of learning just enough to make something that someone hopefully finds worthwhile to play for longer than an hour.

Perhaps a better name for this thread is, "simply ask a question, and get either an answer from the community or a sarcastic response from minmay."

That's the dominant theme of the near 1,000 posts in this thread. All-in-all though, it's a fun read and a worthy cause (I think) :mrgreen:
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Ask a simple question, get a simple answer

Post by Dr.Disaster »

FeMaiden wrote:ignore me...i just had to comment on the irony. this thread is titled "....simple question...simple answer" and half of these scripts I see are like a whole nother league above my pay grade. I haven't even begun to understand the complexity...
I haven't gotten past bossfights hudPrints and the intro to "if then else".

but the double irony is that these probably really ARE simple, to the people that wrote them.
Yeah the title might irritate somebody new to modding. Think of it as "if then else" thread: straight question going for a straight answer(s) without fooling around.
Post Reply