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


I could not have done this without @anders !!! Big ups!


— 9/10/18 —
Hey guys, had to upload a quick fix that allowed players in vehicles to pull out guns and shoot, even if they left the car they would still have the gun out. For now I just made it so if you try to left click in the zone, it will set you unarmed and send another notification saying “You cant do that”. Sloppy Quick fix but hey, it works for now.

Thanks @kheire007 for pointing out the vehicle glitch

Quick fix vid

FiveMSafeZoneHotFix - YouTube


What it does!

-adds MULTIPLE safe zones around the map
-disable FF, so if someone is in the zone they can not be shot from someone outside of the zone.
-force any weapons in your hands to be put away.
-display a notification when you enter or leave the safe zone.
-display a notification when you try to access the weapon wheel saying “You can not…”
-adds blips to the map for the safe zones(can be disabled)
-add markers to the safe zones!(can be disabled)

Side notes

  • I personally don’t like the marker so i have it commented out
  • I have included a bunch of links and documentation within the client.lua to help you guys out with blip pics and etc.

Many Thanks to @Setro with the help on pNotify :slight_smile:

Configure it!!!

Change the example ones, and add your own coords!

The distance is the length of a RADIUS of a circle, therefor if you put 50, it will be a zone with a 100 diameter.

The MARKER x and y scales should be WHAT YOUR DIAMETER is. So if you have 50 for the safe zone, set your marker x scale and y scale to 100!!!

Drag and drop to resources
Add start zone to server.cfg
Done

Here is a download 9/10/18
zone.rar (2.5 KB)

Here is a video

Here it is on GitHub

Here is the raw copy pasta
--------------------------------------------------------------------------------------------------------------
------------First off, many thanks to @anders for help with the majority of this script. ---------------------
------------Also shout out to @setro for helping understand pNotify better.              ---------------------
--------------------------------------------------------------------------------------------------------------
------------To configure: Add/replace your own coords in the sectiong directly below.    ---------------------
------------        Goto LINE 90 and change "50" to your desired SafeZone Radius.        ---------------------
------------        Goto LINE 130 to edit the Marker( Holographic circle.)               ---------------------
--------------------------------------------------------------------------------------------------------------
-- Place your own coords here!
local zones = {
	{ ['x'] = 1847.916015625, ['y'] = 3675.8190917968, ['z'] = 33.767009735108},
	{ ['x'] = -1688.43811035156, ['y'] = -1073.62536621094, ['z'] = 13.1521873474121 },
	{ ['x'] = -2195.1352539063, ['y'] = 4288.7290039063, ['z'] = 49.173923492432 }
}

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

Great work! Glad to see more vRP scripts being made.

3 Likes

This should work with anything :stuck_out_tongue: But yes, I do love me some vRP

1 Like

Nice job dude! :slight_smile:

1 Like

Elegant and very useful script!
Thanks for your work!

2 Likes

@Magister @JacobRamsayVenkat Thanks guys!

First of all, nice script! Also good to see you’re using vRP <3

An improvement could also disabling the ability to attack players, it is kind of annoying if people throw grenades and shit even tho you don’t die of them. :slight_smile:

