Jump to content

Gate maker wont close gates


blake7120

Recommended Posts

gateloader

gateList        = {} 
  
gateListMoveToX = {} 
gateListMoveToY = {} 
gateListMoveToZ = {} 
  
gateListMoveTorX = {} 
gateListMoveTorY = {} 
gateListMoveTorZ = {} 
  
shapes          = {} 
team            = {} 
temp            = {} 
  
status          = {} -- 0 = not moving. 1 = moving to open. 2 = moving to close 
  
function checkClass(hitElement, matchingDimension) 
  
    if ( getElementType(hitElement) == "vehicle" ) then 
        hitElement = getVehicleController(hitElement) 
    end 
  
    for i=0,#gateList do  
        local name = getTeamName(getPlayerTeam(hitElement)) 
        if(name == false) then 
            name = "false" 
        end 
        if ( name == team[i] or name == "true") then  
            detection = isElementWithinColShape ( hitElement, shapes[i] ) 
            if detection == true then  
                move(i, false) 
            end 
        end 
    end 
end 
  
  
function loadup(startedResource) 
    gates = xmlLoadFile ( "gates.xml" ) 
    count = xmlNodeGetChildren(gates) 
  
    for i=1,#count do 
        local gate = xmlFindChild ( gates, "gate", i-1 ) 
        local attributes = xmlNodeGetAttributes ( gate ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
  
     
            gateList[i]  = createObject(temp["objectID"], temp["x"], temp["y"], temp["z"], temp["rx"], temp["ry"], temp["rz"]) 
            gateListMoveToX[i] = temp["x2"] 
            gateListMoveToY[i] = temp["y2"] 
            gateListMoveToZ[i] = temp["z2"] 
  
            gateListMoveTorX[i] = temp["rx2"] 
            gateListMoveTorY[i] = temp["ry2"] 
            gateListMoveTorZ[i] = temp["rz2"] 
            outputDebugString("" .. temp["objectID"] .. "") 
            shapes[i] = createColRectangle(temp["collisionx"], temp["collisionY"], temp["collisionZ"], temp["collisionSize"],temp["collisionSize"])  
            team[i]   = temp["team"] 
            setElementInterior(gateList[i], temp["interiorID"]) 
            status[i] = 0 
            addEventHandler ( "onColShapeHit", shapes[i], checkClass ) 
  
    end 
  
  
    xmlUnloadFile ( gates ) 
end 
  
function move(gateIndex, rotate) -- 0 = not moving. 1 = moving to open. 2 = moving to close 
    outputDebugString("moving..") 
    x,y,z = getElementPosition(gateList[gateIndex]) 
    rx,ry,rz = getObjectRotation(gateList[gateIndex]) 
    if status[gateIndex] == 0 then 
        moveObject ( gateList[gateIndex], 2000, gateListMoveToX[gateIndex], gateListMoveToY[gateIndex],gateListMoveToZ[gateIndex]) 
        status[gateIndex] = 1 
        setTimer ( moveBack, 3000, 1,gateIndex, x,y,z,rx,ry,rz, raising ) 
    end 
end 
  
function moveBack(index, x,y,z, raising) 
    if status[index] == 1 then 
        status[index] = 2 
        moveObject ( gateList[index], 2000, x,y,z, gateListMoveTorX[gateIndex],gateListMoveTorY[gateIndex],gateListMoveTorZ[gateIndex],rx,ry,rz ) 
        setTimer ( resetTimer, 2000, 1, index ) 
    end 
end 
  
function resetTimer(index) 
    status[index] = 0 
end 
  
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 

server.lua

Editor      = {} 
Gate        = {}
Gate2       = {}
Precision   = {}
status      = {}
coll        = {}
coll2        = {}
coll3        = {}
coll4        = {}
 
 -- this script mod is (no longer) PRIVATE
 -- - Deject3d
 
function startBuilding(playerSource, commandName, objectid)
    if not objectid then
        outputChatBox("usage: /addgate objectid teamname", playerSource)
    end
       
    team = getTeamName(getPlayerTeam(playerSource))
    if team == false then
        team = ""
    end
    for i = 1,20 do
        if Editor[i] == playerSource then
            destroyElement(Gate[i])
            Gate[i] = null
            Editor[i] = null
            Precision[i] = null
        end
        if Editor[i] == null then
            Editor[i] = playerSource -- set Editor[i] to who made the object
 
                --creating object -v
            local x,y,z = getElementPosition(playerSource)
            object = createObject ( objectid, x + 3,y + 3,z)
            interior = getElementInterior ( playerSource )
            setElementInterior(object,interior)
                --created object -^
 
            Gate[i] = object -- added object identifier to the array, corresponds to who created it
            Precision[i] = .5   -- default precision
 
            bindKey(playerSource, "i",        "down", moveIt)
            bindKey(playerSource, "j",        "down", moveIt)
            bindKey(playerSource, "k",        "down", moveIt)
            bindKey(playerSource, "l",        "down", moveIt)
            bindKey(playerSource, "mouse_wheel_up",   "down", moveIt)
            bindKey(playerSource, "mouse_wheel_down", "down", moveIt)
            bindKey(playerSource, "pgup",         "down", moveIt)
            bindKey(playerSource, "pgdn",         "down", moveIt)
 
            bindKey(playerSource, "u",        "down", moveIt)
            bindKey(playerSource, "o",        "down", moveIt)
 
            bindKey(playerSource, "[",        "down", moveIt)
            bindKey(playerSource, "]",        "down", moveIt)
 
            bindKey(playerSource, "enter",        "down", nextPosition ,objectid, team)
            bindKey(playerSource, "delete",       "down", removeIt, playerSource)
 
            break -- done adding our object and who created it to the arrays... stop the loop
        end
    end
 
end
 
function nextPosition(playerSource, key, keyState, objectid, team)
            unbindKey ( playerSource, "i"               )
            unbindKey ( playerSource, "j"               )
            unbindKey ( playerSource, "k"               )
            unbindKey ( playerSource, "l"               )
            unbindKey ( playerSource, "pgup"            )
            unbindKey ( playerSource, "pgdn"            )
            unbindKey ( playerSource, "mouse_wheel_down")
            unbindKey ( playerSource, "mouse_wheel_up"  )
            unbindKey ( playerSource, "enter"           )
            unbindKey ( playerSource, "delete"          )
            unbindKey ( playerSource, "u"               )
            unbindKey ( playerSource, "o"               )
            unbindKey ( playerSource, "["               )
            unbindKey ( playerSource, "]"               )
 
    outputDebugString("object 1 set. object 2 controlled. ID: " .. objectid .." team: " .. team .. "")
    for i = 1,20 do
        if Editor[i] == playerSource then
 
                --creating object -v
            local x,y,z = getElementPosition(Gate[i])
            local rx,ry,rz= getObjectRotation(Gate[i])
            object = createObject ( objectid, x,y,z,rx,ry,rz)
            interior = getElementInterior ( playerSource )
            setElementInterior(object,interior)
                --created object -^
 
            Gate2[i] = object -- added object identifier to the array, corresponds to who created it
            Precision[i] = .5   -- default precision
 
            bindKey(playerSource, "i",        "down", moveIt2)
            bindKey(playerSource, "j",        "down", moveIt2)
            bindKey(playerSource, "k",        "down", moveIt2)
            bindKey(playerSource, "l",        "down", moveIt2)
            bindKey(playerSource, "mouse_wheel_up",   "down", moveIt2)
            bindKey(playerSource, "mouse_wheel_down", "down", moveIt2)
            bindKey(playerSource, "pgup",         "down", moveIt2)
            bindKey(playerSource, "pgdn",         "down", moveIt2)
 
            bindKey(playerSource, "u",        "down", moveIt2)
            bindKey(playerSource, "o",        "down", moveIt2)
 
            bindKey(playerSource, "[",        "down", moveIt2)
            bindKey(playerSource, "]",        "down", moveIt2)
 
            bindKey(playerSource, "enter",        "down", collisionObject, team, objectID)
            bindKey(playerSource, "delete",       "down", removeIt, playerSource)
 
            break -- done adding our object and who created it to the arrays... stop the loop
        end
    end
end
 
function changePrecision(playerSource,commandName,value)
    if value then
        for i = 1,20 do
            if Editor[i] == playerSource then
                Precision[i] = value
                outputChatBox("Sensitivity set to: " .. value .. "", playerSource)
                break
            end
        end
    end
end
 
 
function moveIt(source, key, keyState)
    for i = 1,20 do
        if Editor[i] == source then
            object = Gate[i]
            prec = Precision[i]
            break
        end
    end
   
    if key == "i" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y + prec,z )
    end
    if key =="j" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x - prec,y,z )
    end
    if key =="l" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x + prec,y,z )
    end
    if key =="k" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y - prec,z )
    end
    if key =="pgup" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y,z + prec )
    end
    if key =="pgdn" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y ,z - prec )
    end
 -- rotation --
    if key =="mouse_wheel_up" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz - prec * 5)
    end
    if key =="mouse_wheel_down" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz + prec * 5)
    end
    if key =="u" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry - prec*10,rz)
    end
    if key =="o" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry + prec*10,rz)
    end
    if key =="[" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx- prec*10,ry,rz)
    end
    if key =="]" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx+ prec*10,ry,rz)
    end
