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
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Is it possible to change the size of a 3D model via script (without creating any new model in blender) ? I just tried to use setWorldRotation with a matrix 4x4 containing a scaling factor, and did it on a tiny spider to make it grow slowly. Seems it does not work as the engine overrides frequently the values I set. Is there a simplier method to do it ? (Does it really fit as a "simple question" ??? :lol: )
Last edited by AndakRainor on Fri Jul 17, 2015 2:28 pm, edited 1 time in total.
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

AFAIK it is not possible to grow/shrink monsters in that way. The animations resizes them to their former dimensions. Also every animation wouldn't work because in a shrinked version the animation wouldn't lead the monster from square-center to square-center (where all animations have to start/end).
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
THOM
Posts: 1280
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 am trying to script a function, that spawns several items randomly on the map.

My aim: I have 12 defined spots and 4 items. The items should be spread out randomly on random spots.

Sadly I cannot figure out, how to do that. I am sure, I am doing it far too complicate, but thats the only way I know how to do. (or better "don't know how to...")
All I get are several error messages and the preview doesn't start. Can anyone help me, please?

That's what I have:

Code: Select all

function AddQuestItem()

local tMap = spawn("treasure_map");
tMap.scrollitem:setScrollImage("mod_assets/textures/note_pic/asia_tiger.tga")


-- decide which item is spawned
local x = math.random(1,4)

	if x == 1 then
		local itemA = spawn("ancient_apparatus");
		local itemB = tMap;
		local itemC = spawn("globe_spherical_map");
		local itemD = spawn("telescope");
	end
	if x == 2 then
		local itemB = spawn("ancient_apparatus");
		local itemC = tMap;
		local itemD = spawn("globe_spherical_map");
		local itemA = spawn("telescope");
	end
	if x == 3 then
		local itemC = spawn("ancient_apparatus");
		local itemD = tMap;
		local itemA = spawn("globe_spherical_map");
		local itemB = spawn("telescope");
	end
	if x == 4 then
		local itemD = spawn("ancient_apparatus");
		local itemA = tMap;
		local itemB = spawn("globe_spherical_map");
		local itemC = spawn("telescope");
	end


-- decide where item is spawned
local spotA = math.random(1,5)
local spotB = math.random(1,7)
local spotC = math.random(1,7)
local spotD = math.random(1,7)

	if spotA == 1 then
		sx_barrel_chest_8.surface:addItem(itemA.item);
	end
	if spotA == 2 then
		sx_barrel_chest_02_9.surface:addItem(itemA.item);
	end
	if spotA == 3 then
		ratling1_5.monster:addItem(itemA.item);
	end
	if spotA == 4 then
		ratling1_4.monster:addItem(itemA.item);
	end
	if spotA == 5 then
		ratling1_2.monster:addItem(itemA.item);
	end


	if spotB == 1 then
		spawn(itemB.item, 9, 23, 10, 2, 0) -- behind barrels
	end
	if spotB == 2 then
		spawn(itemB.item, 9, 6, 18, 0, 0) -- under bush 
	end
	if spotB == 3 then
		spawn(itemB.item, 9, 26, 17, 3, 0) -- in water 
	end
	if spotB == 4 then
		spawn(itemB.item, 9, 3, 11, 2, 0)-- upper left 
	end
	if spotB == 5 then
		spawn(itemB.item, 9,  17, 15, 0, 0) -- under table
	end
	if spotB == 6 then
		ratling3_6.monster:addItem(itemB.item);
	end
	if spotB == 7 then
		ratling2_1.monster:addItem(itemB.item);
	end

	if spotC == 1 then
		spawn(itemC.item, 9, 23, 10, 2, 0) -- behind barrels
	end
	if spotC == 2 then
		spawn(itemC.item, 9, 6, 18, 0, 0) -- under bush 
	end
	if spotC == 3 then
		spawn(itemC.item, 9, 26, 17, 3, 0) -- in water 
	end
	if spotC == 4 then
		spawn(itemC.item, 9, 3, 11, 2, 0)-- upper left 
	end
	if spotC == 5 then
		spawn(itemC.item, 9,  17, 15, 0, 0) -- under table
	end
	if spotC == 6 then
		ratling3_6.monster:addItem(itemC.item);
	end
	if spotC == 7 then
		ratling2_1.monster:addItem(itemC.item);
	end

	if spotD == 1 then
		spawn(itemD.item, 9, 23, 10, 2, 0) -- behind barrels
	end
	if spotD == 2 then
		spawn(itemD.item, 9, 6, 18, 0, 0) -- under bush 
	end
	if spotD == 3 then
		spawn(itemD.item, 9, 26, 17, 3, 0) -- in water 
	end
	if spotD == 4 then
		spawn(itemD.item, 9, 3, 11, 2, 0)-- upper left 
	end
	if spotD == 5 then
		spawn(itemD.item, 9,  17, 15, 0, 0) -- under table
	end
	if spotD == 6 then
		ratling3_6.monster:addItem(itemD.item);
	end
	if spotD == 7 then
		ratling2_1.monster:addItem(itemD.item);
	end

end


THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
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 »

Does it work better ?

Code: Select all

function addQuestItems()
  local tmap = spawn("treasure_map");
  tmap.scrollitem:setScrollImage("mod_assets/textures/note_pic/asia_tiger.tga")
  local objects = randomOrder({spawn("globe_spherical_map"), spawn("telescope"), spawn("ancient_apparatus"), tmap})

  local behin_barrels = {x=23, y=10, f=2, e=0, l=9}
  local under_bush    = {x= 6, y=18, f=0, e=0, l=9}
  local in_water      = {x=26, y=17, f=3, e=0, l=9}
  local upper_left    = {x= 3, y=11, f=2, e=0, l=9}
  local under_table   = {x=17, y=15, f=0, e=0, l=9}

  objects = {
    {objects[1], randomElement({sx_barrel_chest_8, sx_barrel_chest_02_9, ratling1_5, ratling1_4, ratling1_2})},
    {objects[2], randomElement({behin_barrels, under_bush, in_water, upper_left, under_table, ratling3_6, ratling2_1})},
    {objects[3], randomElement({behin_barrels, under_bush, in_water, upper_left, under_table, ratling3_6, ratling2_1})},
    {objects[4], randomElement({behin_barrels, under_bush, in_water, upper_left, under_table, ratling3_6, ratling2_1})},
  }
  addItems(objects)
end

function randomOrder(tab)
  local result = {}
  for i = 1,#tab do table.insert(result, math.random(i), tab[i]) end
  return result
end

function randomElement(tab) return tab[math.random(#tab)] end

function addItems(objects)
  for i = 1,#objects do addItem(objects[i][1], objects[i][2]) end
end

function addItem(o, t)
  if t.surface then
    t.surface:addItem(o.item)
  elseif t.monster then
    t.monster:addItem(o.item)
  else
    o:setPosition(t.x, t.y, t.f, t.e, t.l)
  end
end
PS: you had local variables not declared at the level you used them in your script, that would crash the preview. My script should do exactly what you wanted to if your variables were declared at the right place. But may be it is still a little too complicated to simply shuffle things (I kept the way you randomized items and destinations) ? If so I could also write something shorter and simpler, but it won't be the same random result :)
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

AndakRainor, thanks a lot. Seem to work.

Funny thing is: If I have a look at your script I nearly understand nothing of what it does... :lol:
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Ask a simple question, get a simple answer

Post by Drakkan »

Hi guys
I hope, this could be easy. I need following object to be non-walkable like real wall and also it should display itself as a regular wall on the automap. What I need to define here ?
edit: the same goes for standrad castle_wall object

Code: Select all

defineObject{
	name = "castle_wall_outside_01",
	baseObject = "base_wall",
	components = {
		{
			class = "Model",
			model = "assets/models/env/castle_outside_wall_01.fbx",
			dissolveStart = 6,
			dissolveEnd = 8,
			staticShadow = true,
		},
		{
			class = "Occluder",
			model = "assets/models/env/castle_wall_01_occluder.fbx",
		},
	},
	minimalSaveState = true,
}
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
THOM
Posts: 1280
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 am trying to close all doors named dungeon_secret_door_THOM_a_1 ..._2 .._3 etc.

I've tried this (and many other attempts) - nothing works.
Can anyone help, please??

Code: Select all

	for e in party.map:allEntities() do
			if e.name == "dungeon_secret_door_THOM_a_%d" then
				e.door:close()
			end
	end
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

It doesn't seem to work. And I am looking already at the StringLibraryTutorial. I am unable to find a something that works. *sigh*
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

then you did not read the whole page!

Code: Select all

       for e in party.map:allEntities() do
             if e.name:find("dungeon_secret_door_THOM_a_") then
                e.controller:close()
             end
       end
%d is just the pattern to match a decimal number, it won't do anything special unless the string is passed to string.format or string.gmatch or string.pattern, etc
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.
Post Reply