erisP Posted August 21, 2021 Share Posted August 21, 2021 (edited) 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 August 21, 2021 by erisP Link to comment
βurak Posted August 21, 2021 Share Posted August 21, 2021 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
erisP Posted August 21, 2021 Author Share Posted August 21, 2021 10 minutes ago, Burak5312 said: bunu dene WARNING: customweap/client.lua:210: Bad Argument @ 'getElementType' [Expected element at argument 1, got nil] Link to comment
βurak Posted August 21, 2021 Share Posted August 21, 2021 (edited) Change the if structure where getElementType is like this if(target and getElementType(target) == "player") then Edited August 21, 2021 by Burak5312 Link to comment
erisP Posted August 21, 2021 Author Share Posted August 21, 2021 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. Link to comment
βurak Posted August 21, 2021 Share Posted August 21, 2021 (edited) 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 August 21, 2021 by Burak5312 Link to comment
erisP Posted August 21, 2021 Author Share Posted August 21, 2021 (edited) 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 August 21, 2021 by erisP Link to comment
βurak Posted August 21, 2021 Share Posted August 21, 2021 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
erisP Posted August 21, 2021 Author Share Posted August 21, 2021 (edited) 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 August 21, 2021 by erisP Link to comment
βurak Posted August 21, 2021 Share Posted August 21, 2021 (edited) Can you change root to localPlayer? I'm not sure but it might work addEventHandler("onClientWeaponFire", localPlayer, noDamageToPlayersFromCustomWeapons) Edited August 21, 2021 by Burak5312 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now