end
 
function moveIt2(source, key, keyState)
    for i = 1,20 do
        if Editor[i] == source then
            object = Gate2[i]
            prec = Precision[i]
            break
        end
    end
   
    if key == "i" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y + prec,z )
    end
    if key =="j" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x - prec,y,z )
    end
    if key =="l" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x + prec,y,z )
    end
    if key =="k" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y - prec,z )
    end
    if key =="pgup" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y,z + prec )
    end
    if key =="pgdn" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y ,z - prec )
    end
 -- rotation --
    if key =="mouse_wheel_up" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz - prec * 5)
    end
    if key =="mouse_wheel_down" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz + prec * 5)
    end
    if key =="u" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry - prec*10,rz)
    end
    if key =="o" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry + prec*10,rz)
    end
    if key =="[" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx- prec*10,ry,rz)
    end
    if key =="]" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx+ prec*10,ry,rz)
    end
end
Link to comment
gateloader
gateList        = {} 
  
gateListMoveToX = {} 
gateListMoveToY = {} 
gateListMoveToZ = {} 
  
gateListMoveTorX = {} 
gateListMoveTorY = {} 
gateListMoveTorZ = {} 
  
shapes          = {} 
team            = {} 
temp            = {} 
  
status          = {} -- 0 = not moving. 1 = moving to open. 2 = moving to close 
  
