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!
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.
--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:
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!
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.
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
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:
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.
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! Thank you!
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!
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