Damonya wrote:Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onMove = function( self , dir )
return partyScript.canMove( self , dir )
end,
}
And I have error with the "return" when I add script on this hook.
Once you put a "return" inside a function, you cannot put lines of script after it! Since you already have a "partyScript.canMove" function that handles your party moves, you should modify that script with something as (I will assume that the altar as id "moveable_altar" and is placed at 'xa','ya' in the dungeon, with facing equal to 'fc')
Code: Select all
-- outside the canMove function
partyplaces = {{x = xa + 1,y = ya, facing = 3},{x = xa - 1, y = ya, facing = 1}, {x = xa, y = ya + 1, facing = 0}, {x = xa, y = ya - 1, facing = 2}}
--inside the canMove function
local movealtar = false
local direction = 0
for _,pp in pairs(partyplaces) do
if (self.x == pp.x) and (self.y == pp.y) and (self.facing == pp.facing) and (dir == pp.facing) then -- check that we are in the right place, looking and moving in the right direction
movealtar = true
direction = dir
end
if (movealtar) then
findEntity("moveable_altar"):destroy()
local dx,dy = getForward(direction)
xa = xa + dx
ya = ya + dy
spawn("altar",party.level,xa,ya,fc,"moveable_altar")
-- add particles and dust effects here
end
The only trouble with this script is that - in this way - you may well move the altar through a wall; hence, there should be a table of 'admissible places': if the target position (xa+dx,ya+dy) is ok, then move the altar, otherwise leave everything as is
alois
