[Release] Safe Zone(s) Updated 9/10/18

roleplay
zone
safe-zone
safezone
no-pvp

#84

You need to comment out the whole blip section.

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
-------                              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)

@Povesti_Horror


#85

Hi bro,
I have a Spanish server of zombies and I have also installed the CorruptSnail, what I need is that when a player is in a safe area, the zombies that enter die instantly or disappear. Here I leave the whole code of the zombiespawner of CorruptSnail

-- CODE --

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)


#86

I’m on my phone atm***

So basically you would have to make it so the zone is also looking for NPCs and when the npc is in the zone you set their health to 0.

My guess would be to use SetEntityHealth

https://runtime.fivem.net/doc/reference.html#_0x6B76DC1F3AE6E6A3


#87

thanks for answering so fast, I’ve been looking at what you said and nothing, I created this code:

        		if inzone == 1 then
            	SetEntityHealth(mPlayer(-1), 0) 
       			end	

#88

shouldnt you use " ped " ? It looks like ped is your zombies?

You could go something like

local x2,y2,z2 = table.unpack(GetEntityCoords(ped, true))
local dist2 = Vdist(zones[closestZone].x, zones[closestZone].y, zones[closestZone].z, x2, y2, z2)


if dist2 <= 50 then
    SetPedToRagdoll(ped, 10000, 0, 0, 0, 0, 0)
    Wait(5000)
    if IsPedRagdoll(ped) then
        DeleteEntity(ped)
    end
end

I really have no idea, never messed with npcs lol


#89

It does not work, I do not know how to make it work, since I’m too noob in this and little by little I’m improving.
when you have 30 zombies that kill you with 2 blows … You understand my concern for the safe areas hahaha


#90

If you are just trying to copy paste this somewhere in your code of course its not going to work. You have to mess about with it. You cant just throw it in my code and expect it to realize what a “zombie” is. You have to define it somewhere. And you cant just put this into your code because it doesnt know what a zone is. Youre gonna need to figure out how to identify the zombies in the zone code.


#91

Hmm. Having some weird issues. For some reason people are able to shoot from the outside players inside.

Also, adjusting the radius doesn’t adjust the radius of the blue visual circle.


#92

Can I add a blacklist group like police so police pfficers can point guns at people in safe zones?


#93

So you will still be able to shoot into the zone. I have no idea how youd be able to even work out not being able to shoot at the zone. You wont be able to shoot people though. If they are in their car in the zone. Bullets can hit it. But it wont damage the vehicle. As for the circle. Look in the code, it’s all the way at the bottom, and re read the OP. It tells you exactly how to change the circle. @CakeArmy_Max

As for blacklisting, white listing, whatever, you will have to figure that out on your own till I get back into messing around with this. Havent been coding for a bit. On that rocket league grind :slight_smile:

@Fernando_Picoral


#94

What I was referring to is users can shoot and kill players that are inside the zone. I also did adjust the blue circles to my liking, just was making the OP aware in case they wanted to document scale.


#96

how to add safezone different size at different location
for example
safezone at garage dist <= 50.0 and
safezone at hospital dist <=200.0


#97

How can I make the circle transparent instead of blue?
@davewazere


#98

If only the guy who wrote the resource had commented his code.

Like at line 141, perhaps…

-- Comment out lines 142 - 145 if you dont want a marker.

#99

Anyway to make that the peds can’t spawn in certain areas?


#100

I can confirm that players can still shoot from out side the zone to kill players. They can also take a car and kill you the old fashion VDM style - was interesting to say the least.


#101

@davewazere
Can I post a modified version of myself?


#102

@Cimpoeru_Cristian https://github.com/syndicate1984/SafeZoneV2.03777514cf44123654ddd34ebdba824a7

We edited the safezone script made by davewazere

Feature

1.When u are in safezone you are invicible

2.Configurable

3.You have an textdraw in right corner

4.I removed the colision with other players when u are in safezone


#103

Of course, the more mods the better! We should all try and help each other as much as possible!


#104

Thanks