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
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

Isaac wrote:
Curunir wrote:How would I go about checking to see if the party is within a certain range of map coordinates (let's say a 4x4 grid at x16-19 and y16-19, one tile away from a fountain model) and if they are, execute a script?
One way is to place party-only activated floor-triggers in every tile in the region; tiles that all connect to the same script. You can inspect the the triggers to learn the exact location, if useful to you.

An alternative scripted method:

Code: Select all

--Place script_entity at top left of region.
--Set values of regionX, and regionY to the number of columns & rows to check 


party.party:addConnector('onMove', self.go.id, "positionCheck")
region_active = true
regionX, regionY = 7,7 

function positionCheck() 
	if region_active then
		local width, height = party.x +regionX, party.y +regionY
	
		if (party.x >= self.go.x and party.x <= width) and (party.y >= self.go.y and party.y <= height)
		 then
			--=======================================[ triggered actions ]
			
			
			print('Party is in region.')
			party:spawn("shockburst").tiledamager:setAttackPower(1)
			
			
			--============================================================
		end
	end
end

function setActive(self, bool)
	if type(bool)=="boolean" then region_active = bool return end
	if type(self)=="boolean" then region_active = self end
end
You're the best, guys! I would have never come up with this script on my own.

I did initially think of doing the thing with floor triggers and cobbled this together last night, and it worked:

Code: Select all

function proximityCheck()

for i=2,13 do
	local widget = findEntity("floor_trigger_"..i)
	if widget.floortrigger:isActivated() then 
		triggerDoor.door:open()
		end
		end
		end
Your code is obviously going to be a LOT more useful for larger areas. Thank you very much for the help!
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 »

Made a minor update to the script. The setActive function, it now toggles the effect if not given arguments. This makes it work with floor_triggers, buttons, and levers.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Isaac wrote:

Code: Select all

function setActive(self, bool)
	if type(bool)=="boolean" then region_active = bool return end
	if type(self)=="boolean" then region_active = self return end
	region_active = not region_active
end
Why does this function have two arguments?
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 »

Zo Kath Ra wrote:
Isaac wrote:

Code: Select all

function setActive(self, bool)
	if type(bool)=="boolean" then region_active = bool return end
	if type(self)=="boolean" then region_active = self return end
	region_active = not region_active
end
Why does this function have two arguments?
It was done this way because of the two ways that a user might try to call it; three ways, if you count lack of arguments. It only needs the one boolean argument... but if it's called in the way that passes the calling script first... then the first argument won't be a boolean.

The function type checks bool first, failing that it type checks self (in case that is the boolean argument); and failing either, it toggles the boolean state.

So that all three of these calling conventions will work:

Code: Select all

script_entity_1.script.setActive()
script_entity_1.script.setActive(false)
script_entity_1.script:setActive(false)
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

Why doesn't this work? I have a custom item and a floor trigger to check if the party has the custom item, then open a door, and it doesn't work.

Code: Select all

function loreStoneCheck()

if party.party:isCarrying("lore_stone_1") then

door_1.door:open()
else
door_1.door:close()
end
end
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

try with defining the item "lore_stone" only
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Curunir wrote:Why doesn't this work? I have a custom item and a floor trigger to check if the party has the custom item, then open a door, and it doesn't work.

Code: Select all

function loreStoneCheck()

if party.party:isCarrying("lore_stone_1") then

door_1.door:open()
else
door_1.door:close()
end
end
Because PartyComponent:isCarrying(string) doesn't take an object ID as a parameter.
It needs an object name, in this case "lore_stone"
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

Guess I should pick my info sources better! I've been collecting tidbits of scripts and info from both LOG2DOC and the forum and my reference says
if party.party:isCarrying("item_id") then ... end, which is obviously wrong! :D Thank you!
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

One more before the weekend is over!

I have this:

Code: Select all

function offeringAltar(self, item)
   if (item.go.name == "battle_axe") then
      hudPrint("Offering accepted")
      item.go:destroy()
	spawn("particle_system", 1, 15, 16, 0, 0).particle:setParticleSystem("teleporter")
	playSound("secret")
	offeringDoor.door:open()
   else
      hudPrint("You fail to please") end

   end
It works fine, but I have no idea how to play the teleporter particle fx for just a short while, they stay on forever and I want them to linger for, say, a second or two. Is there any way to control this? Thanks!
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 »

Curunir wrote:Guess I should pick my info sources better!
This is a good source. ;)
https://github.com/JKos/log2doc/wiki/Co ... -component

Particle effect

Code: Select all

function offeringAltar(self, item)
   if (item.go.name == "battle_axe") then
     hudPrint("Offering accepted")
	  local effect = findEntity(item.go:spawn("particle_system").id)
		    effect.particle:setParticleSystem("teleporter")
	       effect.particle:fadeOut(2.5)  --<<<<<<<<<<<<<<[ :fadeOut() fades the particle system]
		    effect.particle:setDestroySelf(true)
	  item.go:destroy()
	  playSound("secret")
	  offeringDoor.door:open()
     else
      hudPrint("You fail to please")
	end
end
Post Reply