Page 42 of 400

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 30, 2015 11:48 pm
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?

Re: Ask a simple question, get a simple answer

Posted: Sat Jan 31, 2015 1:00 am
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.

Re: Ask a simple question, get a simple answer

Posted: Mon Feb 02, 2015 2:47 pm
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


Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 9:14 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 9:36 pm
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

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 9:57 pm
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 :)

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 10:01 pm
by minmay
FirearmAttackComponent

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 10:15 pm
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 :)

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 10:19 pm
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).

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 04, 2015 10:22 pm
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