Also implementing pNotify would be nice, so you don’t have the mission text all the time (:slight_smile:

Yeah I actually had 3 different things going on when I first made it. It was disabling FF, turning god mod, and disabling weapons. It was aggravating me earlier so i slimmed it down :P. Gonna have to look up those natives again xD

Gonna work on updating it, dont worry! If you have any insight on that pNotify let me know, Ive only used it once when I was editing the vRP drivers school.

Also this one might work for that grenade problem of yours :stuck_out_tongue: https://runtime.fivem.net/doc/reference.html#_0xFC52E0F37E446528 - REMOVE_ALL_PROJECTILES_OF_TYPE
I assume it would be RemoveAllProjectilesOfType(0x93E220BD,0)

This is the FF
NetworkSetFriendlyFireOption(false/true)
Gonna add it in, but I have no one on to test it with me right now so tomorrow is another day! XD

So it was pretty easy to add in pNotifications, HOWEVER, it just spams the fuck out of them becuase its inside the loop, but how can I have the loop only trigger the Notification only ONCE you enter or exit the zone if it needs to constantly be calling for your location?

. Anyone have any ideas?
Should I add a Wait time other than 0? Maybe move the notifications to a seperate ClientEvent?

Spammy BS
-- I am assuming the distance is in meters? No idea honestly. All you have to do is change the coords and the
-- distance which you want to be covered. The distance is the RADIUS of a circle. So if you do 50, it will be a 100(unit) diameter.
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local player = GetPlayerPed( -1 )
        local pedpos = GetEntityCoords(player)
        local inzone = 0
        local dist = GetDistanceBetweenCoords(pedpos,1847.916015625,3675.8190917968,33.767009735108,true)
        
        if dist <= 50.0 then
            inzone = 1
        elseif dist >= 50.1 then
            inzone = 0
        end
        
        if inzone == 1 then
            SetEntityInvincible(player,true)
            TriggerEvent("pNotify:SendNotification",{
                text = "<b style='color:#1E90FF'>You are in a SafeZone</b>",
                type = "success",
                timeout = (3000),
                layout = "topright",
                queue = "global"
            })
        elseif inzone == 0 then
            SetEntityInvincible(player,false)
            TriggerEvent("pNotify:SendNotification",{
                text = "<b style='color:#1E90FF'>You are in NO LONGER a SafeZone</b>",
                type = "error",
                timeout = (3000),
                layout = "topright",
                queue = "global"
            })
        end
    end
end)

function DrawMissionText2(m_text, showtime)
    ClearPrints()
    SetTextEntry_2("STRING")
    AddTextComponentString(m_text)
    DrawSubtitleTimed(showtime, 1)
end

You could try:

TriggerEvent("pNotify:SetQueueMax", queueName, Max)

How do I add new locations, or is it just for a location?

1 Like

Hei there, nice script for starters. i was looking for one of this. got a problem tho. after i add more coordonates for example:
local dist = GetDistanceBetweenCoords(pedpos,-541.43060302734,-210.1474609375,37.649837493896,true)
local dist = GetDistanceBetweenCoords(pedpos,-516.0064086914,-254.34159851074,35.631900787354,true)
one works, one dosn’t any ideea why? i tryed to set the message time from 5000 to 0, thinking it was a delay betwen messages. but same.

As of now it is only the one zone. Working on making it so it will be a list of coords and you can has multiple. Also working on integrating pNotify right now :slight_smile:

right, well, good job, and thank you, waiting for your release soon!

1 Like
-- I am assuming the distance is in meters? No idea honestly. All you have to do is change the coords and the
-- distance which you want to be covered. The distance is the RADIUS of a circle. So if you do 50, it will be a 100(unit) diameter.
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local player = GetPlayerPed( -1 )
        local pedpos = GetEntityCoords(player)
		inzone = 0
        local dist = GetDistanceBetweenCoords(pedpos,1847.916015625,3675.8190917968,33.767009735108,true)
        
        if dist <= 50.0 then
            inzone = 1
			if not notifIn then
				--pnotify "you entered the zone"
				notifIn = true
				notifOut = false
			end)
        elseif dist >= 50.1 then
            inzone = 0
			if not notifOut then
				--pnotify "you left the zone"
				notifOut = true
				notifIn = false
			end)
        end
        
        if inzone == 1 then
            SetEntityInvincible(player,true)
        elseif inzone == 0 then
            SetEntityInvincible(player,false)
        end
    end
end)

Have not tested. But this should do it.

Ohhh niiiiiiice. Ill give her a whirl :slight_smile:

Looks like it works, however, that extra ) after the notifIn/notifOut needs to be removed. Once I did that it worked perfectly :slight_smile: Gonna update it now, thanks dawg!

Done :wink: (2020222220200)

1 Like