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
Drakkan
Posts: 1317
Joined: Mon Dec 31, 2012 12:25 am

Re: Ask a simple question, get a simple answer

Post by Drakkan » Mon Nov 10, 2014 10:41 am

upping my questions:

1. I´d like to clone object forest_oak_cluster just with some offset (it will be placed outside the map -it should be done with offset parameter), please somebody help me define it.

defineObject{
name = "offset_oak",

components = {
{

offset = vec(4,0,4),
}
},
}


2. I´d like to have script which will prevent party to take out torch from torch_holder. on log1 it was

function keepTorch5(holder1)
holder1:addItem(spawn(\"torch\"))\
setMouseItem(nil)\
hudPrint(\" This is not your property ;)\")\
end")


3. Somebody figured out how to place water surface in different height than just -1 ? For example creating clone of some water object just with different height placement ?
Breath from the unpromising waters.
Eye of the Atlantis

User avatar
Matlock19
Posts: 23
Joined: Sun Nov 02, 2014 2:11 am

Re: Ask a simple question, get a simple answer

Post by Matlock19 » Mon Nov 10, 2014 10:42 am

This is a pretty dumb question but:

I know how to use the console to find the model file for each item:

print(spawn("item_name").model:getModel())

but how do I use the console to find the "gfxIndex" and "gfxAtlas" for an item? Everything I try returns a nil or some error. I'm trying to define some new keys and stuff.
QuintinStone wrote:Question: I thought I saw a thread where a defineObject block was posted for a single example of each object type; can anyone help me find it?
Seconding this. This would be incredibly helpful.

Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Ask a simple question, get a simple answer

Post by Grimfan » Mon Nov 10, 2014 12:33 pm

I'm getting to the stage of modding where I want to try harder stuff, however with that comes added levels of hair-tearing. For instance while the current script works it is horribly inefficient and wordy (just look at all those unneeded ends):

Code: Select all

function alternateSpikes()
    for i=22,28 do
	for n=29,35 do
	for d=36,42 do
	local l = findEntity("floor_spike_trap_"..i)
	local m = findEntity("floor_spike_trap_"..n)
	local p = findEntity("floor_spike_trap_"..d)
	counter_6.counter:getValue()
	if counter_6.counter:getValue() == 3 then
	l.controller:activate()
	else
	if counter_6.counter:getValue() == 2 then
	m.controller:activate()
	else
	if counter_6.counter:getValue() == 1 then
	p.controller:activate()
	else
	if counter_6.counter:getValue() == 0 then
	counter_6.counter:setValue(3)
	end
	end
end
end
end
end
end
end
How do I make this code more elegant and less wordy?

By the way, forget about the numbering of the spike traps. These are going to be changed to unique ids once the script becomes better.

User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Ask a simple question, get a simple answer

Post by Prozail » Mon Nov 10, 2014 2:24 pm

Grimfan wrote:I'm getting to the stage of modding where I want to try harder stuff, however with that comes added levels of hair-tearing. For instance while the current script works it is horribly inefficient and wordy (just look at all those unneeded ends):
I'm curious, what are you trying to do? have three spiketraps activate one by one in a loop? I don't really get the three nested for-loops.

For a 3x7 setup where you want to activate each line.. maybe something like this??
First of all name your spiketraps after their x-y position somehow like trap_0_3
Then think about the pattern you want them to activate in.
If its some kind of loop.. use a counter and modulus operator.

Code: Select all


counter = 0
function triggerPlates()
	local line = counter % 3 --gives you 0..2 depending on value of counter
	for x = 1,7 do 
		local trap = findEntity("trap_"..line.."_"..x)
		if trap then
			trap.controller:activate()
		end
	end
	counter=counter + 1
end


Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Ask a simple question, get a simple answer

Post by Grimfan » Mon Nov 10, 2014 2:50 pm

What you see above is what you get when someone learns scripting from trolling messageboards - a strange mess of cobbled together facts that sometimes works. :lol:

Thanks for the information Prozail. I will try and put it into practice. :)

Jackard
Posts: 59
Joined: Thu Oct 30, 2014 7:32 pm

Re: Ask a simple question, get a simple answer

Post by Jackard » Mon Nov 10, 2014 5:00 pm

Why does scripting refer to tga files when the files are dds extension? I picked up the dds plugin for Photoshop but there's some error when trying to open the files.

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Ask a simple question, get a simple answer

Post by NutJob » Mon Nov 10, 2014 5:04 pm

Grimfan wrote:What you see above is what you get when someone learns scripting from trolling messageboards - a strange mess of cobbled together facts that sometimes works. :lol:

Thanks for the information Prozail. I will try and put it into practice. :)
There is (or at least, was) quite a lot of misinformation, but trolling, not so much.

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Ask a simple question, get a simple answer

Post by NutJob » Mon Nov 10, 2014 7:25 pm

Is there a way to retrieve the top-level class of *any* entity?

LoG1 had this: '“class” returns the class name of the entity'

How do I get the class for an object in LoG2?

Code: Select all

function testFunction(id)
	local o = findEntity(id)
	print(o.class)
	print(o.Class)
	print(o.type)
end
Returns nil, always. "o.name" is also unhelpful because that would just mean I would have to setup a definition table.

User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Ask a simple question, get a simple answer

Post by Doridion » Mon Nov 10, 2014 9:08 pm

Aaa ...... NutJob ? When I want to know all the classes of something in the editor, i just add the item/object/etc on the map, and see names of all the classes in the object properties :D

NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Ask a simple question, get a simple answer

Post by NutJob » Mon Nov 10, 2014 9:56 pm

Yes, as do I. I want to send an ID to a function, I made, and anonymously get it's foundational class the object represents [or even better yet var_dump(anObject)]. I understand that objects can have many classes, thus, why, the field accessible in LoG1 "obj.class" is not available in LoG2. Though it would be relatively easy to implement (on their side) so long as the objects top-level defining class is first in the order (then simply assign that "Class" to the field obj.class).

Post Reply