--LUA Script - precede every function and global member with lowercase name of script + '_main' --DESCRIPTION: smallg's moving object script --DESCRIPTION: (directions to move in) --DESCRIPTION: [MOVEONX!=0] --DESCRIPTION: [MOVEONY!=0] --DESCRIPTION: [MOVEONZ!=0] --DESCRIPTION: (how far along each direction before returning) --DESCRIPTION: [MAXMOVEX=10] --DESCRIPTION: [MAXMOVEY=10] --DESCRIPTION: [MAXMOVEZ=10] --DESCRIPTION: (movement speed - negative values makes it move the negative axis / opposite way at start) --DESCRIPTION: [MOVESPEEDX=100] --DESCRIPTION: [MOVESPEEDY=100] --DESCRIPTION: [MOVESPEEDZ=100] --DESCRIPTION: [FIXXPOS!=0] --DESCRIPTION: [FIXYPOS!=0] --DESCRIPTION: [FIXZPOS!=0] --DESCRIPTION: [FIXXROT!=1] --DESCRIPTION: [FIXYROT!=1] --DESCRIPTION: [FIXZROT!=1] g_moving_object = {} local direction, startx, starty, startz, startax, startay, startaz, state = {},{},{},{},{},{},{},{} function moving_object_properties(e, moveonx, moveony, moveonz, maxmovex, maxmovey, maxmovez, movespeedx, movespeedy, movespeedz, fixxpos, fixypos, fixzpos, fixxrot, fixyrot, fixzrot) local mo = g_moving_object[e] mo.moveonx = moveonx mo.moveony = moveony mo.moveonz = moveonz mo.maxmovex = maxmovex mo.maxmovey = maxmovey mo.maxmovez = maxmovez mo.movespeedx = movespeedx mo.movespeedy = movespeedy mo.movespeedz = movespeedz mo.fixxpos = fixxpos mo.fixypos = fixypos mo.fixzpos = fixzpos mo.fixxrot = fixxrot mo.fixyrot = fixyrot mo.fixzrot = fixzrot end function moving_object_init(e) g_moving_object[e] = {} local mo = g_moving_object[e] mo.moveonx = 0 mo.moveony = 0 mo.moveonz = 0 mo.maxmovex = 10 mo.maxmovey = 10 mo.maxmovez = 10 mo.movespeedx = 100 mo.movespeedy = 100 mo.movespeedz = 100 mo.fixxpos = 0 mo.fixypos = 0 mo.fixzpos = 0 mo.fixxrot = 1 mo.fixyrot = 1 mo.fixzrot = 1 state[e] = "setup" direction[e] = {} for a = 1, 3 do direction[e][a] = 0 end end function moving_object_main(e) local mo = g_moving_object[e] if state[e] == "setup" then if mo.moveonx == 0 then mo.movespeedx = 0 else direction[e][1] = mo.movespeedx / 100 end if mo.moveony == 0 then mo.movespeedy = 0 else direction[e][2] = mo.movespeedy / 100 end if mo.moveonz == 0 then mo.movespeedz = 0 else direction[e][3] = mo.movespeedz / 100 end if mo.moveonx == 0 and mo.moveony == 0 and mo.moveonz == 0 then return end startx[e], starty[e], startz[e], startax[e], startay[e], startaz[e] = GetEntityPosAng(e) if direction[e][1] < 0 then startx[e] = startx[e] - mo.maxmovex end if direction[e][2] < 0 then starty[e] = starty[e] - mo.maxmovey end if direction[e][3] < 0 then startz[e] = startz[e] - mo.maxmovez end state[e] = "move" elseif state[e] == "move" then local x1,y1,z1,ax,ay,az = GetEntityPosAng(e) if mo.moveonx == 1 then if direction[e][1] > 0 then if x1 < startx[e] + mo.maxmovex then x1 = x1 + direction[e][1] else direction[e][1] = direction[e][1] * -1 x1 = startx[e] + mo.maxmovex end elseif direction[e][1] < 0 then if x1 > startx[e] then x1 = x1 + direction[e][1] else direction[e][1] = direction[e][1] * -1 x1 = startx[e] end end end if mo.moveony == 1 then if direction[e][2] > 0 then if y1 < starty[e] + mo.maxmovey then y1 = y1 + direction[e][2] else direction[e][2] = direction[e][2] * -1 y1 = starty[e] + mo.maxmovey end elseif direction[e][2] < 0 then if y1 > starty[e] then y1 = y1 + direction[e][2] else direction[e][2] = direction[e][2] * -1 y1 = starty[e] end end end if mo.moveonz == 1 then if direction[e][3] > 0 then if z1 < startz[e] + mo.maxmovez then z1 = z1 + direction[e][3] else direction[e][3] = direction[e][3] * -1 z1 = startz[e] + mo.maxmovez end elseif direction[e][3] < 0 then if z1 > startz[e] then z1 = z1 + direction[e][3] else direction[e][3] = direction[e][3] * -1 z1 = startz[e] end end end if mo.fixxpos == 1 then x1 = startx[e] end if mo.fixypos == 1 then y1 = starty[e] end if mo.fixzpos == 1 then z1 = startz[e] end CollisionOff(e) SetPosition(e, x1, y1, z1) ResetPosition(e, x1, y1, z1) CollisionOn(e) if mo.fixxrot == 1 then ax = startax[e] end if mo.fixyrot == 1 then ay = startay[e] end if mo.fixzrot == 1 then az = startaz[e] end SetRotation(e, ax, ay, az) ResetRotation(e, ax, ay, az) --PromptLocal(e, direction[e][1].." "..direction[e][2].." "..direction[e][3]) end end