function checkClass(hitElement, matchingDimension) 
  
    if ( getElementType(hitElement) == "vehicle" ) then 
        hitElement = getVehicleController(hitElement) 
    end 
  
    for i=0,#gateList do  
        local name = getTeamName(getPlayerTeam(hitElement)) 
        if(name == false) then 
            name = "false" 
        end 
        if ( name == team[i] or name == "true") then  
            detection = isElementWithinColShape ( hitElement, shapes[i] ) 
            if detection == true then  
                move(i, false) 
            end 
        end 
    end 
end 
  
  
function loadup(startedResource) 
    gates = xmlLoadFile ( "gates.xml" ) 
    count = xmlNodeGetChildren(gates) 
  
    for i=1,#count do 
        local gate = xmlFindChild ( gates, "gate", i-1 ) 
        local attributes = xmlNodeGetAttributes ( gate ) 
        for name,value in pairs ( attributes ) do 
                temp["" .. name .. ""] = value 
        end 
  
     
            gateList[i]  = createObject(temp["objectID"], temp["x"], temp["y"], temp["z"], temp["rx"], temp["ry"], temp["rz"]) 
            gateListMoveToX[i] = temp["x2"] 
            gateListMoveToY[i] = temp["y2"] 
            gateListMoveToZ[i] = temp["z2"] 
  
            gateListMoveTorX[i] = temp["rx2"] 
            gateListMoveTorY[i] = temp["ry2"] 
            gateListMoveTorZ[i] = temp["rz2"] 
            outputDebugString("" .. temp["objectID"] .. "") 
            shapes[i] = createColRectangle(temp["collisionx"], temp["collisionY"], temp["collisionZ"], temp["collisionSize"],temp["collisionSize"])  
            team[i]   = temp["team"] 
            setElementInterior(gateList[i], temp["interiorID"]) 
            status[i] = 0 
            addEventHandler ( "onColShapeHit", shapes[i], checkClass ) 
  
    end 
  
  
    xmlUnloadFile ( gates ) 
