Peds attack players

I tried to make a gang members respect me,when I take their skin ped In game,but don’t work,any ideas what might be wrong? This hash key “0xC26D562A” is gangs and this one is skins hash key"0xF42EE883".

Citizen.CreateThread(function()
AddRelationshipGroup(“0xC26D562A”)
SetRelationshipBetweenGroups(1, GetHashKey(“0xC26D562A”), GetHashKey(“0xF42EE883”))
SetRelationshipBetweenGroups(1, GetHashKey(“0xF42EE883”), GetHashKey(“0xC26D562A”))
SetRelationshipBetweenGroups(1, GetHashKey(“0xC26D562A”), GetHashKey(“0xC26D562A”))
end)

You would have to make something where if the player model is that hash key, then set the relationship groups between the gang members and player.

(Would write the script if I wasn’t on my phone)

Maybe u got time later then maybe u can write me an example later? Would really appreciate it mate.

Here is a little script I created:

playerPed = GetPlayerPed(-1)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		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") then
			SetRelationshipBetweenGroups(1, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("PLAYER"))
			SetRelationshipBetweenGroups(1, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_BALLAS"))
		else
			SetRelationshipBetweenGroups(3, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("PLAYER"))
			SetRelationshipBetweenGroups(3, GetHashKey("PLAYER"), GetHashKey("AMBIENT_GANG_BALLAS"))
		end
	end
end)

-- Do the same for other gangs

(You will have to make it keep checking for the model.)

Here are my sources:
http://ragepluginhook.net/PedModels.aspx

1 Like

Wow thank you mate you are legend! :wink:

1 Like

@En3rgized247 I’m trying to make sure the NPC of ballas does not get in the way of who the gangs are
ex: I’m from the gang ballas job ballas

wanted when when the player had the job ballas npc do not attack this player

already tried everything that is code type until I made a mix of codic more does not work

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()
    AddRelationshipGroup("ballas")
    SetRelationshipBetweenGroups(5, GetHashKey("ballas"), GetHashKey("AMBIENT_GANG_BALLAS"))
    SetRelationshipBetweenGroups(5, GetHashKey("AMBIENT_GANG_BALLAS"), GetHashKey("ballas"))
    SetRelationshipBetweenGroups(5, GetHashKey("ballas"), GetHashKey("ballas"))
end)


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

could you help me with this?

Hello everyone!

I am looking for a way to build a fresh PED RIOT script:

I want all PEDs to attack players during a certain time frame…

I want all PEDs to either attack with their vehicles or hands (no guns involved unless up north sandy…)

If you are up for this challenge please DM asap so we can work it out!

BPC_DECIUM#0420

1 Like

Not sure if you have got this working yet.
My Crackdown Mission Resource does this. Download link is in the latest thread for it. Check out the HostileAmbientPeds setting in Missions.lua and client.lua. There are other config settings as well for ambient ped weapons (melee etc…), and behavior, stay in car or get out etc… It is based on uranium’s answer in this thread. You could probably take that part easily and adapt it. You can use GetNameOfZone which takes in coords and returns the name of the zone (i.e “SANDY” = Sandy Shores)…

Then use GetGameTimer() to time how long the relation loop lasts for (see uraniums post). I think once you break out of the loop, any new ambient peds should default back to default relationship, not sure if you would need to then set back the relationships in script or not, probably not.

Are you using a command to activate this during game play? My home server is just for my two sons and I to play cops and they are begging me to add a way to start a riot for them to defuse lol

did u find this ?

I’m really new to all of this. Lots of programming experience, but first time with Lua, and first time hacking at GTA. I’m setting up a server for my friends and I, and just want a crazy “riot mode” server. I’ve been all over these forums, looking at the various examples, and managed to slap together this, based on a few examples I’ve seen.

I’m seeing some strange behavior. I’ve got it setup to everyone hates everyone. But, a player needs to be pretty close, within 5 meters, or a player needs to discharge a weapon, before the Peds will react or do anything. Some times I can get them started, and they keep themselves going around a busy intersection. Other times, nothing happens until a player instigates it.

I have two things I’m trying to do now.

1 - Have the peds behave aggressively all the time, without a player instigating it.
2 - Spawn more peds near players. Basically like the Script Hook based riot mode from several of the trainers.

Because I’ve seen some code shared here, here is what I’ve mangled together for my client scripting.

Config = {}

-- 0, just attack the player. 1, total chaos
Config.HostilePeds = 1

Config.RandomWeapons = {
	"WEAPON_KNIFE", 
	"WEAPON_NIGHTSTICK",
	"WEAPON_KNIFE", 
	"WEAPON_NIGHTSTICK",
	"WEAPON_PISTOL",
	"WEAPON_COMBATPISTOL",
	"WEAPON_PISTOL",
	"WEAPON_COMBATPISTOL",
	"WEAPON_PISTOL50", 
	"WEAPON_MICROSMG", 
	"WEAPON_SMG",
	"WEAPON_ASSAULTSMG",
	"WEAPON_MICROSMG", 
	"WEAPON_SMG",
	"WEAPON_ASSAULTSMG",
	"WEAPON_ASSAULTRIFLE", 
	"WEAPON_CARBINERIFLE", 
	"WEAPON_ADVANCEDRIFLE", 
	"WEAPON_PUMPSHOTGUN", 
	"WEAPON_SAWNOFFSHOTGUN",
	"WEAPON_SAWNOFFSHOTGUN",
	"WEAPON_SAWNOFFSHOTGUN",
	"WEAPON_BULLPUPSHOTGUN",
	"WEAPON_SPECIALCARBINE",
	"WEAPON_HEAVYPISTOL",
}

