Jump to content

[HELP] onClientWeaponFire


erisP

Recommended Posts

I want the gun I put in the vehicle not to harm the players of the same team.

function noDamageToPlayersFromCustomWeapons(target)
    if target == exports.Teams:isPlayerInTeam(localPlayer, "Red") and exports.Teams:isPlayerInTeam(localPlayer, "Red") then
        cancelEvent() 
    end
end
addEventHandler("onClientWeaponFire", root, noDamageToPlayersFromCustomWeapons)

 

Edited by erisP
Link to comment

try this

function noDamageToPlayersFromCustomWeapons(target)
    if(getElementType(target) == "player") then
       local playerTeam = exports.Teams:isPlayerInTeam(localPlayer, "Red")
       local targetTeam = exports.Teams:isPlayerInTeam(target, "Red")
       if (playerTeam == targetTeam) then
          cancelEvent() 
       end
    end  
end
addEventHandler("onClientWeaponFire", root, noDamageToPlayersFromCustomWeapons)

 

Link to comment
15 minutes ago, erisP said:

It doesn't give an error, but when I switch to the blue team, the player in the red team still does not take damage. The red team can't hurt each other, but the blue team can hurt the red team.

 

The blue team and the red team are separate teams, your code only checks the red team, and if you want to turn off friendlyFire for the blue team, you can do it this way

function noDamageToPlayersFromCustomWeapons(target)
    if(target and getElementType(target) == "player") then
       local playerTeam = getPlayerTeam(localPlayer)
       local targetTeam = getPlayerTeam(target)
       local playerTeamName
       local targetTeamName

       if(playerTeam and targetTeam) then
          playerTeamName = getTeamName(playerTeam)
          targetTeamName = getTeamName(targetTeam)
          
          if (playerTeamName == targetTeamName) then
             cancelEvent() 
          end
       end

    end  
end
addEventHandler("onClientWeaponFire", root, noDamageToPlayersFromCustomWeapons)

 

but remember this will be valid for all teams if you want to create a team with friendly fire on except for blue and red you will need to edit the code

Edited by Burak5312
Link to comment
13 minutes ago, Burak5312 said:

 

The blue team and the red team are separate teams, your code only checks the red team, and if you want to turn off friendlyFire for the blue team, you can do it this way

function noDamageToPlayersFromCustomWeapons(target)
    if(target and getElementType(target) == "player") then
       local playerTeam = getPlayerTeam(localPlayer)
       local targetTeam = getPlayerTeam(target)
       local playerTeamName
       local targetTeamName

       if(playerTeam and targetTeam) then
          playerTeamName = getTeamName(playerTeam)
          targetTeamName = getTeamName(targetTeam)
          
          if (playerTeamName == targetTeamName) then
             cancelEvent() 
          end
       end

    end  
end
addEventHandler("onClientWeaponFire", root, noDamageToPlayersFromCustomWeapons)

 

but remember this will be valid for all teams if you want to create a team with friendly fire on except for blue and red you will need to edit the code

it didn't work, the red team players should not hurt each other, the blue team should hurt the red team, that's all I wanted.
Edited by erisP
Link to comment
56 minutes ago, erisP said:

It doesn't give an error, but when I switch to the blue team, the player in the red team still does not take damage. The red team can't hurt each other, but the blue team can hurt the red team.

you already got what you want here what more do you want?
Link to comment
28 minutes ago, Burak5312 said:
 

No team can hurt the red team and what you did is wrong. The blue team needs to deal damage, so I can't use it.

Another team needs to damage the red team. When I use your code, the blue team doesn't make any sense as long as it doesn't damage the red team.

Edited by erisP
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...