Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------
- -- INFORMATION: Community Event Manager | Infection Event ( Zelda ) | Server side
- -- TOPIC: https://cit2.net/index.php?topic=325432.msg4794240#msg4794240
- -----------------------------------------------------------------------------------------
- local minPlayers = 3 -- Minimun players to participate
- local zombieHits = 2 -- Zombie hits to convert a survivor
- local timeEvent = 60 -- Seconds to start
- local lastPos, participants, survivors, zombies, dmg, start = {}, {}, {}, {}, nil
- local zombieSpawn = {
- {395.75787353516, -2371.6535644531, 3.3488941192627},
- {394.39294433594, -2371.9772949219, 3.3488941192627},
- {395.90365600586, -2373.4309082031, 3.3488941192627},
- {394.86157226563, -2373.7033691406, 3.3488941192627},
- {405.0712890625, -2384.8032226563, 3.3488941192627},
- {403.89306640625, -2384.9995117188, 3.3488941192627},
- {404.85485839844, -2383.662109375, 3.3488941192627},
- {403.74230957031, -2383.8522949219, 3.3488941192627},
- {407.46069335938, -2381.8188476563, 3.3488941192627},
- {407.12286376953, -2380.388671875, 3.3488941192627},
- {406.87033081055, -2378.9853515625, 3.3488941192627},
- {406.51379394531, -2377.5573730469, 3.3488941192627},
- {400.5719909668, -2371.1164550781, 3.3600325584412},
- {401.61032104492, -2370.9135742188, 3.3600325584412},
- {400.85083007813, -2372.2338867188, 3.3600325584412},
- {401.70031738281, -2371.9643554688, 3.3600325584412},
- }
- local survivalsSpawn = {
- {429.25793457031, -2564.2958984375, 10.582830429077},
- {428.640625, -2562.8400878906, 10.572721481323},
- {430.07098388672, -2563.8388671875, 10.5006275177},
- {429.4479675293, -2563.021484375, 10.516647338867},
- {435.97274780273, -2559.837890625, 10.205181121826},
- {436.78106689453, -2559.3420410156, 10.151559829712},
- {436.71331787109, -2558.5192871094, 10.21697807312},
- {435.56307983398, -2558.8542480469, 10.319427490234},
- {433.6247253418, -2555.3972167969, 10.103618621826},
- {434.46490478516, -2555.7663574219, 10.179895401001},
- {432.54794311523, -2555.8879394531, 10.047999382019},
- {433.64892578125, -2556.8305664063, 10.168029785156},
- {428.171875, -2560.6547851563, 10.521595001221},
- {428.96755981445, -2559.5014648438, 10.412731170654},
- {430.02325439453, -2558.255859375, 10.279745101929},
- {431.10305786133, -2557.2897949219, 10.156097412109},
- }
- function makeEvent(player)
- if (isGuestAccount(getPlayerAccount(player))) then
- return
- end
- if (hasObjectPermissionTo(player, "command.givevehicle", false) or exports.CITadmin:getPlayerAdminLevel(player) >= 1) then
- if startTime and isTimer(startTime) then
- killTimer(startTime)
- end
- startTime = setTimer(startEvent, (timeEvent*1000), 1)
- exports.CIThelp:dm("Infection event will start in "..math.floor((getTimerDetails(startTime)/1000)).." seconds, use /goinfection to participate", root, 255, 0, 200)
- end
- end
- addCommandHandler("startinfection", makeEvent)
- function joinEvent(player)
- if (isGuestAccount(getPlayerAccount(player))) then
- return
- end
- if (not startTime) or (not isTimer(startTime)) then
- exports.CIThelp:dm("The infection event is not activated at this time", player, 255, 0, 0)
- return
- end
- if (start) then
- exports.CIThelp:dm("The infection event already started, wait for the next one", player, 255, 255, 0)
- return
- end
- -- if (not exports.CITchecking:canPlayerDoAction(player, "InfectionEvent")) then return end
- if (participants[player]) then
- exports.CIThelp:dm("You are already participating, seconds remaining to start the event: "..math.floor((getTimerDetails(startTime)/1000)).."", player, 255, 255, 0)
- return
- end
- participants[player] = true
- exports.CIThelp:dm("Now you are participating in the infection event!", player, 0, 255, 0)
- end
- addCommandHandler("goinfection", joinEvent)
- function onResourceStop()
- for k, v in pairs(participants) do
- if (isElement(k)) then
- setElementData(k, "infection", false)
- if (lastPos[k]) then
- local x, y, z, int, dim, model = lastPos[k][1], lastPos[k][2], lastPos[k][3], lastPos[k][4], lastPos[k][5], lastPos[k][6]
- setElementPosition(k, x, y, z)
- setElementInterior(k, int)
- setElementDimension(k, dim)
- exports.CITclothes:setModel(k, model)
- exports.CIThelp:dm("The script has been reset, they all appeared in their previous locations.", k, 255, 255, 0)
- end
- end
- end
- end
- addEventHandler("onResourceStop", resourceRoot, onResourceStop)
- function canPlayerEnter(player)
- if (getElementHealth(player) < 1) then
- exports.CIThelp:dm("Your participation to the infection event is canceled because you not have enough life", player, 255, 0, 0)
- return
- end
- if (isPedDead(player)) then
- exports.CIThelp:dm("Your participation to the infection event is canceled because you are dead", player, 255, 0, 0)
- return
- end
- if (exports.CITprison:isPlayerInJail(player)) then
- exports.CIThelp:dm("Your participation to the infection event is canceled because you are in prison", player, 255, 0, 0)
- return
- end
- if (exports.CITpoliceArrest:isPlayerArrested(player)) then
- exports.CIThelp:dm("Your participation to the infection event is canceled because you are arrested", player, 255, 0, 0)
- return
- end
- if (exports.CITteams:isPlayerInTeams(player, "Staff")) then -- Not allowed because staff is ivencible
- exports.CIThelp:dm("Remove your staff job frist", player, 255, 0, 0)
- return
- end
- return true
- end
- function eventCheck()
- local n = 0
- for k, v in pairs(participants) do
- if (isElement(k) and canPlayerEnter(k)) then
- n = n + 1
- end
- end
- return n
- end
- function getRandomZombie()
- local temporal = {}
- for k, v in pairs(participants) do
- table.insert(temporal, {k})
- end
- return temporal[math.random(1, #temporal)][1]
- end
- function startEvent()
- if (eventCheck() < minPlayers) then
- exports.CIThelp:dm("The infection event was canceled because there are not enough players to participate - Minimun: ("..minPlayers..").", root, 255, 0, 0)
- participants = {}
- return
- end
- start = true
- local zombie = getRandomZombie()
- for k, v in pairs(participants) do
- if (isElement(k)) then
- local x, y, z = getElementPosition(k)
- local int, dim = getElementInterior(k), getElementDimension(k)
- local model = getElementModel(k)
- lastPos[k] = {x, y, z, int, dim, model}
- if (k == zombie) then
- zombies[k] = true
- setElementData(k, "infection", "zombie")
- exports.CITclothes:setModel(k, 11)
- local random = math.random(#zombieSpawn)
- local x, y, z = zombieSpawn[random][1], zombieSpawn[random][2], zombieSpawn[random][3]
- setElementPosition(k, x, y, z)
- setElementDimension(k, 16000)
- setCameraTarget(k, k)
- exports.CITtrivia:sendMessage("Hunt the survivors!", k, 0, 255, 0)
- triggerClientEvent("CITinfection.startEvent", k)
- else
- survivors[k] = true
- setElementData(k, "infection", "survivor")
- exports.CITclothes:setModel(k, 264)
- local random = math.random(#survivalsSpawn)
- local x, y, z = survivalsSpawn[random][1], survivalsSpawn[random][2], survivalsSpawn[random][3]
- setElementPosition(k, x, y, z)
- setElementDimension(k, 16000)
- setCameraTarget(k, k)
- exports.CITtrivia:sendMessage("Kill to zombie's!", k, 0, 255, 0)
- triggerClientEvent("CITinfection.startEvent", k)
- end
- end
- end
- end
- function getPlayerInEvent()
- local surv, zomb = 0, 0
- for k, v in pairs(survivors) do
- if (isElement(k)) then
- surv = surv + 1
- end
- end
- for k, v in pairs(zombies) do
- if (isElement(k)) then
- zomb = zomb + 1
- end
- end
- return surv, zomb
- end
- function onPlayerWasted(ammo, theKiller, weapon, bodypart)
- if (participants[source]) then
- participants[source] = nil
- triggerClientEvent("CITinfection.restoreModels", source)
- if (getElementData(source, "infection") == "survivor") then
- setElementData(source, "infection", false)
- survivors[source] = nil
- elseif (getElementData(source, "infection") == "zombie") then
- zombies[source] = nil
- setElementData(source, "infection", false)
- end
- local survs, zombs = getPlayerInEvent()
- if (survs == 0) then
- for k, v in pairs(participants) do
- if (isElement(k)) then
- exports.CITmoney:GPM(k, 15000, "Infection Event", true)
- setElementData(k, "infection", false)
- triggerClientEvent("CITinfection.passed", k)
- local x, y, z, int, dim, model = lastPos[k][1], lastPos[k][2], lastPos[k][3], lastPos[k][4], lastPos[k][5], lastPos[k][6]
- setElementPosition(k, x, y, z)
- setElementInterior(k, int)
- setElementDimension(k, dim)
- exports.CITclothes:setModel(k, model)
- triggerClientEvent("CITinfection.restoreModels", k)
- end
- end
- exports.CIThelp:dm("Survivors have won the infection event", root, 255, 0, 0)
- lastPos, participants, survivors, zombies, start = {}, {}, {}, {}, nil
- elseif zombs == 0 then
- for k, v in pairs(participants) do
- if (isElement(k)) then
- exports.CITmoney:GPM(k, 15000, "Infection Event", true)
- setElementData(k, "infection", false)
- triggerClientEvent("CITinfection.passed", k)
- local x, y, z, int, dim, model = lastPos[k][1], lastPos[k][2], lastPos[k][3], lastPos[k][4], lastPos[k][5], lastPos[k][6]
- setElementPosition(k, x, y, z)
- setElementInterior(k, int)
- setElementDimension(k, dim)
- exports.CITclothes:setModel(k, model)
- triggerClientEvent("CITinfection.restoreModels", k)
- end
- end
- exports.CIThelp:dm("The zombies have won the event of infection", root, 255, 0, 0)
- lastPos, participants, survivors, zombies, start = {}, {}, {}, {}, nil
- end
- end
- end
- addEventHandler("onPlayerWasted", root, onPlayerWasted)
- function onPlayerQuit()
- if (start) then
- lastPos[source], participants[source], zombies[source], survivors[source] = nil, nil, nil, nil
- local survs, zombs = getPlayerInEvent()
- if (survs == 0) then
- exports.CIThelp:dm("Survivors have won the infection event", root, 255, 0, 0)
- for k, v in pairs(participants) do
- if isElement(k) then
- exports.CITmoney:GPM(k, 15000, "Infection Event", true)
- setElementData(k, "infection", false)
- triggerClientEvent("CITinfection.passed", k)
- local x, y, z, int, dim, model = lastPos[k][1], lastPos[k][2], lastPos[k][3], lastPos[k][4], lastPos[k][5], lastPos[k][6]
- setElementPosition(k, x, y, z)
- setElementInterior(k, int)
- setElementDimension(k, dim)
- exports.CITclothes:setModel(k, model)
- triggerClientEvent("CITinfection.restoreModels", k)
- end
- end
- lastPos, participants, survivors, zombies, start = {}, {}, {}, {}, nil
- end
- end
- end
- addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit)
- function dmgReset(victim)
- if (isElement(victim)) then
- setElementData(victim, "hitz", 0)
- dmg[victim] = nil
- end
- end
- function tryConvertToZombie(survivor)
- if (not dmg[survivor]) then
- dmg[survivor] = setTimer(dmgReset, 10000, 1, survivor)
- end
- setElementData(survivor, "hitz", (getElementData(survivor, "hitz") or 0) +1)
- local data = getElementData(survivor,"hitz") or 0
- exports.CIThelp:modTextBar(client, "CITinfection", ""..data.."/"..zombieHits.." Bite by "..getPlayerName(client).."", 255, 0, 0, 255, 10000)
- exports.CIThelp:modTextBar(survivor, "CITinfection", ""..data.."/"..zombieHits.." Bite by "..getPlayerName(client).."", 255 , 0, 0, 255, 10000)
- if (getElementData(survivor, "hitz") < zombieHits) then
- return
- end
- exports.CIThelp:modTextBar(client, "CITinfection", "Converted", 255, 255, 255)
- exports.CIThelp:modTextBar(survivor, "CITinfection", "Converted", 255, 255, 255)
- exports.CITclothes:setModel(survivor, 11)
- survivors[survivor] = nil
- zombies[survivor] = true
- setElementData(survivor, "infection", "zombie")
- triggerClientEvent("CITinfection.converted", survivor)
- local survs, zombs = getPlayerInEvent()
- if (survs == 0) then
- participants[survivor] = nil
- exports.CIThelp:dm("Survivors have won the infection event", root, 255, 0, 0)
- for k, v in pairs(participants) do
- if (isElement(k)) then
- setElementData(k, "infection", false)
- triggerClientEvent("CITinfection.passed", k)
- exports.CITmoney:GPM(k, 15000, "Infection Event", true)
- local x, y, z, int, dim, model = lastPos[k][1], lastPos[k][2], lastPos[k][3], lastPos[k][4], lastPos[k][5], lastPos[k][6]
- setElementPosition(k, x, y, z)
- setElementInterior(k, int)
- setElementDimension(k, dim)
- exports.CITclothes:setModel(k, model)
- triggerClientEvent("CITinfection.restoreModels", k)
- end
- end
- lastPos, participants, survivors, zombies, start = {}, {}, {}, {}, nil
- end
- end
- addEvent("CITinfection.tryConvertToZombie",true)
- addEventHandler("CITinfection.tryConvertToZombie", root, tryConvertToZombie)
Advertisement
Add Comment
Please, Sign In to add comment