Best-Killer Posted January 19, 2016 Share Posted January 19, 2016 --- GATE SYSTEM BY Fiocing Aka:Cherry --- miniDistance = 3 --RESOURCE SETTINGS --HERE CHANGE THE RESOURCE NAME TO THE GROUPS SYSTEM THAT YOU USE local GROUPS_RESOURCE_NAME = "SAEGGroups" -- CHANGE THAT LINE TO YOUR GROUP SYSTEM NAME function GPG(plr) if plr and getACC(plr) then return exports.SAEGGroups:getPlayerGroup ( plr) or (getTeamName(getPlayerTeam(plr)) == "Staff") end end 0 errors any help pls ! Link to comment
KariiiM Posted January 19, 2016 Share Posted January 19, 2016 What's that? It's not a full code also where's the variable of getACC ? and from where you got the parametre plr? Dude I suggest you to start learning , you know just editing done codes! don't be afraid from trying.. Link to comment
Best-Killer Posted January 19, 2016 Author Share Posted January 19, 2016 --- GATE SYSTEM BY Fiocing Aka:Cherry --- miniDistance = 3 --RESOURCE SETTINGS --HERE CHANGE THE RESOURCE NAME TO THE GROUPS SYSTEM THAT YOU USE local GROUPS_RESOURCE_NAME = "SAEGGroups" -- CHANGE THAT LINE TO YOUR GROUP SYSTEM NAME function GPG(plr) if plr and getACC(plr) then return exports.SAEGGroups:getPlayerGroup ( plr) end end -- GATE MANAGERS LIST (ACCOUNT NAME) managers = { "oussama", } -- ALLOWED OBJECTS THAT MANAGERS CAN USE TO PLACE GATE allowedModels = { 980 , 967 , 16773 , 10829 , 10832, 2990 , 2933 , 971 , 9042 , 8957, 3089, 2955 , 2947 , 2924 , 2911 , 1491 , 1504 , 1505 , 1507 , 1523 , 1557 , } ----Gate System By Omar(aka.Darhal)---- ---- All Right Reserved --- --RESOURCE VARRIABLES local gates = {} local lastGatePos = {} -----SQL FUNCTIONS----- local DB_LOCATION = ":/gates.db" -- The location where the database file is stored default is ":/gates.db" (/server/mods/deathmatch/databases/global) Just copy gates.db to there and it will work fine dbc = dbConnect("sqlite", DB_LOCATION) -- To use MySQL you'll only need to change just this line. dbExec(dbc, "CREATE TABLE IF NOT EXISTS gates (pos TEXT, rot TEXT, model INT, groups TEXT, mvt TEXT)") function onStop() dbExec(dbc, "DELETE FROM gates") for i, v in pairs(gates) do local x, y, z = v.pos[1], v.pos[2],v.pos[3] local rx, ry, rz = v.rot[1], v.rot[2],v.rot[3] local pos = x..", "..y..", "..z local rot = rx..", "..ry..", "..rz local groupsJSON = toJSON (v.groups) dbExec ( dbc, "INSERT INTO gates (pos, rot, model, groups, mvt) VALUES ( ?, ?, ?, ?, ?)", pos, rot, getElementModel(v.gate), groupsJSON, v.mvt) end end addEventHandler("onResourceStop", resourceRoot, onStop) function onStart() local mnew = dbQuery ( dbc, "SELECT * FROM gates") local mresult = dbPoll ( mnew, - 1 ) for i, v in pairs(mresult) do local x, y, z = unpack(split(v.pos, ",")) local rx, ry, rz = unpack(split(v.rot, ",")) local groups = fromJSON(v.groups) local cordTbl = {x, y, z} local rotTbl = {rx, ry, rz} createGate(cordTbl, rotTbl, groups, v.mvt, v.model) end end addEventHandler("onResourceStart", resourceRoot, onStart) --------CORE----------- ----------------------- -- MAIN SCRIPT -- function getACC(plr) if plr and isElement(plr) then return getAccountName(getPlayerAccount(plr)) or nil end end function reciveDataAndCreateGtae(groups, mvtType, pos, rot, model) createGate(pos, rot, groups,mvtType,model) end addEvent("CUPgates.sendGateData", true) addEventHandler("CUPgates.sendGateData", root, reciveDataAndCreateGtae) function createGate(cordTbl, rotTbl, groups, mvt, model) local gate = createObject(model, cordTbl[1], cordTbl[2], cordTbl[3], rotTbl[1], rotTbl[2], rotTbl[3]) local marker = createMarker (cordTbl[1], cordTbl[2], cordTbl[3] , "cylinder", 4.0, 0, 0, 0, 0) setElementData(gate, "gateIsMoving", false) table.insert(gates, {gate=gate, marker=marker, pos=cordTbl, rot=rotTbl, groups=groups, mvt=mvt}) addEventHandler("onMarkerHit", marker, openGate) addEventHandler("onMarkerLeave", marker, closeGate) end function closeGate(plr, sdim) if plr and getElementType(plr) == "player" and sdim then for i=1, #gates do if gates[i].marker == source and getElementData(gates[i].gate, "gateIsMoving") then triggerClientEvent("CUPgates.moveGateBack", plr, lastGatePos[gates[i].gate], i, gates[i].gate) break end end end end function openGate(plr, sdim) if plr and getElementType(plr) == "player" and sdim then for i=1, #gates do if gates[i].marker == source and not getElementData(gates[i].gate, "gateIsMoving") then for k, group in pairs( gates[i].groups) do if group.accGrp == GPG(plr) then setElementData(gates[i].gate, "gateIsMoving", true) local x, y, z = getElementPosition(gates[i].gate) lastGatePos[gates[i].gate] = {x, y, z} triggerClientEvent("CUPgates.moveGate", plr, gates[i].mvt, i, gates[i].gate) break end end break end end end end function toggleGateDelete(plr, cmd) if plr then local access = false for i=1, #managers do if managers[i] == getACC(plr) then access = true --triggerClientEvent(plr, "CUPgates.placeGate", plr) end end if access then for i, v in pairs(gates) do local gx, gy, gz = getElementPosition(v.gate) local x, y, z = getElementPosition(plr) if getDistanceBetweenPoints3D ( gx, gy, gz, x, y, z ) < miniDistance then destroyElement(v.gate) destroyElement(v.marker) table.remove(gates, i) break end end end end end addCommandHandler("delgate", toggleGateDelete) function toggleGateCreation(plr, cmd, model) if plr then local access = false for i=1, #managers do if managers[i] == getACC(plr) then access = true --triggerClientEvent(plr, "CUPgates.placeGate", plr) end end if access then bool = false for i=1, #allowedModels do if allowedModels[i] == tonumber(model) then bool = true end end if bool then triggerClientEvent(plr, "CUPgates.placeGate", plr, tonumber(model)) else outputChatBox("Invalid Gate ID ! ", plr, 255, 0, 0) end end end end addCommandHandler("addgate", toggleGateCreation) ----Gate System By Omar(aka.Darhal)---- ---- All Right Reserved --- local currentEditingGate local controling local label = {} local movingDoor = {} local movingDoorAccess = {} local accGrpColumn function centerWindow (center_window) local screenW, screenH = guiGetScreenSize() local windowW, windowH = guiGetSize(center_window, false) local x, y = (screenW - windowW) /2,(screenH - windowH) /2 guiSetPosition(center_window, x, y, false) end function placeGate(model) local x, y, z = getElementPosition(localPlayer) local rx, ry, rz = getElementRotation(localPlayer) currentEditingGate = createObject(model, x+1, y+1, z, rx, ry, rz) addEventHandler("onClientKey", root, onClientKey) addEventHandler("onClientRender", root, controlGate) guiSetVisible(gateWindow, true) guiGridListClear(accessToOpenGrid) showCursor(true) end addEvent("CUPgates.placeGate", true) addEventHandler("CUPgates.placeGate", root, placeGate) function saveGateData() if currentEditingGate then local groups = movingDoorAccess[currentEditingGate] local mvtType = movingDoor[currentEditingGate] local x, y, z = getElementPosition(currentEditingGate) local rx, ry, rz = getElementRotation(currentEditingGate) triggerServerEvent("CUPgates.sendGateData", localPlayer, groups, mvtType, {x, y, z}, {rx, ry, rz}, getElementModel(currentEditingGate)) movingDoorAccess[currentEditingGate] = nil movingDoor[currentEditingGate] = nil destroyElement(currentEditingGate) currentEditingGate = nil end end addCommandHandler("gsave", saveGateData) function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end function onClientKey(button, press) if press then pressedButton = button else pressedButton = nil end end addEventHandler("onClientResourceStart", resourceRoot, function() gateWindow = guiCreateWindow(288, 53, 260, 464, "CUP - Doors/Gates Management", false) centerWindow (gateWindow) guiWindowSetSizable(gateWindow, false) hideGUI(gateWindow) saveGateData = guiCreateButton(149, 428, 100, 26, "Save/Close", false, gateWindow) mvtLeft = guiCreateRadioButton(10, 47, 251, 18, "Move to left", false, gateWindow) mvtRight = guiCreateRadioButton(10, 71, 250, 18, "Move to right", false, gateWindow) mvtUp = guiCreateRadioButton(9, 95, 251, 18, "Move upside", false, gateWindow) mvtDown = guiCreateRadioButton(9, 123, 251, 18, "Move down", false, gateWindow) label[1] = guiCreateLabel(10, 26, 268, 15, "Possible gate/door moves :", false, gateWindow) label[2] = guiCreateLabel(15, 145, 263, 18, "Door/Gate access management :", false, gateWindow) accessToOpenGrid = guiCreateGridList(10, 180, 238, 189, false, gateWindow) accGrpColumn = guiGridListAddColumn(accessToOpenGrid, "Group", 0.9) accGrpEdit = guiCreateEdit(10, 393, 135, 26, "", false, gateWindow) addToAccessListBtn = guiCreateButton(149, 392, 94, 26, "Add", false, gateWindow) removeFromAccessListBtn = guiCreateButton(10, 428, 129, 26, "Remove", false, gateWindow) label[3] = guiCreateLabel(10, 374, 233, 18, "GROUP NAME:", false, gateWindow) addEventHandler("onClientGUIClick", saveGateData, closeDoorGUI, false) addEventHandler("onClientGUIClick", addToAccessListBtn, addToAccessList, false) addEventHandler("onClientGUIClick", removeFromAccessListBtn, removeFromAccessList, false) end ) function addToAccessList() local accountOrGroup = guiGetText(accGrpEdit) local givenAccessType = "Group" if accGrpEdit and accGrpEdit ~= "" then if not movingDoorAccess[currentEditingGate] then movingDoorAccess[currentEditingGate] = {} end for i, v in pairs(movingDoorAccess[currentEditingGate]) do if v.accGrp == accountOrGroup then exports.CUPtexts:output("This "..givenAccessType.." name ("..accountOrGroup..") already exsit in the list !", 255, 0, 0) return end end table.insert(movingDoorAccess[currentEditingGate], {accGrp=accountOrGroup}) updateDoorAccessGrid() end end function hideGUI(wnd) guiSetVisible(wnd, false) end function closeDoorGUI() local mvtType if guiRadioButtonGetSelected(mvtLeft) then mvtType = "mvtLeft" elseif guiRadioButtonGetSelected(mvtRight) then mvtType = "mvtRight" elseif guiRadioButtonGetSelected(mvtUp) then mvtType = "mvtUp" elseif guiRadioButtonGetSelected(mvtDown) then mvtType = "mvtDown" end local x, y, z = getElementPosition(currentEditingGate) local radius mvtValue = 7 movingDoor[currentEditingGate] = mvtType hideGUI(gateWindow) showCursor(false) end function updateDoorAccessGrid() if movingDoorAccess[currentEditingGate] then guiGridListClear(accessToOpenGrid) for i, v in pairs(movingDoorAccess[currentEditingGate]) do local row = guiGridListAddRow ( accessToOpenGrid ) guiGridListSetItemText ( accessToOpenGrid, row, accGrpColumn, v.accGrp, false, false) end end end function removeFromAccessList(button) if button ~= "left" then return end local row = guiGridListGetSelectedItem(accessToOpenGrid) if (not row or row == -1) then return end local accGrp = guiGridListGetItemText(accessToOpenGrid, row, accGrpColumn) for i, v in pairs(movingDoorAccess[currentEditingGate]) do if v.accGrp == accGrp then table.remove(movingDoorAccess[currentEditingGate], i) updateDoorAccessGrid() return end end end function getGateCorrectMVT(mvtType, id, door) local nx, ny, nz if mvtType == "mvtRight" then nx, ny, nz = getPositionFromElementOffset(door,0-mvtValue,0,0) elseif mvtType == "mvtLeft" then nx, ny, nz = getPositionFromElementOffset(door,mvtValue,0,0) elseif mvtType == "mvtUp" then nx, ny, nz = getPositionFromElementOffset(door,0, 0, 0-mvtValue) elseif mvtType == "mvtDown" then nx, ny, nz = getPositionFromElementOffset(door,0,0,mvtValue) end moveObject(door, 1000, nx, ny, nz) end addEvent("CUPgates.moveGate", true) addEventHandler("CUPgates.moveGate", root, getGateCorrectMVT) function getGateCorrectMVT(pos, id, door) local nx, ny, nz = pos[1], pos[2], pos[3] moveObject(door, 1000, nx, ny, nz) setTimer(setElementData, 1000, 1, door, "gateIsMoving", false) end addEvent("CUPgates.moveGateBack", true) addEventHandler("CUPgates.moveGateBack", root, getGateCorrectMVT) function controlGate() for k, v in ipairs(getElementsByType("gui-window", resourceRoot)) do if (guiGetVisible(v)) then return end end if isChatBoxInputActive () or not isElement(currentEditingGate) then return end local camera = getCamera () if not currentEditingGate or not (camera) then return end local cameraX,cameraY,cameraZ = getElementPosition(camera) local objectX,objectY,objectZ = getElementPosition(currentEditingGate) local x,y,z if pressedButton == "num_8" then x,y,z = getPositionFromElementOffset(camera,0,moveSpeed,0) controling = true cameraZ = z elseif pressedButton == "num_2" then x,y,z = getPositionFromElementOffset(camera,0,0-moveSpeed,0) controling = true cameraZ = z elseif pressedButton == "num_6" then x,y,z = getPositionFromElementOffset(camera,moveSpeed,0,0) controling = true cameraZ = z elseif pressedButton == "num_4" then x,y,z = getPositionFromElementOffset(camera,0-moveSpeed,0,0) controling = true cameraZ = z elseif pressedButton == "pgup" then x,y,z = getPositionFromElementOffset(camera,0,0, moveSpeed) controling = true elseif pressedButton == "pgdn" then x,y,z = getPositionFromElementOffset(camera,0,0, 0-moveSpeed) controling = true elseif pressedButton == "num_add" then rx, ry, rz = getElementRotation(currentEditingGate) setElementRotation(currentEditingGate, rx, ry, rz+angleSpeed) controling = true elseif pressedButton == "num_sub" then rx, ry, rz = getElementRotation(currentEditingGate) setElementRotation(currentEditingGate, rx, ry, rz-angleSpeed) controling = true elseif pressedButton == "num_7" then rx, ry, rz = getElementRotation(currentEditingGate) setElementRotation(currentEditingGate, rx+angleSpeed, ry, rz) controling = true elseif pressedButton == "num_9" then rx, ry, rz = getElementRotation(currentEditingGate) setElementRotation(currentEditingGate, rx-angleSpeed, ry, rz) controling = true elseif pressedButton == "num_1" then rx, ry, rz = getElementRotation(currentEditingGate) setElementRotation(currentEditingGate, rx, ry+angleSpeed, rz) controling = true elseif pressedButton == "num_3" then rx, ry, rz = getElementRotation(currentEditingGate) setElementRotation(currentEditingGate, rx, ry-angleSpeed, rz) controling = true else controling = false end if x then setElementPosition(currentEditingGate, objectX+(x-cameraX),objectY+(y-cameraY),objectZ+(z-cameraZ)) end end --- GATE SYSTEM BY DARHAL --- moveSpeed = 0.1 -- HOW MUCH GATE SHOULD MOVE WHEN CONTROLING IT angleSpeed = 1 -- THE ROTATION SPEED WHEN ROTATING THE GATE mvtValue = 7 -- THE DISTANCE THAT THE GATE MOVE WHEN SOMEONE IS NEARBY IT about learning i learned much i swear kariim and all thanks to u cuz u made me try to learn again thanks you so much Link to comment
KariiiM Posted January 19, 2016 Share Posted January 19, 2016 Anyway, Speaks about the situation of the code, what's wrong with it? Link to comment
Chris!i! Posted January 19, 2016 Share Posted January 19, 2016 You can't use getPlayerGroup, does your group system have an export called getPlayerGroup ? Link to comment
Best-Killer Posted January 19, 2016 Author Share Posted January 19, 2016 You can't use getPlayerGroup, does your group system have an export called getPlayerGroup ? for player group work fine -.- i want just make gates opened for staff Anyway, Speaks about the situation of the code, what's wrong with it?0 errors and gate not opened for staffs Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now