Page 230 of 400
Re: Ask a simple question, get a simple answer
Posted: Fri Apr 20, 2018 7:01 am
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!
Re: Ask a simple question, get a simple answer
Posted: Fri Apr 20, 2018 7:15 am
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.
Re: Ask a simple question, get a simple answer
Posted: Fri Apr 20, 2018 6:40 pm
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?
Re: Ask a simple question, get a simple answer
Posted: Sat Apr 21, 2018 4:04 am
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)
Re: Ask a simple question, get a simple answer
Posted: Sun Apr 22, 2018 10:41 am
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
Re: Ask a simple question, get a simple answer
Posted: Sun Apr 22, 2018 11:08 am
by bongobeat
try with defining the item "lore_stone" only
Re: Ask a simple question, get a simple answer
Posted: Sun Apr 22, 2018 11:14 am
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"
Re: Ask a simple question, get a simple answer
Posted: Sun Apr 22, 2018 3:05 pm
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!

Thank you!
Re: Ask a simple question, get a simple answer
Posted: Sun Apr 22, 2018 5:28 pm
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!
Re: Ask a simple question, get a simple answer
Posted: Sun Apr 22, 2018 6:26 pm
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