Re: Ask a simple question, get a simple answer
Posted: Wed Jun 17, 2015 4:56 pm
https://www.dropbox.com/s/eskuvw1zgq8zp ... r.zip?dl=1
Updated two mistakes, noticed by minmay.
Code: Select all
--[[ Floor triggers should call floorTriggeredEffect() on activate.
Scripts and timers can call spinTo or spinTo2 directly.
Scripts can include the chosen direction for spinTo or spinTo2.
Timers and triggers default to a random direction.
If you plan to call the effect from a floor_trigger through a script that
calls either spinTo or SpinTo2, do so by calling your function with a delay,
as shown in floorTriggerEffect(); or change delayedCall in floorTriggerEffect,
to call your function name instead.
And/or/also delayedCall can send a facing direction as parameter to spinTo/spinTo2.
--]]
function floorTriggeredEffect()
delayedCall(self.go.id, .35, "spinTo2")
end
function spinTo(self, facing)
local facing = facing or math.random(4)%3
local dir = iff(math.random() <.5, 1, -1)
local loc = {}
loc[1],loc[2],loc[3],loc[5] = party:getPosition()
loc[4] = party.elevation
loc[3] = facing
party:setPosition(unpack(loc))
end
--[[
spinTo2 is a cool alternate of the effect, but it might be unstable :(
It crashed on me once, and I haven't been able to reproduce it.
The error it gave, happened while checking for obstacles.
(Afterwards) I had set it up on a timer to run it every .4 seconds while trying
to wander the map in every direction and bump into things for a good five minutes.
it's been edited since, and I've had no problems with it since,
but it's something to be aware of. If you use it and have any problem, you can
always switch to spinTo instead; all you lose is the animated turn... which might be
what you want anyway. spinTo's effect is instant.
--]]
function spinTo2(caller, facing)
local facing = facing or math.random(4)%3
local dir = iff(math.random() <.5, 1, -1)
local loc = {}
loc[1],loc[2],loc[3],loc[5] = party:getPosition()
loc[4] = party.elevation
loc[3] = facing - dir
party:setPosition(unpack(loc))
delayedCall(self.go.id, .01, "turn", dir)
end
function turn(dir)
if party.party:isIdle() then
party.party:turn(dir)
end
end