Hi, I am using this in my Spanish role play server and I have an old version, since the last version, when I put the zone safe, let’s say that the zombies enter the same and kill my users, I have tried to enter the code clean and add some modifications and stay the same … What can I do? What I use is this:
ZONE SAFE:
local zones = {
{ ['x'] = 456.62, ['y'] = -752.55, ['z'] = 27.36}
}
local notifIn = false
local notifOut = false
local closestZone = 1
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
------- Creating Blips at the locations. --------------
-------You can comment out this section if you dont want any blips showing the zones on the map.--------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) do
Citizen.Wait(0)
end
for i = 1, #zones, 1 do
local szBlip = AddBlipForCoord(zones[i].x, zones[i].y, zones[i].z)
SetBlipAsShortRange(szBlip, true)
SetBlipColour(szBlip, 2) --Change the blip color: https://gtaforums.com/topic/864881-all-blip-color-ids-pictured/
SetBlipSprite(szBlip, 398) -- Change the blip itself: https://marekkraus.sk/gtav/blips/list.html
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("SAFE ZONE") -- What it will say when you hover over the blip on your map.
EndTextCommandSetBlipName(szBlip)
end
end)
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
---------------- Getting your distance from any one of the locations --------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) do
Citizen.Wait(0)
end
while true do
local playerPed = GetPlayerPed(-1)
local x, y, z = table.unpack(GetEntityCoords(playerPed, true))
local minDistance = 100000
for i = 1, #zones, 1 do
dist = Vdist(zones[i].x, zones[i].y, zones[i].z, x, y, z)
if dist < minDistance then
minDistance = dist
closestZone = i
end
end
Citizen.Wait(15000)
end
end)
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------- Setting of friendly fire on and off, disabling your weapons, and sending pNoty -----------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) do
Citizen.Wait(0)
end
while true do
Citizen.Wait(0)
local player = GetPlayerPed(-1)
local x,y,z = table.unpack(GetEntityCoords(player, true))
local dist = Vdist(zones[closestZone].x, zones[closestZone].y, zones[closestZone].z, x, y, z)
if dist <= 50.0 then ------------------------------------------------------------------------------ Here you can change the RADIUS of the Safe Zone. Remember, whatever you put here will DOUBLE because
if not notifIn then -- it is a sphere. So 50 will actually result in a diameter of 100. I assume it is meters. No clue to be honest.
NetworkSetFriendlyFireOption(false)
ClearPlayerWantedLevel(PlayerId())
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true)
TriggerEvent("pNotify:SendNotification",{
text = "<b style='color:#1E90FF'>You are in a SafeZone</b>",
type = "success",
timeout = (3000),
layout = "bottomcenter",
queue = "global"
})
notifIn = true
notifOut = false
end
else
if not notifOut then
NetworkSetFriendlyFireOption(true)
TriggerEvent("pNotify:SendNotification",{
text = "<b style='color:#1E90FF'>You are in NO LONGER a SafeZone</b>",
type = "error",
timeout = (3000),
layout = "bottomcenter",
queue = "global"
})
notifOut = true
notifIn = false
end
end
if notifIn then
DisableControlAction(2, 37, true) -- disable weapon wheel (Tab)
DisablePlayerFiring(player,true) -- Disables firing all together if they somehow bypass inzone Mouse Disable
DisableControlAction(0, 106, true) -- Disable in-game mouse controls
if IsDisabledControlJustPressed(2, 37) then --if Tab is pressed, send error message
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true) -- if tab is pressed it will set them to unarmed (this is to cover the vehicle glitch until I sort that all out)
TriggerEvent("pNotify:SendNotification",{
text = "<b style='color:#1E90FF'>You can not use weapons in a Safe Zone</b>",
type = "error",
timeout = (3000),
layout = "bottomcenter",
queue = "global"
})
end
if IsDisabledControlJustPressed(0, 106) then --if LeftClick is pressed, send error message
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true) -- If they click it will set them to unarmed
TriggerEvent("pNotify:SendNotification",{
text = "<b style='color:#1E90FF'>You can not do that in a Safe Zone</b>",
type = "error",
timeout = (3000),
layout = "bottomcenter",
queue = "global"
})
end
end
-- Comment out lines 142 - 145 if you dont want a marker.
if DoesEntityExist(player) then --The -1.0001 will place it on the ground flush -- SIZING CIRCLE | x y z | R G B alpha| *more alpha more transparent*
DrawMarker(1, zones[closestZone].x, zones[closestZone].y, zones[closestZone].z-1.0001, 0, 0, 0, 0, 0, 0, 100.0, 100.0, 2.0, 13, 232, 255, 155, 0, 0, 2, 0, 0, 0, 0) -- heres what all these numbers are. Honestly you dont really need to mess with any other than what isnt 0.
--DrawMarker(type, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, float rotX, float rotY, float rotZ, float scaleX, float scaleY, float scaleZ, int red, int green, int blue, int alpha, BOOL bobUpAndDown, BOOL faceCamera, int p19(LEAVE AS 2), BOOL rotate, char* textureDict, char* textureName, BOOL drawOnEnts)
end
end
end)
zombiespawner
players = {}
RegisterNetEvent("Z:playerUpdate")
AddEventHandler("Z:playerUpdate", function(mPlayers)
players = mPlayers
end)
peds = {}
Citizen.CreateThread(function()
AddRelationshipGroup("zombeez")
SetRelationshipBetweenGroups(5, GetHashKey("zombeez"), GetHashKey("PLAYER"))
SetRelationshipBetweenGroups(5, GetHashKey("zombeez"), GetHashKey("bandit"))
SetRelationshipBetweenGroups(5, GetHashKey("PLAYER"), GetHashKey("zombeez"))
SetAiMeleeWeaponDamageModifier(2.0)
while true do
Wait(1)
if #peds < 15 then
x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
choosenPed = pedModels[math.random(1, #pedModels)]
choosenPed = string.upper(choosenPed)
RequestModel(GetHashKey(choosenPed))
while not HasModelLoaded(GetHashKey(choosenPed)) or not HasCollisionForModelLoaded(GetHashKey(choosenPed)) do
Wait(1)
end
local newX = x
local newY = y
local newZ = z + 999.0
repeat
Wait(1)
newX = x + math.random(-50, 50)
newY = y + math.random(-50 , 50)
_,newZ = GetGroundZFor_3dCoord(newX+.0,newY+.0,z, 1)
for _, player in pairs(players) do
Wait(1)
playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
if newX > playerX - 35 and newX < playerX + 35 or newY > playerY - 35 and newY < playerY + 35 then
canSpawn = false
break
else
canSpawn = true
end
end
until canSpawn
ped = CreatePed(4, GetHashKey(choosenPed), newX, newY, newZ, 0.0, true, true)
SetPedArmour(ped, 100)
SetPedAccuracy(ped, 25)
SetPedSeeingRange(ped, 100.0)
SetPedHearingRange(ped, 80.0)
SetPedFleeAttributes(ped, 0, 0)
SetPedCombatAttributes(ped, 16, 1)
SetPedCombatAttributes(ped, 17, 0)
SetPedCombatAttributes(ped, 46, 1)
SetPedCombatAttributes(ped, 1424, 0)
SetPedCombatAttributes(ped, 5, 1)
SetPedCombatRange(ped,2)
SetPedAlertness(ped,3)
SetAmbientVoiceName(ped, "ALIENS")
SetPedEnableWeaponBlocking(ped, true)
SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
DisablePedPainAudio(ped, true)
SetPedDiesInWater(ped, false)
SetPedDiesWhenInjured(ped, false)
-- PlaceObjectOnGroundProperly(ped)
SetPedDiesInstantlyInWater(ped,true)
SetPedIsDrunk(ped, true)
SetPedConfigFlag(ped,100,1)
RequestAnimSet("move_m@drunk@verydrunk")
while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
Wait(1)
end
SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)
ApplyPedDamagePack(ped,"BigHitByVehicle", 0.0, 9.0)
ApplyPedDamagePack(ped,"SCR_Dumpster", 0.0, 9.0)
ApplyPedDamagePack(ped,"SCR_Torture", 0.0, 9.0)
StopPedSpeaking(ped,true)
TaskWanderStandard(ped, 1.0, 10)
local pspeed = math.random(20,70)
local pspeed = pspeed/10
local pspeed = pspeed+0.01
SetEntityMaxSpeed(ped, 5.0)
if not NetworkGetEntityIsNetworked(ped) then
NetworkRegisterEntityAsNetworked(ped)
end
table.insert(peds, ped)
end
for i, ped in pairs(peds) do
if DoesEntityExist(ped) == false then
table.remove(peds, i)
end
pedX, pedY, pedZ = table.unpack(GetEntityCoords(ped, true))
if IsPedDeadOrDying(ped, 1) == 1 then
-- Set ped as no longer needed for despawning
local dropChance = math.random(0,100)
if GetPedSourceOfDeath(ped) == PlayerPedId() then
if dropChance >= 95 then
ForceCreateFoodPickupAtCoord(pedX,pedY,pedZ)
end
zombiekillsthislife = zombiekillsthislife+1
zombiekills = zombiekills+1
end
Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
table.remove(peds, i)
else
playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
SetPedArmour(ped, 100)
SetPedAccuracy(ped, 25)
SetPedSeeingRange(ped, 300.0)
SetPedHearingRange(ped, 300.0)
SetPedFleeAttributes(ped, 0, 0)
SetPedCombatAttributes(ped, 16, 1)
SetPedCombatAttributes(ped, 17, 0)
SetPedCombatAttributes(ped, 46, 1)
SetPedCombatAttributes(ped, 1424, 0)
SetPedCombatAttributes(ped, 5, 1)
SetPedCombatRange(ped,2)
SetAmbientVoiceName(ped, "ALIENS")
SetPedEnableWeaponBlocking(ped, true)
SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
DisablePedPainAudio(ped, true)
SetPedDiesInWater(ped, false)
SetPedDiesWhenInjured(ped, false)
if pedX < playerX - 70 or pedX > playerX + 70 or pedY < playerY - 70 or pedY > playerY + 70 then
-- Set ped as no longer needed for despawning
local model = GetEntityModel(ped)
SetEntityAsNoLongerNeeded(ped)
SetModelAsNoLongerNeeded(model)
table.remove(peds, i)
end
end
end
end
end)
RegisterNetEvent("Z:cleanup")
AddEventHandler("Z:cleanup", function()
for i, ped in pairs(peds) do
-- Set ped as no longer needed for despawning
local model = GetEntityModel(ped)
SetEntityAsNoLongerNeeded(ped)
SetModelAsNoLongerNeeded(model)
table.remove(peds, i)
end
end)