end 
  
function move(gateIndex, rotate) -- 0 = not moving. 1 = moving to open. 2 = moving to close 
    outputDebugString("moving..") 
    x,y,z = getElementPosition(gateList[gateIndex]) 
    rx,ry,rz = getObjectRotation(gateList[gateIndex]) 
    if status[gateIndex] == 0 then 
        moveObject ( gateList[gateIndex], 2000, gateListMoveToX[gateIndex], gateListMoveToY[gateIndex],gateListMoveToZ[gateIndex]) 
        status[gateIndex] = 1 
        setTimer ( moveBack, 3000, 1,gateIndex, x,y,z,rx,ry,rz, raising ) 
    end 
end 
  
function moveBack(index, x,y,z, raising) 
    if status[index] == 1 then 
        status[index] = 2 
        moveObject ( gateList[index], 2000, x,y,z, gateListMoveTorX[gateIndex],gateListMoveTorY[gateIndex],gateListMoveTorZ[gateIndex],rx,ry,rz ) 
        setTimer ( resetTimer, 2000, 1, index ) 
    end 
end 
  
function resetTimer(index) 
    status[index] = 0 
end 
  
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), loadup ) 

server.lua

Editor      = {} 
Gate        = {}
Gate2       = {}
Precision   = {}
status      = {}
coll        = {}
coll2        = {}
coll3        = {}
coll4        = {}
 
 -- this script mod is (no longer) PRIVATE
 -- - Deject3d
 
function startBuilding(playerSource, commandName, objectid)
    if not objectid then
        outputChatBox("usage: /addgate objectid teamname", playerSource)
    end
       
    team = getTeamName(getPlayerTeam(playerSource))
    if team == false then
        team = ""
    end
    for i = 1,20 do
        if Editor[i] == playerSource then
            destroyElement(Gate[i])
            Gate[i] = null
            Editor[i] = null
            Precision[i] = null
        end
        if Editor[i] == null then
            Editor[i] = playerSource -- set Editor[i] to who made the object
 
                --creating object -v
            local x,y,z = getElementPosition(playerSource)
            object = createObject ( objectid, x + 3,y + 3,z)
            interior = getElementInterior ( playerSource )
            setElementInterior(object,interior)
                --created object -^
 
            Gate[i] = object -- added object identifier to the array, corresponds to who created it
            Precision[i] = .5   -- default precision
 
            bindKey(playerSource, "i",        "down", moveIt)
            bindKey(playerSource, "j",        "down", moveIt)
            bindKey(playerSource, "k",        "down", moveIt)
            bindKey(playerSource, "l",        "down", moveIt)
            bindKey(playerSource, "mouse_wheel_up",   "down", moveIt)
            bindKey(playerSource, "mouse_wheel_down", "down", moveIt)
            bindKey(playerSource, "pgup",         "down", moveIt)
            bindKey(playerSource, "pgdn",         "down", moveIt)
 
            bindKey(playerSource, "u",        "down", moveIt)
            bindKey(playerSource, "o",        "down", moveIt)
 
            bindKey(playerSource, "[",        "down", moveIt)
            bindKey(playerSource, "]",        "down", moveIt)
 
            bindKey(playerSource, "enter",        "down", nextPosition ,objectid, team)
            bindKey(playerSource, "delete",       "down", removeIt, playerSource)
 
            break -- done adding our object and who created it to the arrays... stop the loop
        end
    end
 
end
 
