Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local spawnPoint, showSpawns, tempSpawns, spawned = {}, {}, {}, {}
- local limit, status, info
- function addSpawn(plr, cmd, restriction)
- if (not hasObjectPermissionTo(plr, "command.em", false) or getElementDimension(plr) ~= 336) then
- return false
- end
- if (status) then
- outputChatBox("Error: Someone is already using the spawn points!", plr, 255, 0, 0)
- return false
- end
- if (not restriction) then
- restriction = "all"
- end
- if (restriction and restriction ~= "all") then
- local team = findTeam(restriction)
- if (not team) then
- outputChatBox("Error: Invalid team name.", plr, 255, 0, 0)
- return false
- end
- end
- local x, y, z = getElementPosition(plr)
- local int = getElementInterior(plr)
- spawnPoint[#spawnPoint + 1] = {x, y, z, int, restriction}
- local text = "Added a marker. Currently has "..(#spawnPoint).." spawnPoint added."
- if (showSpawns[plr]) then
- showSpawn(plr, "showspawns", true)
- setTimer(restartSpawn, 5000, 1, plr, "add")
- text = "Added the marker and updating the spawnPoint. Within 5 seconds, spawnPoint will appear. Currently has "..(#spawnPoint).." spawnPoint added."
- removeCommandHandler("addspawn", addSpawn)
- end
- outputChatBox(text, plr, 0, 255, 0)
- end
- addCommandHandler("addspawn", addSpawn)
- function delSpawn(plr)
- if (not hasObjectPermissionTo(plr, "command.em", false) or getElementDimension(plr) ~= 336) then
- return false
- end
- if (status) then
- outputChatBox("Error: Someone is already using the spawn points!", plr, 255, 0, 0)
- return false
- end
- if (#spawnPoint <= 0) then
- outputChatBox("Error: You do not have any marker added.", plr, 255, 0, 0)
- return false
- end
- table.remove(spawnPoint, #spawnPoint)
- local text = "Removed a marker. Currently has "..(#spawnPoint).." spawnPoint added."
- if (showSpawns[plr]) then
- showSpawn(plr, "showspawns", true)
- setTimer(restartSpawn, 5000, 1, plr, "remove")
- text = "Removed a marker and updating the spawnPoint. Within 5 seconds, spawnPoint will appear. Currently has "..(#spawnPoint).." spawnPoint added."
- removeCommandHandler("delspawn", delSpawn)
- end
- outputChatBox(text, plr, 0, 255, 0)
- end
- addCommandHandler("delspawn", delSpawn)
- function restartSpawn(plr, cmd)
- if (not plr or not cmd) then
- return false
- end
- if (cmd and cmd == "remove") then
- addCommandHandler("delspawn", delSpawn)
- showSpawn(plr, "showspawns", true)
- return true
- end
- addCommandHandler("addspawn", addSpawn)
- showSpawn(plr, "showspawns", true)
- end
- function showSpawn(plr, cmd, auto)
- if (not hasObjectPermissionTo(plr, "command.em", false) or getElementDimension(plr) ~= 336) then
- return false
- end
- if (status) then
- outputChatBox("Error: Someone is already using the spawn points!", plr, 255, 0, 0)
- return false
- end
- if (#spawnPoint <= 0) then
- outputChatBox("Error: You do not have any marker added.", plr, 255, 0, 0)
- return false
- end
- if (showSpawns[plr]) then
- for i, v in pairs(tempSpawns) do
- if (isElement(i) and isElement(v)) then
- destroyElement(i)
- destroyElement(v)
- end
- end
- tempSpawns = {}
- showSpawns[plr] = false
- if (auto) then
- return false
- end
- outputChatBox("Disable the spawnPoint! Currently has "..(#spawnPoint).." spawnPoint added.", plr, 0, 255, 0)
- return true
- end
- for i, v in pairs(spawnPoint) do
- local x, y, z = v[1], v[2], v[3]
- local r, g, b = 255, 255, 255
- if (v[5] ~= "all") then
- local team = findTeam(v[5])
- r, g, b = getTeamColor(team)
- end
- local marker = createMarker(x, y, z-1, "cylinder", 4, r, g, b, 255, plr)
- tempSpawns[marker] = createBlipAttachedTo(marker, 0, 2, r, g, b, 255, 0, 65535, plr)
- setElementInterior(marker, v[4])
- setElementInterior(tempSpawns[marker], v[4])
- setElementDimension(marker, 336)
- setElementDimension(tempSpawns[marker], 336)
- end
- showSpawns[plr] = true
- if (auto) then
- return false
- end
- outputChatBox("Enable the spawnPoint! Currently has "..(#spawnPoint).." spawnPoint added.", plr, 0, 255, 0)
- end
- addCommandHandler("showspawns", showSpawn)
- function usageSpawns(plr, cmd, typeS, misc)
- if (not hasObjectPermissionTo(plr, "command.em", false) or getElementDimension(plr) ~= 336) then
- return false
- end
- if (not typeS or typeS ~= "stop" and not misc) then
- outputChatBox("Syntax: '/emspawn start/stop/limit race(start)/dm(start)/number(limit)", plr, 255, 0, 0)
- return false
- end
- if (typeS == "start" and not misc or typeS == "start" and misc ~= "dm" and misc ~= "race") then
- outputChatBox("Syntax: '/emspawn start race/dm", plr, 255, 0, 0)
- return false
- end
- if (typeS == "limit" and not tonumber(misc)) then
- outputChatBox("Syntax: '/emspawn limit number", plr, 255, 0, 0)
- return false
- end
- if (typeS == "limit") then
- if (status) then
- outputChatBox("Error: You cannot change the limit of respawn!", plr, 255, 0, 0)
- return false
- end
- limit = tonumber(misc)
- outputChatBox("Limited to "..tostring(limit).." respawns.", plr, 0, 255, 0)
- return true
- end
- if (typeS == "start") then
- if (status) then
- outputChatBox("Error: Someone is already using the spawn points!", plr, 255, 0, 0)
- return false
- end
- if (showSpawns[plr]) then
- showSpawn(plr, "showspawns", true)
- outputChatBox("Disable all spawnPoint!", plr, 0, 255, 0)
- end
- if (misc == "dm") then
- removeEventHandler("onPlayerSpawn", root, plrSpawn)
- addEventHandler("onPlayerSpawn", root, plrSpawn)
- status = true
- info = misc
- outputChatBox("Started the death match event!", plr, 0, 255, 0)
- return true
- end
- for i, v in pairs(spawnPoint) do
- local x, y, z = v[1], v[2], v[3]
- local r, g, b = 255, 255, 255
- if (v[5] ~= "all") then
- local team = findTeam(v[5])
- r, g, b = getTeamColor(team)
- end
- local plrs = exports.CITutil:getPlayersInDimension(336)
- for i, plr in pairs(plrs) do
- local marker = createMarker(x, y, z-1, "cylinder", 4, r, g, b, 0, plr)
- tempSpawns[marker] = {v[4], v[5]}
- setElementInterior(marker, v[4])
- setElementDimension(marker, 336)
- addEventHandler("onMarkerHit", marker, hitCheckPoint)
- if (hasObjectPermissionTo(plr, "command.em", false)) then
- spawned[plr] = 0
- end
- end
- removeEventHandler("onVehicleExplode", root, explodeVeh)
- addEventHandler("onVehicleExplode", root, explodeVeh)
- end
- addCommandHandler("backpos", backPos)
- status = true
- info = misc
- outputChatBox("Started the race event!", plr, 0, 255, 0)
- return true
- end
- if (not status) then
- outputChatBox("Error: Nobody is using the event!", plr, 255, 0, 0)
- return false
- end
- spawned = {}
- if (info == "dm") then
- for i, v in pairs(tempSpawns) do
- if (isElement(i)) then
- destroyElement(i)
- end
- end
- tempSpawns = {}
- spawnPoint = {}
- removeCommandHandler("backpos", backPos)
- end
- info, status = false, false
- outputChatBox("Cleaning the spawn points!", plr, 0, 255, 0)
- end
- addCommandHandler("emspawn", usageSpawns)
- --DM section
- function plrSpawn()
- if (not spawned[source] or spawned[source] > limit) then
- return false
- end
- local x, y, z, int = getNearestSpawn(source, getElementPosition(source))
- setTimer(respawnPlr, 5000, 1, source, x, y, z, int)
- if (not limit or limit == 0) then
- return false
- end
- end
- function respawnPlr(plr, x, y, z, int)
- if (not plr or not x or not y or not z or not int) then
- return false
- end
- setElementDimension(plr, 336)
- setElementPosition(plr, x, y, z)
- setElementInterior(plr, int)
- if (spawned[plr] >= limit) then
- executeCommandHandler("leaveevent", plr)
- spawned[plr] = nil
- end
- end
- --Race Section
- function hitCheckPoint(hitElement, dim)
- if (getElementType(hitElement) ~= "player" and getElementType(hitElement) ~= "vehicle" or not dim) then
- return false
- end
- local plr
- if (getElementType(hitElement) == "vehicle") then
- plr = getVehicleController(hitElement)
- end
- if (getElementType(hitElement) == "player") then
- plr = hitElement
- end
- if (tempSpawns[source][2] ~= "all") then
- local team = findTeam(tempSpawns[source][2])
- if (team ~= getPlayerTeam(plr)) then
- return false
- end
- end
- local x, y, z = getElementPosition(plr)
- local rotx, roty, rotz = getElementRotation(plr)
- spawned[plr] = {x, y, z, rotx, roty, rotz, tempSpawns[source][1]}
- end
- function backPos(plr)
- if (getElementDimension(plr) ~= 336) then
- return false
- end
- if (not spawned[plr]) then
- outputChatBox("You did not touch at spawn point!", plr, 255, 0, 0)
- return false
- end
- local x, y, z, rotx, roty, rotz, int = spawned[plr][1], spawned[plr][2], spawned[plr][3], spawned[plr][4], spawned[plr][5], spawned[plr][6], spawned[plr][7]
- local veh = getPedOccupiedVehicle(plr)
- if (veh) then
- setElementPosition(veh, x, y, z)
- setElementRotation(veh, rotx, roty, rotz)
- setElementDimension(veh, int)
- fixVehicle(veh)
- outputChatBox("Back to your last checkpoint!", plr, 0, 255, 0)
- return true
- end
- setElementPosition(plr, x, y, z)
- setElementRotation(plr, rotx, roty, rotz)
- setElementDimension(plr, int)
- outputChatBox("Back to your last checkpoint!", plr, 0, 255, 0)
- end
- function plrLeaveEvent()
- if (spawned[source]) then
- spawned[source] = nil
- end
- end
- addEventHandler("onPlayerQuit", root, plrLeaveEvent)
- function explodeVeh()
- if (getVehicleOccupant(source, 0) and getElementDimension(source) == 336) then
- local plr = getVehicleController(source)
- if (not spawned[plr]) then
- return false
- end
- spawned[plr] = nil
- end
- end
- --Useful export
- function getNearestSpawn(plr, x, y, z)
- local temp = {}
- for i, v in pairs(spawnPoint) do
- local x1, y1, z1 = v[1], v[2], v[3]
- local dist = getDistanceBetweenPoints3D(x, y, z, x1, y1, z1)
- if (v[5] ~= "all") then
- local team = findTeam(v[5])
- if (getPlayerTeam(plr) == team) then
- table.insert(temp, {i = i, dist = dist})
- end
- else
- table.insert(temp, {i = i, dist = dist})
- end
- end
- table.sort (
- temp,
- function( a, b )
- return((a.dist or 0) < (b.dist or 0))
- end
- )
- return unpack(spawnPoint[temp[1].i])
- end
- function findTeam(name)
- local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
- if name then
- for _, team in ipairs(getElementsByType("team")) do
- local name_ = getTeamName(team):gsub("#%x%x%x%x%x%x", ""):lower()
- if name_:find(name, 1, true) then
- return team
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment