Friendly fire: How to properly assign teams

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.

14 Likes

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

Thanks. (20charrrrrr)

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.

Using this exact method, we werent able to disable pvp, but if players are in a certain group and the other group hates them, they cant sit in a car together because the Players i nthe other team will constantly be kicked out of the car as as sonn as i start the engine