shaio

Members
  • Content Count

    117
  • Joined

  • Last visited

Everything posted by shaio

  1. I made a table on server side global. I want to access that table on client side.. How do I do this? Please help me. meta.xml - <meta> <script src="server.lua" type="server"/> <script src="client.lua" type="client"/> </meta> server.lua - root = getRootElement() rotators = {} rotatorSet = createObject(13646,0,0,-10,0,0,0) index = 0 addEventHandler("onResourceStart",root,function() setTimer(rotateSetObject,30000,0) setTimer(rotateSecond,30000,0) end) function rotateSetObject() local px,py,pz = getElementPosition(rotatorSet) local prx,pry,prz = getElementRotation(rotatorSet) moveObject(rotatorSet,30000,px,py,pz,0,0,prz+180) end function rotateFirst() for i,u in pairs(rotators) do local x,y,z = getElementPosition(u.object) local rx,ry,rz = getElementRotation(rotatorSet) moveObject(u.object,10,x,y,z,0,0,rz) setObjectScale(u.object,1.1) attachElements(u.vehicle,u.object,0,0,1.5,0,0,0) end end function rotateSecond() for i,v in pairs(rotators) do local sx,sy,sz = getElementPosition(v.object) local prx,pry,prz = getElementRotation(rotatorSet) moveObject(v.object,30000,sx,sy,sz,0,0,prz+180) end end function createRotator(player,cmd,id) if not isPedInVehicle(player) then local x,y,z = getElementPosition(player) table.insert(rotators,{id = index+1,object = createObject(13646,x,y,z-1.4,0,0,0),vehicle = createVehicle(id,x,y,z+2)}) for i,v in pairs(rotators) do attachElements(v.vehicle,v.object,0,0,1.5,0,0,0) setObjectScale(v.object,1.1) setElementData(v.vehicle,"rotateCar",true) end setElementPosition(player,x,y,z+1.2) setTimer(rotateFirst,30000,1) index = index+1 end end addCommandHandler("crotate",createRotator) addEventHandler("onVehicleStartEnter",root,function(player,seat) if (getElementData(source,"rotateCar") == true) then cancelEvent() outputChatBox("You may not enter this vehicle!",player,255,0,0,true) end end) addCommandHandler("clearrotators",function() setTimer(function() for i,p in pairs(rotators) do destroyElement(p.vehicle) destroyElement(p.object) end for _,plr in ipairs(getElementsByType("player")) do outputChatBox("All rotators have been destroyed!",plr,255,0,0,true) end end,10000,1) end) function update(player,cmd) local rx,ry,rz = getElementRotation(rotatorSet) for i,c in ipairs(rotators) do setElementRotation(c.object,0,0,rz) end end addCommandHandler("updater",update) client.lua - localPlayer = getLocalPlayer() function createText() for i,o in pairs(rotators) do local x,y,z = getElementPosition(o.vehicle) local sx,sy = getScreenFromWorldPosition(x,y,z+1) dxDrawText("ID: "..tostring(o.id),sx/2,sy/2,sx,sy,tocolor(255,255,255,255),1,"pricedown") end end function renderText() addEventHandler("onClientRender",root,createText) end addEventHandler("onClientResourceStart",root,renderText)
  2. Cody wtf. Sponge talk to me bro. Email: fencski@hotmail.com or shay@ffroam.rf.gd Phone: +1(920)-994-9678 Skype: cemour.burkoff or shay.fencski or message me on here.
  3. shaio

    Saving Maps

    Hello, I've downloaded offroader23's in-game map editor (offedit) from the community, and I've added one of my old save systems to it, and it doesn't wanna work. I have talked to offroader about this and he can't fix it, I'm just expanding for help.. Here is the full code. Note that it is the only load and save portion of the code that I edited. commands "loadmap" and "savemap" those are what you wanna look at. local playerobj = {} objectid = {} maxobjects = 500 function playerLeave () setElementData ( source, "tempbuilder", false ) setElementData ( source, "permbuilder", false ) end function playerJoin () setElementData ( source, "tempbuilder", false ) setElementData ( source, "permbuilder", false ) local pname = getPlayerName(source) if (pname == "example") or (pname == "example2") then setElementData ( source, "permbuilder", true ) end end function thisResourceStart () local players = getElementsByType ( "player" ) for k,v in ipairs(players) do setElementData ( v, "tempbuilder", false ) setElementData ( v, "permbuilder", false ) local pname = getPlayerName(v) if (pname == "example") or (pname == "example2") then setElementData ( v, "permbuilder", true ) end end end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), thisResourceStart ) addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin ) addEventHandler ( "onPlayerQuit", getRootElement(), playerLeave ) function guestBuildPlayer ( player, commandName, player2nick ) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) then local player2 = getPlayerFromName ( player2nick ) local player2n = getPlayerName ( player2 ) if (getElementData ( player2, "tempbuilder" ) == false) then outputChatBox ( "#FFFF00"..player2n.." recieved map editor pass.", getRootElement(), 255, 255, 255, true ) setElementData ( player2, "tempbuilder" , true ) else outputChatBox ( "#FFFF00"..player2n.." map editor pass removed.", getRootElement(), 255, 255, 255, true ) setElementData ( player2, "tempbuilder" , false ) end else outputChatBox ( "You do not have permission to do that.", player ) end end addCommandHandler("guestb", guestBuildPlayer ) function createCurrentObject (player,cmd,objid) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then outputChatBox ( "You are already editing an object. Please save or delete to make another.", player ) else local x, y, z = getElementPosition(player) destroyMObj (player) playerobj[player] = createObject(tonumber(objid), x + 5, y + 5, z - 1) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "mcreate", createCurrentObject ) function cloneCurrentObject (player, cmd, addx, addy, addz, addrx, addry, addrz) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if addx then addx = tonumber(addx) else addx = 0 end if addy then addy = tonumber(addy) else addy = 0 end if addz then addz = tonumber(addz) else addz = 0 end if addrx then addrx = tonumber(addrx) else addrx = 0 end if addry then addry = tonumber(addry) else addry = 0 end if addrz then addrz = tonumber(addrz) else addrz = 0 end if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) local rx, ry, rz = getObjectRotation(playerobj[player]) local model = getElementModel ( playerobj[player] ) saveObjID(player) playerobj[player] = createObject(model, x + addx, y + addy, z + addz, rx + addrx, ry + addry, rz + addrz) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "mclone", cloneCurrentObject ) function stackCurrentObject (player, cmd, times, addx, addy, addz, addrx, addry, addrz) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if tonumber(times) < 50 and addx then times = tonumber(times) addx = tonumber(addx) if addy then addy = tonumber(addy) else addy = 0 end if addz then addz = tonumber(addz) else addz = 0 end if addrx then addrx = tonumber(addrx) else addrx = 0 end if addry then addry = tonumber(addry) else addry = 0 end if addrz then addrz = tonumber(addrz) else addrz = 0 end if playerobj[player] then for i=0,times do local x, y, z = getElementPosition(playerobj[player]) local rx, ry, rz = getObjectRotation(playerobj[player]) local model = getElementModel ( playerobj[player] ) saveObjID(player) playerobj[player] = createObject(model, x + addx, y + addy, z + addz, rx + addrx, ry + addry, rz + addrz) end end else outputChatBox ( "Failed to stack object. You can only stack up to 50 items at once. Also make sure you at least specified an X value.", player ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "mstack", stackCurrentObject ) function loopCurrentObject (player, cmd, pieces, radi, offset, rotaxis, loops, rota) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then local angle local newi if loops then loops = tonumber(loops) else loops = 1 end if rota then rota = rota*(math.pi/180) else rota = 0 end if rotaxis == "x" or rotaxis == "-x" or rotaxis == "y" or rotaxis == "-y" then --do nothing else rotaxis = "x" end if radi and pieces and offset then radi = tonumber(radi) pieces = tonumber(pieces) offset = tonumber(offset) local spiralp = math.atan((offset/2)/(2*radi))/loops if playerobj[player] then local orx, ory, orz = getElementPosition(playerobj[player]) newi = -1 for i=0,pieces do local x, y, z = getElementPosition(playerobj[player]) local rx, ry, rz = getObjectRotation(playerobj[player]) local model = getElementModel ( playerobj[player] ) saveObjID(player) local weight = 1-(1/(pieces/2))*math.abs((pieces/2)-i) local radians = (i/pieces)*(2*math.pi)*loops local newx = orx + radi*math.sin(radians)*math.cos(rota)+(offset/2)*math.cos(radians/(2*loops))*-math.sin(rota) local newy = ory +(offset/2)*math.cos(radians/(2*loops))*math.cos(rota)+radi*math.sin(radians)*math.sin(rota) local newz = orz + radi*-math.cos(radians) angle = (((360/pieces)* loops )* newi) if angle <= 359.9999999999999999999999999 then newi = newi + 1 end angle = (((360/pieces)* loops )* newi) if angle >= 360 then newi = -1 angle = (((360/pieces)* loops )* newi) end if rotaxis == "x" then newrotx = angle newroty = ry --+ ((radians)-math.cos(rota)*spiralp*weight) elseif rotaxis == "-x" then newrotx = -angle newroty = ry --+ ((radians)-math.cos(rota)*spiralp*weight) elseif rotaxis == "y" then newrotx = rx --+ ((radians)-math.cos(rota)*spiralp*weight) newroty = angle elseif rotaxis == "-y" then newrotx = rx --+ ((radians)-math.cos(rota)*spiralp*weight) newroty = -angle end playerobj[player] = createObject(model, newx, newy, newz, newrotx, newroty, rz) end end else outputChatBox ( "Failed to make loop. Use /mloop <radius> <pieces> <offset>", player ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "mloop", loopCurrentObject ) function moveObjZ (player,cmd,newz) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) moveObject ( playerobj[player], 200, x, y, z + tonumber(newz) ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "oz", moveObjZ ) function moveObjX (player,cmd,newx) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) moveObject ( playerobj[player], 200, x + tonumber(newx), y, z ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "ox", moveObjX ) function moveObjY (player,cmd,newy) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) moveObject ( playerobj[player], 200, x, y + tonumber(newy), z ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "oy", moveObjY ) function moveRotZ (player,cmd,newrz) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) moveObject ( playerobj[player], 200, x, y, z, 0, 0, tonumber(newrz) ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "rz", moveRotZ ) function moveRotX (player,cmd,newrx) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) moveObject ( playerobj[player], 200, x, y, z, tonumber(newrx), 0, 0 ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "rx", moveRotX ) function moveRotY (player,cmd,newry) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local x, y, z = getElementPosition(playerobj[player]) moveObject ( playerobj[player], 200, x, y, z, 0, tonumber(newry), 0 ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "ry", moveRotY ) function destroyMObj (player,cmd) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then for i=0,maxobjects do if objectid[i] == playerobj[player] then local numstr = tostring(i) outputChatBox ( "Object ID deleted: " ..numstr.. "", player ) local succeed = destroyElement(playerobj[player]) objectid[i] = nil playerobj[player] = nil break end end end if playerobj[player] then destroyElement(playerobj[player]) end playerobj[player] = nil else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "mdestroy", destroyMObj ) function openTheFile(objFile) local mapFile = fileOpen ( "objects.txt" ) if not mapFile then outputChatBox ( "objects.txt not Found...") mapFile = fileCreate( "objects.txt" ) fileWrite (mapFile, "--Objects Script Created\r\n\r\n") outputChatBox ( "File Created") end return mapFile end function commentFix ( comment ) if not ( comment ) then comment = "na" end return comment end function saveObjID ( player, cmd ) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then for i=0,maxobjects do if objectid[i] == playerobj[player] then local numstr = tostring(i) outputChatBox ( "Object saved as ID: " ..numstr.. "", player ) playerobj[player] = nil break elseif objectid[i] then --do nothing else objectid[i] = playerobj[player] local numstr = tostring(i) outputChatBox ( "Object saved as ID: " ..numstr.. "", player ) playerobj[player] = nil break end end end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "msave", saveObjID ) function selectObject ( player, cmd, selid ) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then num = tonumber(selid) if playerobj[player] then saveObjID(player) outputChatBox ( "You were editing an object. It was saved as ID: " ..selid.. "", player ) end if objectid[num] then playerobj[player] = objectid[num] local x, y, z = getElementPosition(playerobj[player]) outputChatBox ( "Object ID selected: " ..selid.. "", player ) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "msel", selectObject ) function getEndOFile(mapFile) local temp, endPos = fileGetPos ( mapFile ) while not fileIsEOF ( mapFile ) do fileRead ( mapFile, 500 ) end endPos = fileGetPos ( mapFile ) fileSetPos ( mapFile, temp ) return endPos end function getObjInfo ( player) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then if playerobj[player] then local model = getElementModel (playerobj[player]) local x, y, z = getElementPosition(playerobj[player]) local rx, ry, rz = getObjectRotation(playerobj[player]) outputChatBox ( "Object Info - Object Model ID: " .. model .. "", player) outputChatBox ( "Pos X: " .. x .. " Pos Y: " .. y .. " Pos Z: " .. z .. "", player) outputChatBox ( "Rot X: " .. rx .. " Rot Y: " .. ry .. " Rot Z: " .. rz .. "", player) else outputChatBox ( "You currently have no object selected.", player) end else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "minfo", getObjInfo ) function saveObjPOS ( player, cmd, comment ) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then comment = commentFix ( comment ) local model = getElementModel ( playerobj[player] ) local x, y, z = getElementPosition(playerobj[player]) local rx, ry, rz = getObjectRotation(playerobj[player]) local pname = getPlayerName(player) local objFile = fileOpen ( "objects.txt" ) if objFile then local endPos = getEndOFile (objFile) fileSetPos(objFile, endPos) else outputChatBox ( "objects.txt not Found...") objFile = fileCreate( "objects.txt" ) fileSetPos(objFile, 0) fileWrite (objFile, "--Objects Script Created Using OffRoader23's In Game Editor\r\n\r\n") outputChatBox ( "File Created") end fileWrite ( objFile, "createObject(" .. model .. ", " .. x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz .. ") --" .. comment .. " " .. pname .. "\r\n") outputChatBox ( "Object Saved as: " ..comment.. "", player ) fileClose ( objFile ) saveObjID (player) else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "saveobj", saveObjPOS ) function saveMap(player,cmd,mapName) local account = getPlayerAccount(player) if (isGuestAccount(account) == true) then outputChatBox("You need to be logged in to use this!", player, 0, 255, 255) return end if mapName then if not string.find(mapName, '%W') then if (getElementData(player,"tempbuilder") == true) then if playerobj then if #playerobj >= 1 then local tempdata = {} tempdata['info'] = {} tempdata['info']['creator'] = getPlayerName(player) tempdata['info']['serial'] = getPlayerSerial(player) tempdata['info']['ip'] = getPlayerIP(player) tempdata['info']['dimension'] = getElementDimension(playerobj[i]) for _,i in ipairs(playerobj[player]) do if playerobj[player][i] then tempdata[i] = {} tempdata[i]['model'] = getElementModel(playerobj[i]) tempdata[i]['col'] = getElementCollisionsEnabled(playerobj[i]) local x, y, z = getElementPosition(playerobj[i]) local rx, ry, rz = getElementRotation(playerobj[i]) tempdata[i]['pos'] = {x, y, z, rx, ry, rz} local scalex, scaley, scalez = getObjectScale(playerobj[i]) tempdata[i]['scale'] = {scalex, scaley, scalez} tempdata[i]['type'] = 'object' end end local file = fileCreate('maps/'..mapName..'.json') fileWrite(file, toJSON(tempdata)) fileClose(file) tempdata = {} outputChatBox('Saved map as '..mapName, player, 0, 255, 255) end end end else outputChatBox('Invalid map name.', player, 0, 255, 255) end else outputChatBox('SYNTAX: /savemap name', player, 0, 255, 255) end end addCommandHandler("savemap",saveMap) function loadMap(player,cmd,mapName) local account = getPlayerAccount(player) if (isGuestAccount(account) == true) then outputChatBox("You need to be logged in to use this!", player, 0, 255, 255) return end if fileExists('maps/'..mapName..'.json') then if isElement(player) then outputChatBox('Map loaded: '..mapName, player, 0, 255, 255) name = getPlayerName(player) else name = 'the server' end local file = fileOpen('maps/'..mapName..'.json') local size = fileGetSize(file) local buffer = fileRead(file, size) local tempdata = fromJSON(buffer) fileClose(file) for k,v in pairs (tempdata) do if k ~= 'info' then local id = tonumber(k) local ids = tostring(k) local x, y, z, rx, ry, rz = unpack(tempdata[id]['pos']) playerobj[id] = createObject(tempdata[ids]['model'], x, y, z, rx, ry, rz) scalex, scaley, scalez = unpack(tempdata[ids]['scale']) setObjectScale(playerobj[id], scalex, scaley, scalez) setElementCollisionsEnabled(playerobj[id], tempdata[ids]['col']) end end else outputChatBox("Map "..mapName.." failed to load.", player, 0, 255, 255) end end addCommandHandler("loadmap",loadMap) function clearObjects (player) if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) then for i=0,maxobjects do if objectid[i] then destroyElement(objectid[i]) end end objectid = nil objectid = {} local players = getElementsByType ( "player" ) for k,v in ipairs(players) do if playerobj[v] then destroyElement(playerobj[v]) end playerobj[v] = nil end if playerobj[player] then destroyElement(playerobj[player]) end playerobj[player] = nil outputChatBox ( "Map cleared.", player ) else outputChatBox ( "You do not have permission to build.", player ) end end addCommandHandler( "mclear", clearObjects ) There are no errors in console or debugscript.
  4. shaio

    Phone System

    For now I just want to show the dx gui when near a payphone, and I did try getElementModel(), it still doesn't work.
  5. shaio

    Phone System

    But by doing this for _,phone in ipairs(getElementsByType("Object")) do if (getObjectModel(phone) == 1216) or (getObjectModel(phone) == 1363) then it grabs all of the phone OBJECTS in the map, whether they are added by map, script or not added at all.. The script doesn't work yet
  6. shaio

    Phone System

    I need help creating a phone system with dx GUI, I can't get it to work, this is my code so far.. Please help me out Client.lua - addEventHandler("onClientRender",root,function() for _,phone in ipairs(getElementsByType("Object")) do if (getObjectModel(phone) == 1216) or (getObjectModel(phone) == 1363) then local x,y,z = getElementPosition(getLocalPlayer()) local vx,vy,vz = getElementPosition(phone) if (getDistanceBetweenPoints3D(x,y,z,vx,vy,vz) <= 4) then addEventHandler("onClientRender",root,function() dxDrawLine(18 - 1, 536, 286, 536, tocolor(0, 0, 0, 254), 1, false) dxDrawLine(286, 536, 286, 479 - 1, tocolor(0, 0, 0, 254), 1, false) dxDrawRectangle(18, 479, 268, 57, tocolor(0, 0, 16, 238), false) dxDrawImage(28, 487, 44, 39, "/images/phone.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawText("Press E to use the phone.", 78, 487, 276, 526, tocolor(236, 233, 0, 254), 0.45, "bankgothic", "center", "center", false, false, false, false, false) end) end end end end) Meta.xml - <meta> <script src="client.lua" type="client"/> <file src="images/phone.png"/> </meta> phone.png -
  7. Yes this works, although you set most of the messages up in client-side format. I fixed those Otherwise, works great! Thank you.
  8. There are no errors posted in debugscript or console... This is just the share part of the script.. local players = {} function share(player,cmd,otherPlayer) if isPedInVehicle(player) then if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then if players[getPedOccupiedVehicle(player)] then for _,carA in pairs(players[getPedOccupiedVehicle(player)]) do if getPlayerSerial(player) ~= carA then if not getPlayerSerial(getPlayerFromName(otherPlayer)) ~= carA then local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.insert(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle shared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has granted you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) else local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.removeValue(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle unshared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has denied you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) end end end end else outputChatBox("You need to be the driver!",player,255,0,0) end end end addCommandHandler("share",share) function table.removeValue(table, val) for index, value in ipairs(table) do if value == val then table.remove(table, index) return index end end return false end
  9. i want to save offedit maps inside of json files, with all the properties of the objects, meaning scale, position, rotation, collidable(true/false) etc..
  10. How do I get this to work with offedit? I've tried and tried and tried. I really wanna save to json files. :L addCommandHandler('savemap', function (player, command, mapName) local account = getPlayerAccount(player) if (isGuestAccount(account) == true) then outputChatBox("You need to be logged in to use this!", player, 0, 255, 255) return end if mapName then if not string.find(mapName, '%W') then if (getElementData(player,"tempbuilder") == true) then if playerobj[player] then if #playerobj[player] >= 1 then local tempdata = {} tempdata['info'] = {} tempdata['info']['creator'] = getPlayerName(player) tempdata['info']['serial'] = getPlayerSerial(player) tempdata['info']['ip'] = getPlayerIP(player) tempdata['info']['time'] = getTimeStamp() tempdata['info']['dimension'] = getElementDimension(playerobj[player][i]) for _,i in ipairs(playerobj[player]) do if playerobj[player][i] then tempdata[i] = {} tempdata[i]['model'] = getElementModel(playerobj[player][i]) tempdata[i]['col'] = getElementCollisionsEnabled(playerobj[player][i]) local x, y, z, rx, ry, rz = getElementAttachedOffsets(playerobj[player][i]) tempdata[i]['pos'] = {x, y, z, rx, ry, rz} if getElementType(playerobj[player][i]) == 'vehicle' then tempdata[i]['type'] = 'vehicle' local colours = {getVehicleColor(playerobj[player][i], true)} for k=1,12 do if not colours[k] then colours[k] = 255 end end tempdata[i]['colour'] = colours else local scalex, scaley, scalez = getObjectScale(playerobj[player][i]) tempdata[i]['scale'] = {scalex, scaley, scalez} tempdata[i]['type'] = 'object' end end end local file = fileCreate('maps/'..mapName.. '.json') fileWrite(file, toJSON(tempdata)) fileClose(file) tempdata = {} outputChatBox('Saved map as ' .. mapName, player, 0, 255, 255) end end end else outputChatBox('Invalid map name.', player, 0, 255, 255) end else outputChatBox('SYNTAX: /savemap name', player, 0, 255, 255) end end ) function loadMap(player,cmd,mapName) local account = getPlayerAccount(player) if (isGuestAccount(account) == true) then outputChatBox("You need to be logged in to use this!", player, 0, 255, 255) return end local vehicle = vehicle if not vehicle then vehicle = getPedOccupiedVehicle(player) end if vehicle then if fileExists('maps/'..mapName..'.json') then local name if isElement(player) then clearVehicleObjects(player) outputChatBox('Map loaded: ' ..mapName, player, 0, 255, 255) name = getPlayerName(player) else name = 'the server' end local file = fileOpen('maps/'..mapName..'.json') local size = fileGetSize(file) local buffer = fileRead(file, size) local tempdata = fromJSON(buffer) fileClose(file) playerobj[player] = {} local vx, vy, vz = getElementPosition(vehicle) for k,v in pairs (tempdata) do if k ~= 'info' then local id = tonumber(k) local ids = tostring(k) if tempdata[ids]['type'] == 'vehicle' then objectid[playerobj][id] = createVehicle(tempdata[ids]['model'], vx, vy, vz) setVehicleColor(playerobj[player][id], unpack(tempdata[ids]['colour'])) else playerobj[player][id] = createObject(tempdata[ids]['model'], vx, vy, vz) scalex, scaley, scalez = unpack(tempdata[ids]['scale']) setObjectScale(playerobj[player][id], scalex, scaley, scalez) end setElementCollisionsEnabled(attachment[vehicle][id], tempdata[ids]['col']) end end tempdata = {} else outputChatBox("Map " ..mapName.. " failed to load.", player, 0, 255, 255) end end end
  11. Ok this works, but the /share doesn't work, idk why. Someone help me out local players = {} addEventHandler("onResourceStart",getRootElement(),function() for _,plr in pairs(getElementsByType("player")) do bindKey(plr,"k","down","lock") end end) addEventHandler("onPlayerJoin",getRootElement(),function() bindKey(source,"k","down","lock") end) function spawnCar(player,cmd,vehicle,value1) if (isPedInVehicle(player) == true) then if getPedOccupiedVehicle(player) and getPedOccupiedVehicleSeat(player) == 0 then local occupiedCar = getPedOccupiedVehicle(player) destroyElement(occupiedCar) local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end else outputChatBox("You need to get out of your current vehicle!",player,0,255,255) end else local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end end end addCommandHandler("vi", spawnCar) function lock(source,cmd) if lock == false then if isPedInVehicle(source) then if players[getPedOccupiedVehicle(source)] then return end local serial = getPlayerSerial(source) players[getPedOccupiedVehicle(source)] = {} table.insert(players[getPedOccupiedVehicle(source)],serial) lock = true outputChatBox("Locked!",source,0,255,255) end else if isPedInVehicle(source) then if not players[getPedOccupiedVehicle(source)] then return end players[getPedOccupiedVehicle(source)] = nil lock = false outputChatBox("Unlocked!",source,0,255,255) end end end addCommandHandler("lock",lock) function share(player,cmd,otherPlayer) if isPedInVehicle(player) then if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then if players[getPedOccupiedVehicle(player)] then for _,carA in pairs(players[getPedOccupiedVehicle(player)]) do if getPlayerSerial(player) ~= carA then if not getPlayerSerial(getPlayerFromName(otherPlayer)) ~= carA then local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.insert(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle shared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has granted you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) else local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.removeValue(players[getPedOccupiedVehicle(player)],serialOther) outputChatBox("Vehicle unshared with "..otherPlayer.."!",player,0,255,255) outputChatBox(getPlayerName(player).." has denied you access to their vehicle!",getPlayerFromName(otherPlayer),0,255,255) end end end end else outputChatBox("You need to be the driver!",player,255,0,0) end end end addCommandHandler("share",share) addEventHandler("onVehicleStartEnter",getRootElement(),function(player,seat) if players[source] then if not (getElementData(player,"passenger") == "allowed") then for _,carA in pairs(players[source]) do if player ~= carA then cancelEvent() outputChatBox("This vehicle is locked!",player,0,255,255) end end else if seat == 0 then cancelEvent() outputChatBox("This vehicle is locked!",player,0,255,255) else return end end end end) function allow(player,cmd,other) if isPedInVehicle(player) then if (getVehicleOccupant(getPedOccupiedVehicle(player),0) == player) then if (getElementData(getPlayerFromName(other),"passenger") == "disallowed") or (getElementData(getPlayerFromName(other),"passenger") == nil) then setElementData(getPlayerFromName(other),"passenger","allowed") outputChatBox(other.." is now allowed to get in as a passenger!",player,0,255,255) outputChatBox(getPlayerName(player).." has allowed you to get in their car as a passenger!",getPlayerFromName(other),0,255,255) else setElementData(getPlayerFromName(other),"passenger","disallowed") outputChatBox(other.." is now disallowed to get in as a passenger!",player,0,255,255) outputChatBox(getPlayerName(player).." has disallowed you to get in their car as a passenger!",getPlayerFromName(other),0,255,255) end end end end addCommandHandler("allow",allow) function eject(player,cmd,other) if isPedInVehicle(player) then if getVehicleOccupant(getPedOccupiedVehicle(player),0) == player then removePlayerFromVehicle(getPlayerFromName(other)) local x,y,z = getElementPosition(getPlayerFromName(other)) setElementPosition(getPlayerFromName(other),x+5,y,z) outputChatBox(getPlayerName(player).." has ejected you from the vehicle!",getPlayerFromName(other),0,255,255) else outputChatBox("You need to be the driver!",player,255,0,0) end end end addCommandHandler("eject",eject) function table.removeValue(table, val) for index, value in ipairs(table) do if value == val then table.remove(table, index) return index end end return false end
  12. My server is posted under every one of my messages/posts, so if u wanna test it, go ahead
  13. /vi works just fine, i don't have any errors in console or anything in debugscript. I made /vi a long time ago, its the lock system I'm having trouble with.. It gives the messages, but tables just aren't working like they're suppose to.
  14. local players = {} addEventHandler("onResourceStart",getRootElement(),function() for _,plr in pairs(getElementsByType("player")) do bindKey(plr,"k","down","lock") end end) addEventHandler("onPlayerJoin",getRootElement(),function() bindKey(source,"k","down","lock") end) function spawnCar(player,cmd,vehicle,value1) if (isPedInVehicle(player) == true) then if getPedOccupiedVehicle(player) and getPedOccupiedVehicleSeat(player) == 0 then local occupiedCar = getPedOccupiedVehicle(player) destroyElement(occupiedCar) local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end else outputChatBox("You need to get out of your current vehicle!",player,0,255,255) end else local x,y,z = getElementPosition(player) local dim = getElementDimension(player) local int = getElementInterior(player) local s = getVehicleModelFromName(vehicle) if (s == 425) or (s == 520) or (s == 432) then outputChatBox("This vehicle is not allowed!",player,255,0,0) return else if (vehicle == "super" and value1 == "gt") then local car = createVehicle(506,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end elseif (vehicle == "blista" and value1 == "compact") then local car = createVehicle(496,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.." "..value1.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end else local car = createVehicle(s,x,y,z) setElementDimension(car,dim) setElementInterior(car,int) warpPedIntoVehicle(player,car) outputChatBox("You have spawned an "..vehicle.."!", player, 0, 255, 255) if not players[car] then players[car] = {} local serial = getPlayerSerial(player) table.insert(players[car],serial) end end end end end addCommandHandler("vi", spawnCar) function owner(source,cmd) if lock == false then if isPedInVehicle(source) then if players[getPedOccupiedVehicle(source)] then return end local serial = getPlayerSerial(source) players[getPedOccupiedVehicle(source)] = {} table.insert(players[getPedOccupiedVehicle(source)],serial) lock = true outputChatBox("Locked!",source,0,255,255) end else if isPedInVehicle(source) then if not players[getPedOccupiedVehicle(source)] then return end players[getPedOccupiedVehicle(source)] = nil lock = false outputChatBox("Unlocked!",source,0,255,255) end end end addCommandHandler("lock",owner) function assignToAnother(player,cmd,otherPlayer) if isPedInVehicle(player) then local serialOther = getPlayerSerial(getPlayerFromName(otherPlayer)) table.insert(players[getPedOccupiedVehicle(player)],serial) outputChatBox("Vehicle Shared With "..otherPlayer.."!",source,0,255,255) outputChatBox(getPlayerName(player).." has granted you access to their vehicle!",shared,0,255,255) end end addCommandHandler("share", assignToAnother) addEventHandler("onVehicleStartEnter",getRootElement(),function(player,seat) if players[source] then for _,carA in pairs(players[source]) do if seat == 0 then if not carA == getPlayerSerial(player) then cancelEvent() outputChatBox("This vehicle is locked!",player,0,255,255) end end end end end)
  15. Help? addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function() createObject(11388, -2048.216796875, 166.73092651367, 34.468391418457, 0.000000, 0.000000, 0.000000) createObject(11389, -2048.1174316406, 166.71966552734, 30.975694656372, 0.000000, 0.000000, 0.000000) createObject(11392, -2047.8289794922, 167.54446411133, 27.835615158081, 0.000000, 0.000000, 0.000000) end) objects = {} lifts = { {ID = 1, x = -2052.5903320312, y = 178.61114501953, z = 27.834247589111, rx = 0, ry = 0, rz = 90}, {ID = 1, x = -2052.5903320312, y = 170.61114501953, z = 27.834247589111, rx = 0, ry = 0, rz = 90} } for _,w in ipairs(lifts) do objects[w.ID] = {} objects[w.ID].someObject = createObject(2597, w.x, w.y, w.z, w.rx, w.ry, w.rz) objects[w.ID].someObject2 = createObject(2231, w.x, w.y, w.z - 3.632013320923, w.rx, w.ry, w.rz) objects[w.ID].marker = createMarker(w.x, w.y - 3.1, w.z - 0.1, "cylinder", 1, 250, 20, 100, 170) addEventHandler("onMarkerHit",getRootElement(),function(element) if (getElementType(element) == "player") and (source == objects[w.ID].marker) and (isPedInVehicle(element) == false) then if source == objects[w.ID].marker then setMarkerColor(objects[w.ID].marker, 10, 195, 245, 170) bindKey("num_add","down",moveDown) bindKey("num_add","up",stopRamp) bindKey("num_sub","down",moveUp) bindKey("num_sub","up",stopRamp) end end end) addEventHandler("onMarkerLeave",getRootElement(),function(element) if (getElementType(element) == "player") and (source == objects[w.ID].marker) and (isPedInVehicle(element) == false) then if source == objects[w.ID].marker then unbindKey("num_add","both") unbindKey("num_sub","both") stopRamp() setMarkerColor(objects[w.ID].marker,250,20,100,170) end end end) end
  16. shaio

    Lock System

    im still hella confused
  17. shaio

    Lock System

    Could u script a part of it out cuz I really don't understand..
  18. I have a car lift mod, basically the machine and base are seperate mods, and i just move the base up. But I cant get anything to go with tables.. I need a little help.. addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function() createObject(11388, -2048.216796875, 166.73092651367, 34.468391418457, 0.000000, 0.000000, 0.000000) createObject(11389, -2048.1174316406, 166.71966552734, 30.975694656372, 0.000000, 0.000000, 0.000000) createObject(11392, -2047.8289794922, 167.54446411133, 27.835615158081, 0.000000, 0.000000, 0.000000) end) lifts = { {ID = 1, x = -2052.5903320312, y = 178.61114501953, z = 27.834247589111, rx = 0, ry = 0, rz = 90} } for _,w in ipairs(lifts) do object[w.ID] = createObject(2597, w.x, w.y, w.z, w.rx, w.ry, w.rz) lift[w.ID] = createObject(2231, w.x, w.y, w.z - 3.632013320923, w.rx, w.ry, w.rz) marker[w.ID] = createMarker( w.x + 2, w.y, w.z, "cylinder", 1, 250, 20, 100, 170) addEventHandler("onMarkerHit",marker[w.ID],function(element) if (getElementType(element) == "player") and (source == marker[w.ID]) and (isPedInVehicle(element) == false) then if source == marker[w.ID] then setMarkerColor(marker[w.ID],10,195,245,170) bindKey("num_add","down",moveRamp2) bindKey("num_add","up",stopRamp) bindKey("num_sub","down",moveRamp1) bindKey("num_sub","up",stopRamp) end end end) addEventHandler("onMarkerLeave",marker[w.ID],function(element) if (getElementType(element) == "player") and (source == marker[w.ID]) and (isPedInVehicle(element) == false) then if source == marker[w.ID] then unbindKey("num_add","both") unbindKey("num_sub","both") stopRamp() setMarkerColor(marker[w.ID],250,20,100,170) end end end) end --[[ This is all gonna be changed function moveRamp1() timer1 = setTimer(moveUp,50,0) end function moveRamp2() timer2 = setTimer(moveDown,50,0) end function stopRamp() if timer1 then killTimer(timer1) end if timer2 then killTimer(timer2) end end) function moveUp() x,y,z = getElementPosition(liftBase2) if z > 28 then return else x,y,z = getElementPosition(liftBase2) moveObject(liftBase2,1.5,x,y,z + 0.022) end end function moveDown() x,y,z = getElementPosition(liftBase2) if z < 24.2 then return else x,y,z = getElementPosition(liftBase2) moveObject(liftBase2,1.5,x,y,z - 0.022) end end ]]
  19. shaio

    Lock System

    could someone script it out for me so i can get a better understanding?
  20. shaio

    Lock System

    I'm making the tables yes but the tables need to save to separate vehicles..
  21. shaio

    Lock System

    could anyone help me save the tables to vehicle?
  22. I was wondering if it is possible to call a server or client side function from another resource.
  23. shaio

    Lock System

    This is what I have.. local players = {shares = {}} addEventHandler("onPlayerJoin",getRootElement(),function() bindKey(source,"k","down","lock") end) addEventHandler("onResourceStart",getRootElement(),function() for _,plr in ipairs(getElementsByType("player")) do bindKey(plr,"k","down","lock") end end) function lockVehicle(player,cmd) local vehicle = getPedOccupiedVehicle(player) if isVehicleLocked(vehicle) then setVehicleLocked(vehicle,false) else setVehicleLocked(vehicle,true) players[player] = {} end end addCommandHandler("lock",lockVehicle) function shareLock(player,cmd,other) local serial = getPlayerSerial(getPlayerFromPartialName(other)) for _,v in pairs(players) do table.insert(v.shares,serial) end end addCommandHandler("allow",shareLock) addEventHandler("onVehicleStartEnter",getRootElement(),function(player,seat,jacked) for _,v in pairs(players) do for _,a in pairs(v.shares) do if (a == player) then return else cancelEvent() end end end end) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x",""):lower() or nil if name then for _,player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x",""):lower() if name_:find(name,1,true) then return player end end end end