function nextPosition(playerSource, key, keyState, objectid, team)
            unbindKey ( playerSource, "i"               )
            unbindKey ( playerSource, "j"               )
            unbindKey ( playerSource, "k"               )
            unbindKey ( playerSource, "l"               )
            unbindKey ( playerSource, "pgup"            )
            unbindKey ( playerSource, "pgdn"            )
            unbindKey ( playerSource, "mouse_wheel_down")
            unbindKey ( playerSource, "mouse_wheel_up"  )
            unbindKey ( playerSource, "enter"           )
            unbindKey ( playerSource, "delete"          )
            unbindKey ( playerSource, "u"               )
            unbindKey ( playerSource, "o"               )
            unbindKey ( playerSource, "["               )
            unbindKey ( playerSource, "]"               )
 
    outputDebugString("object 1 set. object 2 controlled. ID: " .. objectid .." team: " .. team .. "")
    for i = 1,20 do
        if Editor[i] == playerSource then
 
                --creating object -v
            local x,y,z = getElementPosition(Gate[i])
            local rx,ry,rz= getObjectRotation(Gate[i])
            object = createObject ( objectid, x,y,z,rx,ry,rz)
            interior = getElementInterior ( playerSource )
            setElementInterior(object,interior)
                --created object -^
 
            Gate2[i] = object -- added object identifier to the array, corresponds to who created it
            Precision[i] = .5   -- default precision
 
            bindKey(playerSource, "i",        "down", moveIt2)
            bindKey(playerSource, "j",        "down", moveIt2)
            bindKey(playerSource, "k",        "down", moveIt2)
            bindKey(playerSource, "l",        "down", moveIt2)
            bindKey(playerSource, "mouse_wheel_up",   "down", moveIt2)
            bindKey(playerSource, "mouse_wheel_down", "down", moveIt2)
            bindKey(playerSource, "pgup",         "down", moveIt2)
            bindKey(playerSource, "pgdn",         "down", moveIt2)
 
            bindKey(playerSource, "u",        "down", moveIt2)
            bindKey(playerSource, "o",        "down", moveIt2)
 
            bindKey(playerSource, "[",        "down", moveIt2)
            bindKey(playerSource, "]",        "down", moveIt2)
 
            bindKey(playerSource, "enter",        "down", collisionObject, team, objectID)
            bindKey(playerSource, "delete",       "down", removeIt, playerSource)
 
            break -- done adding our object and who created it to the arrays... stop the loop
        end
    end
end
 
function changePrecision(playerSource,commandName,value)
    if value then
        for i = 1,20 do
            if Editor[i] == playerSource then
                Precision[i] = value
                outputChatBox("Sensitivity set to: " .. value .. "", playerSource)
                break
            end
        end
    end
end
 
 
function moveIt(source, key, keyState)
    for i = 1,20 do
        if Editor[i] == source then
            object = Gate[i]
            prec = Precision[i]
            break
        end
    end
   
    if key == "i" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y + prec,z )
    end
    if key =="j" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x - prec,y,z )
    end
    if key =="l" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x + prec,y,z )
    end
    if key =="k" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y - prec,z )
    end
    if key =="pgup" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y,z + prec )
    end
    if key =="pgdn" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y ,z - prec )
    end
 -- rotation --
    if key =="mouse_wheel_up" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz - prec * 5)
    end
    if key =="mouse_wheel_down" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz + prec * 5)
    end
    if key =="u" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry - prec*10,rz)
    end
    if key =="o" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry + prec*10,rz)
    end
    if key =="[" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx- prec*10,ry,rz)
    end
    if key =="]" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx+ prec*10,ry,rz)
    end
end
 
function moveIt2(source, key, keyState)
    for i = 1,20 do
        if Editor[i] == source then
            object = Gate2[i]
            prec = Precision[i]
            break
        end
    end
   
    if key == "i" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y + prec,z )
    end
    if key =="j" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x - prec,y,z )
    end
    if key =="l" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x + prec,y,z )
    end
    if key =="k" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y - prec,z )
    end
    if key =="pgup" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y,z + prec )
    end
    if key =="pgdn" then
        x,y,z = getElementPosition(object)
        setElementPosition ( object, x,y ,z - prec )
    end
 -- rotation --
    if key =="mouse_wheel_up" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz - prec * 5)
    end
    if key =="mouse_wheel_down" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry,rz + prec * 5)
    end
    if key =="u" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry - prec*10,rz)
    end
    if key =="o" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx,ry + prec*10,rz)
    end
    if key =="[" then
        rx,ry,rz = getObjectRotation(object)
        setObjectRotation ( object, rx- prec*10,ry,rz)
    end
    if key =="]" then
        rx,ry,rz =
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...