Friendly fire: How to properly assign teams


#1

prerequisite:

NetworkSetFriendlyFireOption(false)

(without this friendly fire might be enabled)

then:

-- on every client
AddRelationshipGroup('team1')
AddRelationshipGroup('team2')

SetRelationshipBetweenGroups(5, 'team1', 'team2')
SetRelationshipBetweenGroups(5, 'team2', 'team1')

-- locally, probably; might need setting on every client for every other player ped
SetPedRelationshipGroupHash(PlayerPedId(), 'team2') -- or team1

basically, deciding this uses the same system that AI peds would use in deciding whether or not to attack: with friendly fire off, you can only damage players that you have a non-neutral (or perhaps, hateful) relationship with.


How to enable friendly fire in a way certain people can kill you and others cant?
Team Deathmatch setup?
How native team functions works?
#2

Nice, I think this will help a lot of people :slight_smile:


#3

Thanks. (20charrrrrr)


#4

So you fixed it? Few months ago all players were “PLAYER” relationship whatever you do with them.

local relgroup=GetHashKey("PLAYER")
while true do
        Wait(0)
        local myself=PlayerId()
        SetPlayerTeam(myself,my_team)
        SetCanAttackFriendly(PlayerPedId(),true,true)
        local campos=GetGameplayCamCoord()
        for i=0,31 do
            if i~=myself then
                local ped=GetPlayerPed(i)
                local team=GetPlayerTeam(i)
                local friend=(team==my_team)
                SetEntityCanBeDamagedByRelationshipGroup(ped,not friend,relgroup)
                SetPedCanBeTargettedByTeam(ped,team,false)
                if friend then
                    local pos=GetEntityCoords(ped)
                    local not_on_screen,x,y=N_0xf9904d11f1acbec3(pos.x,pos.y,pos.z+0.35)

We used SetEntityCanBeDamagedByRelationshipGroup without changing relationship grops for players because nothing else worked.