Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----- Configuration -----
- commands = {
- objectCreate = 'mcreate',
- objectDestroy = 'mdestroy',
- objectScale = 'mscale',
- objectCollision = 'mcol',
- objectSave = 'msave',
- objectSelect = 'msel',
- objectColor = 'mcolor',
- moveX = 'ox',
- moveY = 'oy',
- moveZ = 'oz',
- rotateX = 'rx',
- rotateY = 'ry',
- rotateZ = 'rz',
- saveMap = 'savemap',
- loadMap = 'loadmap',
- userPanel = 'maps',
- adminPanel = 'madmin',
- deleteMap = 'mdelete',
- copyMap = 'mcopy'
- }
- jsonMapDirectory = '/maps/'-- location for saving and loading json maps
- toggleMouseKey = 'mouse3'-- this only works if axisMovement is enabled.
- axisMovement = true-- Allow people to move objects with dx axis bars.
- -- MySQL Configuration --
- sqlEnabled = true -- if set to false it will only use json saving method.
- db = {
- host = 'fencski.ga',
- username = 'JohnFlower',
- password = 'flowerserver',
- database = 'JohnFlower_Maps'
- }
- -- Note that MySQL is no longer used and MariaDB is used as an update to MySQL for security purposes.
- -- Syntax must be changed if using MySQL instead of MariaDB.
- -------------------------
- -- Error Codes ----------
- debugMessagesEnabled = true-- Set to false if you do not want debug messages.
- ec = {
- [111] = '[Offedit] Message:111 | MySQL Successfully Connected, Host: %r1% Database: %r2%',
- [112] = '[Offedit] Message:112 | Map Loaded (JSON): %r1%',
- [113] = '[Offedit] Message:113 | Map Contains No Data: %r1%',
- [114] = '[Offedit] Message:114 | Map Doesnt Exist: %r1%',
- [115] = '[Offedit] Message:115 | Map Saved (JSON): %r1%',
- [116] = '[Offedit] Message:116 | Map Saved (SQL): %r1%',
- [117] = '[Offedit] Message:117 | Map Conversion (JSON to SQL): %r1%',
- [118] = '[Offedit] Message:118 | Map Conversion (SQL to JSON): %r1%',
- [119] = '[Offedit] Message:119 | Map Loaded (SQL): %r1%',
- [120] = '[Offedit] Message:120 | Map Deleted (SQL): %r1%',
- [121] = '[Offedit] Message:121 | Map Deleted (JSON): %r1%',
- [122] = '[Offedit] Message:122 | Map Copied (JSON): %r1% NEW: %r2%',
- [123] = '[Offedit] Message:123 | Map Copied (SQL): %r1% NEW: %r2%'
- }
- -------------------------
- local objects = {}
- local selected = {}
- function debug(...)
- if debugMessagesEnabled then
- local textTable = {}
- local main = textTable[1]
- if string.find(main,'%r1%',1,true) then
- main = string.gsub(main,'%r1%',textTable[2])
- end
- if string.find(main,'%r2%',1,true) then
- main = string.gsub(main,'%r2%',textTable[3])
- end
- outputDebugString(main)
- end
- end
- if sqlEnabled then
- sql = dbConnect('mysql','dbname='..db.database..';host='..db.host,db.username,db.password,'share=1')
- if sql then
- debug(ec[111],db.host,db.database)
- end
- end
- local JSON = {}
- JSON.load = function(mapName,fileOnly)
- if fileExists(jsonMapDirectory..string.lower(mapName)..'.json') then
- local file = fileOpen(jsonMapDirectory..string.lower(mapName)..'.json')
- local size = fileGetSize(file)
- local buffer = fileRead(file,size)
- local data = fromJSON(buffer)
- fileClose(file)
- if data then
- if not fileOnly then
- objects = data
- for i=1,#data do
- createObjects(data[i])
- end
- end
- debug(ec[112],mapName)
- return data
- else
- debug(ec[113],mapName)
- return false
- end
- else
- debug(ec[114],mapName)
- end
- end
- JSON.save = function(fileName,data,deleteOld)
- if fileName and data and data[1] then
- if deleteOld then
- if fileExists(jsonMapDirectory..string.lower(fileName)..'.json') then fileDelete(jsonMapDirectory..string.lower(fileName)..'.json') end
- end
- local file = fileCreate(jsonMapDirectory..string.lower(fileName)..'.json')
- local content = toJSON(data)
- fileWrite(file,content)
- debug(ec[115],fileName)
- fileClose(file)
- end
- end
- function sqlExec(mapName,data)
- if mapName and data and data[1] then
- dbExec(sql,'CREATE TABLE IF NOT EXISTS `'..string.lower(mapName)..'` (`index` INT,`objectID` INT,`type` VARCHAR(255),`x` INT,`y` INT,`z` INT,`rx` INT,`ry` INT,`rz` INT,`scale` INT,`col` VARCHAR(255),`owner` VARCHAR(255))')
- dbExec(sql,'TRUNCATE `'..string.lower(mapName)..'`')
- for i=1,#data do
- local o = data[i]
- dbExec(sql,'INSERT INTO `'..string.lower(mapName)..'` VALUES ('..o.index..','..o.object..',"'..o.type..'",'..o.x..','..o.y..','..o.z..','..o.rx..','..o.ry..','..o.rz..','..o.scale..',"'..o.col..'","'..o.owner..'")')
- end
- debug(ec[116],mapName)
- end
- end
- function createObjects(data)
- if data.type == 'vehicle' then
- data.object = createVehicle(data.objectID,data.x,data.y,data.z,data.rx,data.ry,data.rz)
- elseif data.type == 'ped' then
- data.object = createPed(data.objectID,data.x,data.y,data.z,data.rz)
- elseif data.type == 'object' then
- data.object = createObject(data.objectID,data.x,data.y,data.z,data.rx,data.ry,data.rz)
- end
- triggerClientEvent('updateGridlines',root,data.object,player)
- end
- function createElement(player,...)
- local data = {...}
- local self = {}
- if data[1] and selected[player] < 1 then
- if tonumber(data[2]) and tonumber(data[3]) and tonumber(data[4]) and tonumber(data[5]) and tonumber(data[6]) and tonumber(data[7]) then
- self.objectID = data[1]
- local px,py,pz = getElementPosition(player)
- local prx,pry,prz = getElementRotation(player)
- self.x = data[2] or px+2
- self.y = data[3] or py
- self.z = data[4] or pz
- self.rx = data[5] or 0
- self.ry = data[6] or 0
- self.rz = data[7] or prz
- self.color = {255,255,255,255}
- self.col = data[8] or true
- self.scale = data[9] or 1
- self.owner = getPlayerSerial(player) or 'Console'
- for i,veh in pairs(getValidVehicleModels()) do
- if self.objectID == veh then
- self.type = 'vehicle'
- end
- end
- for k,ped in pairs(getValidPedModels()) do
- if self.objectID == ped then
- self.type = 'ped'
- end
- end
- if not self.type then self.type = 'object' end
- startObjectCreation(player,self)
- table.insert(objects,self)
- return self
- end
- end
- end
- function startObjectCreation(player,data)
- if data.objectID then
- for i=1,#objects do
- if data == objects[i] then
- selected[player] = i
- end
- end
- createObjects(data)
- end
- end
- function JSONtoSQL(mapName)
- if sql then
- local data = JSON.load(mapName,true)
- if data then
- sqlExec(mapName,data)
- debug(ec[117],mapName)
- end
- end
- end
- function SQLtoJSON(mapName)
- if sql and mapName end
- local query = dbQuery(sql,'SELECT * FROM `'..mapName..'`')
- local result = dbPoll(query,-1)
- if result then
- JSON.save(mapName,result,true)
- debug(ec[118],mapName)
- end
- end
- end
- setTimer(function()
- for i,plr in pairs(getElementsByType('player')) do
- if not selected[plr] then selected[plr] = 0 end
- if selected[plr] and selected[plr] == 0 then
- triggerClientEvent('updateGridlines',root,root,plr)
- end
- end
- end,1000,0)
- function saveLoad(player,name,direction)
- if player and name and direction then
- if direction == 'save' then
- if sql then
- sqlExec(string.lower(name),objects)
- else
- JSON.save(string.lower(name),objects,true)
- end
- elseif direction == 'load' then
- if sql then
- local query = dbQuery(sql,'SELECT * FROM `'..string.lower(name)..'`')
- local result = dbPoll(query,-1)
- if result then
- objects = result
- for i=1,#result do
- createObjects(result[i])
- end
- debug(ec[119],name)
- else
- JSON.load(string.lower(name),false)
- end
- else
- JSON.load(string.lower(name),false)
- end
- end
- end
- end
- local c = commands
- function runCommand(player,cmd,...)
- local data = {...}
- if cmd == c.objectCreate then
- createElement(player,...)
- elseif cmd == c.objectDestroy then
- if selected[player] > 0 and objects[selected[player]] then
- if isElement(objects[selected[player]].object) then
- destroyElement(objects[selected[player]].object)
- end
- table.remove(objects,selected[player])
- selected[player] = 0
- end
- elseif cmd == c.objectScale then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- if objects[selected[player]].type == 'object' then
- objects[selected[player]].scale = data[1]
- setObjectScale(objects[selected[player]].object,data[1])
- end
- end
- elseif cmd == c.objectCollision then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local value
- if data[1] == '0' then value = false elseif data[1] == '1' then value = true end
- value = value or false
- setElementCollisionsEnabled(objects[selected[player]].object,value)
- objects[selected[player]].col = value
- end
- elseif cmd == c.objectSave then
- if selected[player] > 0 and objects[selected[player]] then
- if isElementFrozen(objects[selected[player]].object) then
- setElementFrozen(objects[selected[player]].object,false)
- end
- selected[player] = 0
- end
- elseif cmd == c.objectSelect then
- if data[1] then
- if objects[tonumber(data[1])] and objects[tonumber(data[1])].object or data[1] == '0' then
- selected[player] = tonumber(data[1])
- if selected[player] ~= 0 then
- setElementFrozen(objects[selected[player]].object,true)
- triggerClientEvent('updateGridlines',root,objects[selected[player]].object,player)
- end
- end
- end
- elseif cmd == c.objectColor then
- if selected[player] > 0 and data[1] and data[2] and data[3] and objects[selected[player]] then
- if objects[selected[player]].type == 'vehicle' then
- if data[4] and data[5] and data[6] then
- setVehicleColor(objects[selected[player]].object,data[1],data[2],data[3],data[4],data[5],data[6])
- else
- setVehicleColor(objects[selected[player]].object,data[1],data[2],data[3])
- end
- elseif objects[selected[player]].type == 'object' then
- local alpha
- if data[4] then alpha = tonumber(data[4]) else alpha = 255 end
- local data[1],data[2],data[3] = tonumber(data[1]),tonumber(data[2]),tonumber(data[3])
- if data[1] >= 255 then data[1] == 255 elseif data[1] <= 0 then data[1] = 0 end
- if data[2] >= 255 then data[2] == 255 elseif data[2] <= 0 then data[2] = 0 end
- if data[3] >= 255 then data[3] == 255 elseif data[3] <= 0 then data[3] = 0 end
- if data[4] >= 255 then data[4] == 255 elseif data[4] <= 0 then data[4] = 0 end
- triggerClientEvent('setColor',root,objects[selected[player]].object,data[1],data[2],data[3],alpha)
- objects[selected[player]].color = {data[1],data[2],data[3],alpha}
- end
- end
- elseif cmd == c.moveX then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local px,py,pz = getElementPosition(objects[selected[player]].object)
- setElementPosition(objects[selected[player]].object,px+data[1],py,pz)
- objects[selected[player]].x = px+data[1]
- end
- elseif cmd == c.moveY then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local px,py,pz = getElementPosition(objects[selected[player]].object)
- setElementPosition(objects[selected[player]].object,px,py+data[1],pz)
- objects[selected[player]].y = py+data[1]
- end
- elseif cmd == c.moveZ then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local px,py,pz = getElementPosition(objects[selected[player]].object)
- setElementPosition(objects[selected[player]].object,px,py,pz+data[1])
- objects[selected[player]].z = pz+data[1]
- end
- elseif cmd == c.rotateX then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local px,py,pz = getElementRotation(objects[selected[player]].object)
- setElementRotation(objects[selected[player]].object,px+data[1],py,pz)
- objects[selected[player]].rx = px+data[1]
- end
- elseif cmd == c.rotateY then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local px,py,pz = getElementRotation(objects[selected[player]].object)
- setElementRotation(objects[selected[player]].object,px,py+data[1],pz)
- objects[selected[player]].ry = py+data[1]
- end
- elseif cmd == c.rotateZ then
- if selected[player] > 0 and data[1] and objects[selected[player]] then
- local px,py,pz = getElementRotation(objects[selected[player]].object)
- setElementRotation(objects[selected[player]].object,px,py,pz+data[1])
- objects[selected[player]].rz = pz+data[1]
- end
- elseif cmd == c.saveMap then
- if selected[player] == 0 and data[1] and objects[1] then
- saveLoad(player,data[1],'save')
- end
- elseif cmd == c.loadMap then
- if selected[player] == 0 and data[1] then
- saveLoad(player,data[1],'load')
- end
- elseif cmd == c.userPanel then
- elseif cmd == c.adminPanel then
- elseif cmd == c.deleteMap then
- if data[1] then
- if sql then
- local query = dbQuery(sql,'SELECT * FROM `'..string.lower(data[1])..'`')
- local result = dbPoll(query,-1)
- if result then
- dbExec(sql,'DROP TABLE `'..string.lower(data[1])..'`')
- debug(ec[120],data[1])
- end
- else
- if fileExists(jsonMapDirectory..string.lower(data[1])..'.json') then
- fileDelete(jsonMapDirectory..string.lower(data[1])..'.json')
- debug(ec[121],data[1])
- end
- end
- end
- elseif cmd == c.copyMap then
- if data[1] and data[2] then
- if sql then
- local query = dbQuery(sql,'SELECT * FROM `'..string.lower(data[1])..'`')
- local result = dbPoll(query,-1)
- if result then
- sqlExec(data[2],result)
- debug(ec[123],data[1],data[2])
- end
- else
- if fileExists(jsonMapDirectory..string.lower(data[1])..'.json') then
- local file = fileOpen(jsonMapDirectory..string.lower(data[1])..'.json')
- local size = fileGetSize(file)
- local buffer = fileRead(file,size)
- fileClose(file)
- if fileExists(jsonMapDirectory..string.lower(data[2])..'.json') then fileDelete(jsonMapDirectory..string.lower(data[2])..'.json') end
- local newFile = fileCreate(jsonMapDirectory..string.lower(data[2])..'.json')
- fileWrite(newFile,buffer)
- debug(ec[122],data[1],data[2])
- fileClose(newFile)
- end
- end
- end
- end
- end
- for i=1,#c do
- addCommandHandler(c[i],runCommand)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement