[Help] Gang Relationship Script

I got a little issue with a script for fivem.

I’m trying to make it so when you have a certain model, It will change the relationship between the player and a certain gang.

Here’s what I’ve got so far:

playerPed = GetPlayerPed(-1)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if DoesEntityExist(playerPed) then
			-- Ballas
			if IsPedModel(playerPed, "g_m_y_ballasout_01") or IsPedModel(playerPed, "g_m_y_ballaorig_01") or IsPedModel(playerPed, "csb_ballasog") or IsPedModel(playerPed, "g_m_y_ballaeast_01") or IsPedModel(playerPed, "a_m_y_soucent_02") or IsPedModel(playerPed, "g_m_y_strpunk_01") or IsPedModel(playerPed, "ig_ballasog") or IsPedModel(playerPed, "g_f_y_ballas_01") or IsPedModel(playerPed, "csb_grove_str_dlr") then
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_BALLAS"))
			end

			-- Families
			if IsPedModel(playerPed, "g_f_y_families_01") or IsPedModel(playerPed, "g_m_y_famfor_01") or IsPedModel(playerPed, "g_m_y_famdnf_01") or IsPedModel(playerPed, "g_m_y_famca_01") or IsPedModel(playerPed, "mp_m_famdd_01") or IsPedModel(playerPed, "csb_ramp_gang") or IsPedModel(playerPed, "ig_ramp_gang") then
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_FAMILY"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_FAMILY"))
			end
		
			-- Shared
			if IsPedModel(playerPed, "a_m_m_og_boss_01") or IsPedModel(playerPed, "a_m_y_soucent_02") or IsPedModel(playerPed, "csb_denise_friend") or IsPedModel(playerPed, "csb_g") or IsPedModel(playerPed, "g_m_y_strpunk_02") or IsPedModel(playerPed, "s_m_y_dealer_01") or IsPedModel(playerPed, "a_m_m_soucent_01") or IsPedModel(playerPed, "ig_claypain") or IsPedModel(playerPed, "ig_tonya") then
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_FAMILY"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_FAMILY"))
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_BALLAS"))
			end
		end
	end
end)

It works, but when I change my model, it doesn’t change the relationship.
If anyone knows what I need to do, please let me know :wink:

1 Like

Basically you just want the gangs to not attack fellow player gang members right?

Just the playerPed = GetPlayerPed(-1) inside the loop. For example: after the Citizen.Wait(0)
And an other tipp, I think you will need to clear the last relationship before setting a new one, because if you switch a ped with this script for ex.: If you in the family and you switch to ballas then you will be friends with the family and ballas too

local Gangs = {
	{
		Group = "AMBIENT_GANG_BALLAS",
		Models = {
			"g_m_y_ballasout_01",
			"g_m_y_ballaorig_01",
			"csb_ballasog",
			"g_m_y_ballaeast_01",
			"a_m_y_soucent_02",
			"g_m_y_strpunk_01",
			"ig_ballasog",
			"g_f_y_ballas_01",
			"csb_grove_str_dlr"
		}
	},
	{
		Group = "AMBIENT_GANG_FAMILY",
		Models = {
			"g_f_y_families_01",
			"g_m_y_famfor_01",
			"g_m_y_famdnf_01",
			"g_m_y_famca_01",
			"mp_m_famdd_01",
			"csb_ramp_gang",
			"ig_ramp_gang"
		}
	}
}

local CurrentGang = nil

Citizen.CreateThread(function()
	while true do
		if CurrentGang == nil then
			-- Default Gang NONE
			RemovePedFromGroup(GetPlayerPed(PlayerId()))
			CurrentGang = "NONE"
		else
			local SuspectedGang = FindPlayerSupposedGang()
			if CurrentGang ~= SuspectedGang then
				-- Gang Change
				if SuspectedGang ~= "NONE" then
					SetPedRelationshipGroupHash(GetPlayerPed(PlayerId()), GetHashKey(SuspectedGang))
					CurrentGang = SuspectedGang
				else
					RemovePedFromGroup(GetPlayerPed(PlayerId()))
					CurrentGang = "NONE"
				end

				-- Safe Respawn Catch
				if CurrentGang ~= "NONE" then
					if GetPedRelationshipGroupHash(GetPlayerPed(PlayerId())) ~= GetHashKey(CurrentGang) then
						SetPedRelationshipGroupHash(GetPlayerPed(PlayerId()), GetHashKey(CurrentGang))
					end
				end
			end
		end
		Citizen.Wait(0)
	end
end)

function FindPlayerSupposedGang()
	local ped = GetPlayerPed(PlayerId())
	for a = 1, #Gangs do
		for b = 1, #Gangs[a].Models do
			if IsPedModel(ped, GetHashKey(Gangs[a].Models[b])) then
				return Gangs[a].Group
			end
		end
	end
	return "NONE"
end

To be fair you don’t really need them long lines of code when you can break it down into tables and loops.

To sum it up this code will basically make the AI treat you as one of their own. If someone shoots at you they will attack etc. You can not shoot your team though. If you want to enable friendly fire on your gang then you could mess with some natives to do that.

5 Likes

Thank you, it works!

I was just a little confused on why it wasn’t changing the relationship when I changed my model. But it seems to be working this way. I think I get it now and I should be able to add vagos and lost mc to this.
:clap:

Glad it works. Some friends and I were messing the the family while we were ballas. So much fun XD.

1 Like

Ye you was right I tried the one you helped me with and it didn’t work I will try the one xander just made :stuck_out_tongue: hope it will work,thanks everyone!!! :wink:

Me and @xander1998 spent hours having fun with this script. I highly suggest everyone to use it. :laughing:

