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 »

Why does having 'return false' in the onInsertItem hook of a surface component, not seem to prevent the item being placed on the surface? (As it would have done in an LoG1 alcove's hook of the same kind.)

I was about to suggest to THOM [above], that he define a hooked alcove to either use as the only one that accepts 'essence_air' items, or to use for those few alcoves that refuse them ~but it didn't work. :shock:

It was only odd whimsy that I bothered to even check that in the editor; it being all but a given by this point; or so I had thought.
I confirmed that the hook was being run, and that the return of false did not stop me from placing the item on the surface.
This functionality is changed?
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Ask a simple question, get a simple answer

Post by GoldenShadowGS »

I think it only works on sockets, nor surfaces. I am trying to find a workaround.

EDIT:

Paste the following code into your objects.lua in your mod's script folder

Code: Select all

defineObject{
	name = "custom_dungeon_alcove",
	replacesWall = true,
	placement = "wall",
	editorIcon = 8,
	components = {
		{
			class = "Model",
			model = "assets/models/env/dungeon_wall_alcove.fbx",
			staticShadow = true,
		},
		{
			class = "Occluder",
			model = "assets/models/env/dungeon_wall_alcove_occluder.fbx",
		},
		{
			class = "Socket",
			offset = vec(0, 0.85, 0.2),
			size = vec(1.3, 0.65),
			onAcceptItem = function(self, item)
				print(item.go.name)
				if item.go.name == "essence_air" then
					--print("This item can not be placed here.")
					return false
				else
					return true
				end
			end,
		},
		{
			class = "Clickable",
			offset = vec(0, 0.85+0.4, 0.2),
			size = vec(1.3, 0.8, 0.65),
		},
	},
}
This changed the surface of the alcove to a socket. The downside is only one object can be placed in it at a time, you will have to do some scripting to deal with it. But the good side if whatever items you define in the OnAcceptItem function will never go into it.
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 »

I finally found it!

Funny thing is: I did it by try and error and at the end I do not really know, what I am doing :lol:

But it works. If you put an air-essence into the alcove it is emediatly destroyed and respawned in the mouse:

Code: Select all

function surfaceContains(surface, item)
   for _,i in surface:contents() do
      	if i.go.name == item then return true 
		end
   end
end



function keepEssence()

	if	surfaceContains(castle_alcove_key.surface, "essence_air")
		then
			timer_setMouseEssence.timer:enable() -- timer just delays recreation
			--print("timer")
	end	
end

function setMouse()      -- called by timer
   if	surfaceContains(castle_alcove_key.surface, "essence_air") then
		for _,i in castle_alcove_key.surface:contents() do
					if i.go.name == "essence_air" then
			         	i.go:destroy()
 						--print("destroy")
					end
       	       end
               setMouseItem(spawn("essence_air",nil,nil,nil,nil,nil).item)
               --print("create")
   end
end

THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
rlewarne04
Posts: 13
Joined: Wed Feb 04, 2015 9:05 pm

Re: Ask a simple question, get a simple answer

Post by rlewarne04 »

Hey guys :)

This is my first post anywhere, ever, so if I do it wrong, apologies.

I've looked everywhere and I cant seem to find a script that will allow me to change the damage type of a weapon without using either Clone Object or Define object and I was wondering how you'd do that?

My current script looks like this:

local freeze_blade = spawn("long_sword")
freeze_blade.item:setDescription("A blade of ice")
freeze_blade.meleeattack:setAttackPower(50)
freeze_blade.meleeattack:setAccuracy(30)
freeze_blade.meleeattack:setBaseDamageStat("strength")
freeze_blade.meleeattack:setDamage("cold")
freeze_blade.meleeattack:setCooldown(1)
freeze_blade.item:setUiName("Freeze Blade")

Can you tell me what I'm doing wrong? Thanks in advance.
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 »

Welcome !

It seems you wanted this function : MeleeAttackComponent:setDamageType(string) instead of setDamage.

You can check here : http://www.grimrock.net/modding/scripti ... kComponent
rlewarne04
Posts: 13
Joined: Wed Feb 04, 2015 9:05 pm

Re: Ask a simple question, get a simple answer

Post by rlewarne04 »

Thank you so much! I must have missed it in my haste to get things done. It works fine now.

YOu wouldn't happen to know off hand what type of attack fire arms are would you? If not I'll look through the reference section :)
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

FirearmAttackComponent
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.
rlewarne04
Posts: 13
Joined: Wed Feb 04, 2015 9:05 pm

Re: Ask a simple question, get a simple answer

Post by rlewarne04 »

I found it but thank you very much for telling me. I'm looking for firearms to scale with DEX but it would appear you cant do that? I'll look into it further. Thank you :)
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Just set the baseDamageStat field to "dexterity" in the component definition. I assume you are also supposed to be able to change the base stat dynamically with FirearmAttackComponent:setBaseDamageStat() but that method is broken as it only accepts numbers (which are not stats and will just cause an error when the item is added to inventory).
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.
rlewarne04
Posts: 13
Joined: Wed Feb 04, 2015 9:05 pm

Re: Ask a simple question, get a simple answer

Post by rlewarne04 »

Yes exactly that. It wont allow me to put in Dexterity, stating that it expected a number and not a string, and adding a number only causes a crash so I imagine they don't want firearms scaling lol
Post Reply