Page 1 of 1

How to move a "blockage" object?

Posted: Mon Apr 15, 2013 8:51 am
by Damonya
I am looking for a solution to move with script, a blockage prop object. In fact an altar. When you move the player against the altar (which have the behavior of a wall) the altar moves from one box.
I've given it some thought, and it would be easier, is to detect player faces the altar with a OnMove, then destroy the altar, creating a dust FX and spawn again the altar one box further, but it is not awesome.

Any ideas?

In First, I don't know how to script my party OnMove because I have already this hook on the OnMove:

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.

Re: How to move a "blockage" object?

Posted: Mon Apr 15, 2013 10:00 am
by Xanathar
For the first part: I have no real idea on how it works, etc. but I would check the rolling boulder that was posted here some time ago - someone even implemented a sokoban minigame with it.

As far as the second part go this might be enough, as there is no reason to return false from the altar script, from your description.

Code: Select all

    
cloneObject{
      name = "party",
      baseObject = "party",
   onMove = function( self , dir )
        movingAltarScript.doSomething()
        return partyScript.canMove( self , dir )
   end,    
}
If there is the need to concatenate more than one hook, the solution would be:

Code: Select all

    
cloneObject{
      name = "party",
      baseObject = "party",
   onMove = function( self , dir )
        if (movingAltarScript.doSomething() == false) then 
			return false;
		end
        return partyScript.canMove( self , dir )
   end,    
}

Re: How to move a "blockage" object?

Posted: Mon Apr 15, 2013 10:17 am
by alois
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 :)

Re: How to move a "blockage" object?

Posted: Mon Apr 15, 2013 10:52 am
by Damonya
wow thank you very much to both of you, your script works very well :o
Better, faster, stronger than what I wanted to do. :D