-- Experiement with Ped density. No impact.
--[[
Config.PedDensity = 1

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		SetPedDensityMultiplierThisFrame(Config.PedDensity)
		SetScenarioPedDensityMultiplierThisFrame(Config.PedDensity,Config.PedDensity)
	end
end)
]]--

local relationshipTypes = {
	"PLAYER",
	"CIVMALE",
	"CIVFEMALE",
	"COP",
	"SECURITY_GUARD",
	"PRIVATE_SECURITY",
	"FIREMAN",
	"GANG_1",
	"GANG_2",
	"GANG_9",
	"GANG_10",
	"AMBIENT_GANG_LOST",
	"AMBIENT_GANG_MEXICAN",
	"AMBIENT_GANG_FAMILY",
	"AMBIENT_GANG_BALLAS",
	"AMBIENT_GANG_MARABUNTE",
	"AMBIENT_GANG_CULT",
	"AMBIENT_GANG_SALVA",
	"AMBIENT_GANG_WEICHENG",
	"AMBIENT_GANG_HILLBILLY",
	"DEALER",
	"HATES_PLAYER",
	"HEN",
	"WILD_ANIMAL",
	"SHARK",
	"COUGAR",
	"NO_RELATIONSHIP",
	"SPECIAL",
	"MISSION2",
	"MISSION3",
	"MISSION4",
	"MISSION5",
	"MISSION6",
	"MISSION7",
	"MISSION8",
	"ARMY",
	"GUARD_DOG",
	"AGGRESSIVE_INVESTIGATE",
	"MEDIC",
	"CAT",
}

local RELATIONSHIP_HATE = 5
local RELATIONSHIP_COMPANION = 0

Citizen.CreateThread(function()
	print('Starting Ped Loop')
	while true do
		Citizen.Wait(10)
		for _, group in ipairs(relationshipTypes) do
			SetRelationshipBetweenGroups(RELATIONSHIP_HATE, GetHashKey(group), GetHashKey('PLAYER'))
			if Config.HostilePeds > 0 then
				for _, group2 in ipairs(relationshipTypes) do
					SetRelationshipBetweenGroups(RELATIONSHIP_HATE, GetHashKey(group), GetHashKey(group2))
					SetRelationshipBetweenGroups(RELATIONSHIP_HATE, GetHashKey(group2), GetHashKey(group))
				end
			end
		end
		for Ped in EnumeratePeds() do
			equipPed(Ped)
		end
    end
end)
 
function equipPed(Ped)
	-- Not a human, or the player? Ignore it.
	if (not IsPedHuman(Ped)) or (GetPedRelationshipGroupDefaultHash(Ped)==GetHashKey('PLAYER') or GetPedRelationshipGroupHash(Ped)==GetHashKey('PLAYER')) or (GetBestPedWeapon(Ped,0)~=GetHashKey("WEAPON_UNARMED")) then 
		return
	end
	local randomPedWeapon = Config.RandomWeapons[ math.random( #Config.RandomWeapons ) ]
	SetPedCombatAttributes(Ped, 5, true)	
	SetPedCombatAttributes(Ped, 16, true)
	SetPedCombatAttributes(Ped, 46, true)
	SetPedCombatAttributes(Ped, 26, true)
	SetPedCombatAttributes(Ped, 2, true)
	SetPedCombatAttributes(Ped, 1, true)
	SetPedDiesWhenInjured(Ped, true)
	GiveWeaponToPed(Ped, GetHashKey(randomPedWeapon), 2800, false, true)
	SetPedInfiniteAmmo(Ped, true, randomPedWeapon)
	SetPedFleeAttributes(Ped, 0, 0)
	SetPedPathAvoidFire(Ped,1)
	SetPedPathCanUseLadders(Ped,1)
	SetPedPathCanDropFromHeight(Ped,1)
	SetPedPathCanUseClimbovers(Ped,1)
	SetPedAlertness(Ped,3)
	SetPedCombatRange(Ped,2)
	SetPedAllowedToDuck(Ped,1)
	if(randomPedWeapon == 0x42BF8A85) then
		SetPedFiringPattern(Ped, 0x914E786F) --FIRING_PATTERN_BURST_FIRE_HELI
	end
	ResetAiWeaponDamageModifier()
	SetAiWeaponDamageModifier(0.2) -- 1.0 == Normal Damage. 
	AddArmourToPed(Ped, 50) --<**is 100 max for npc???**
	SetPedArmour(Ped, 50)
end

local entityEnumerator = {
  __gc = function(enum)
    if enum.destructor and enum.handle then
      enum.destructor(enum.handle)
    end
    enum.destructor = nil
    enum.handle = nil
  end
}

local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
  return coroutine.wrap(function()
    local iter, id = initFunc()
    if not id or id == 0 then
      disposeFunc(iter)
      return
    end
    
    local enum = {handle = iter, destructor = disposeFunc}
    setmetatable(enum, entityEnumerator)
    
    local next = true
    repeat
      coroutine.yield(id)
      next, id = moveFunc(iter)
    until not next
    
    enum.destructor, enum.handle = nil, nil
    disposeFunc(iter)
  end)
end

function EnumeratePeds()
  return EnumerateEntities(FindFirstPed, FindNextPed, EndFindPed)
end
2 Likes