Works very well, but i did find an issue. When you switch to a non-gang ped, it doesn’t clear the relationship between the last one.

Otherwise, it works great. I’ve added vagos and lost mc already :+1:

Hm… It should clear. Maybe it was something I missed. dang.

Code doesn’t seem to work anymore ? I transformed myself into a families member and went into ballas territory and nothing happened.

Code works fine. They don’t just start shooting at you. The script just keeps from making your gang shoot at you and they will defend you.

oh okay nice,
it is possible to make it work with a job insted of peds model ?

That’s up to you. I don’t do anything with ESX or VRP because I don’t like them. (My opinion).

Possible to show a exemple if a job is named like “vagos” ?

No. Go look on the forums on how to do it. As I said.

I wrote the script standalone. Any modifications will not be done by me. I released the code as is.

I’m organizing to run in esx, should I create the client.lua with this code and the __resource.lua?

Can you do it?

I have managed to come up with something ESX-compatible from the earlier scripts mentioned. It should work as long as you have es_extended installed.

So create your __resource.lua with this:

resource_manifest_version '77731fab-63ca-442c-a67b-abc70f28dfa5'

client_scripts {
    '@es_extended/locale.lua',
    'client.lua'
}

dependencies {
    'es_extended'
}

And then create your client.lua with this:

local CurrentGang = nil

local Gangs = {
	{
		Group = "AMBIENT_GANG_BALLAS",
		Models = {
			"g_m_y_ballasout_01",
			"g_m_y_ballaorig_01",
			"csb_ballasog",
			"g_m_y_ballaeast_01",
			"a_m_y_soucent_02",
			"g_m_y_strpunk_01",
			"ig_ballasog",
			"g_f_y_ballas_01",
			"csb_grove_str_dlr"
		}
	},
	{
		Group = "AMBIENT_GANG_FAMILY",
		Models = {
			"g_f_y_families_01",
			"g_m_y_famfor_01",
			"g_m_y_famdnf_01",
			"g_m_y_famca_01",
			"mp_m_famdd_01",
			"csb_ramp_gang",
			"ig_ramp_gang"
		}
	}
}

Citizen.CreateThread(function()
	while true do
		if CurrentGang == nil then
			-- Default Gang NONE
			RemovePedFromGroup(GetPlayerPed(PlayerId()))
			CurrentGang = "NONE"
		else
			local SuspectedGang = FindPlayerSupposedGang()
			if CurrentGang ~= SuspectedGang then
				-- Gang Change
				if SuspectedGang ~= "NONE" then
					SetPedRelationshipGroupHash(GetPlayerPed(PlayerId()), GetHashKey(SuspectedGang))
					CurrentGang = SuspectedGang
				else
					RemovePedFromGroup(GetPlayerPed(PlayerId()))
					CurrentGang = "NONE"
				end

				-- Safe Respawn Catch
				if CurrentGang ~= "NONE" then
					if GetPedRelationshipGroupHash(GetPlayerPed(PlayerId())) ~= GetHashKey(CurrentGang) then
						SetPedRelationshipGroupHash(GetPlayerPed(PlayerId()), GetHashKey(CurrentGang))
					end
				end
			end
		end
		Citizen.Wait(0)
	end
end)

function FindPlayerSupposedGang()
	local ped = GetPlayerPed(PlayerId())
	for a = 1, #Gangs do
		for b = 1, #Gangs[a].Models do
			if IsPedModel(ped, GetHashKey(Gangs[a].Models[b])) then
				return Gangs[a].Group
			end
		end
	end
	return "NONE"
end

playerPed = GetPlayerPed(-1)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if DoesEntityExist(playerPed) then
			-- Ballas
			if IsPedModel(playerPed, "g_m_y_ballasout_01") or IsPedModel(playerPed, "g_m_y_ballaorig_01") or IsPedModel(playerPed, "csb_ballasog") or IsPedModel(playerPed, "g_m_y_ballaeast_01") or IsPedModel(playerPed, "a_m_y_soucent_02") or IsPedModel(playerPed, "g_m_y_strpunk_01") or IsPedModel(playerPed, "ig_ballasog") or IsPedModel(playerPed, "g_f_y_ballas_01") or IsPedModel(playerPed, "csb_grove_str_dlr") then
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_BALLAS"))
			end

			-- Families
			if IsPedModel(playerPed, "g_f_y_families_01") or IsPedModel(playerPed, "g_m_y_famfor_01") or IsPedModel(playerPed, "g_m_y_famdnf_01") or IsPedModel(playerPed, "g_m_y_famca_01") or IsPedModel(playerPed, "mp_m_famdd_01") or IsPedModel(playerPed, "csb_ramp_gang") or IsPedModel(playerPed, "ig_ramp_gang") then
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_FAMILY"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_FAMILY"))
			end
		
			-- Shared
			if IsPedModel(playerPed, "a_m_m_og_boss_01") or IsPedModel(playerPed, "a_m_y_soucent_02") or IsPedModel(playerPed, "csb_denise_friend") or IsPedModel(playerPed, "csb_g") or IsPedModel(playerPed, "g_m_y_strpunk_02") or IsPedModel(playerPed, "s_m_y_dealer_01") or IsPedModel(playerPed, "a_m_m_soucent_01") or IsPedModel(playerPed, "ig_claypain") or IsPedModel(playerPed, "ig_tonya") then
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_FAMILY"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_FAMILY"))
				SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("PLAYER"))
				SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_BALLAS"))
			end
		end
	end
end)

but esx doesn’t use peds for normal player, it use mp_ped as default since it save it in the database