Jump to content

Anti teamkill


Xwad

Recommended Posts

Posted

hi! What funvtions need i use to make a script that disables the explosion demage on the rhino if a rhino shot it. I mean if i shoot the rhino with a rhino then the rhino will not demaged.

Posted

just an example

  
function noshootteam(attacker, target ) 
if isPedInVehicle(attacter) then 
if getElementData( attacker,"cop") == true then 
    if getElementData( target,"cop") == true then 
         outputChatBox ( "Don't Shoot Your TeamMates!",attacker, 255, 0, 0 ) 
         cancelEvent() 
    end 
end 
end 
end 
addEventHandler ( "onClientPlayerDamage", root, noshootteam ) 

Posted

Thanks. I tryed to make it but its not working:/ The debugscript said something problem with 'then'

  
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
if getElementModel( attacker ) == 432) == true then 
    if getElementModel( target ) == 432) == true then 
         outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
         cancelEvent() 
end 
end 
end 
end 
addEventHandler ( "onClientVehicleDamage", root, teamkill ) 
  

Posted

Its not working:/

  
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
if (getElementModel ( attacker ) == 432) == true then 
if (getElementModel ( target ) == 432) == true then 
         outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
         cancelEvent() 
end 
end 
end 
end 
addEventHandler ( "onClientVehicleDamage", root, teamkill ) 
  
  

Posted

It is not working because you are using onClientVehicleDamage's arguments in a wrong way. Either way, you are using attacter at isPedInVehicle - a non-defined variable.

  
addEventHandler("onClientVehicleDamage", root, 
    function(attacker) 
        if getElementModel(source) ~= 432 then return end -- avoid this function from executing in case the vehicle that is being damaged is not a tank(?) 
        if getElementModel(attacker) == 432 then -- in case attacker's model is equal to 432 
            if getVehicleController(attacker) == localPlayer then -- in case the attacker tank's driver is the localPlayer 
                outputChatBox("Don't attack friendly tanks!", 255, 0, 0) -- a warning message is output 
            end 
            cancelEvent() 
        end 
    end 
) 
  

Posted

Try this one.

I just searched some codes made by TAPL.

addEventHandler("onClientVehicleDamage", root, 
function(attacker) 
    if attacker and getElementType(attacker) == "player" then 
        local driver = getVehicleController(source) 
        if driver then 
            local attackerTeam = getPlayerTeam(attacker) 
            local driverTeam = getPlayerTeam(driver) 
            if attackerTeam and driverTeam and attackerTeam == driverTeam then 
                cancelEvent() 
            end 
        end 
    end 
end) 

Posted
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
if (getElementModel ( attacker ) == 432) then 
    if (getElementModel ( target ) == 432) then 
         outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
         cancelEvent() 
end 
end 
end 
end 
addEventHandler ( "onVehicleDamage", root, teamkill ) 

If there is a error please post it

Posted
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
if (getElementModel ( attacker ) == 432) then 
    if (getElementModel ( target ) == 432) then 
         outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
         cancelEvent() 
end 
end 
end 
end 
addEventHandler ( "onVehicleDamage", root, teamkill ) 

If there is a error please post it

The event onVehicleDamage can't be canceled.

Posted
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
    if (getElementModel ( attacker ) == 432) then 
        if (getElementModel ( target ) == 432) then 
             outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
             fixVehicle( target ) 
        end 
   end 
end 
end 
addEventHandler ( "onVehicleDamage", root, teamkill ) 

idk if it will work

Posted
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
    if (getElementModel ( attacker ) == 432) then 
        if (getElementModel ( target ) == 432) then 
             outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
             fixVehicle( target ) 
        end 
   end 
end 
end 
addEventHandler ( "onVehicleDamage", root, teamkill ) 

idk if it will work

Of course it won't work because the event onVehicleDamage have only one argument which is loss. Stop trying to help peoples when you don't even know the basic things.

Posted
function teamkill(attacker, target ) 
if isPedInVehicle(attacter) then 
    if (getElementModel ( attacker ) == 432) then 
        if (getElementModel ( target ) == 432) then 
             outputChatBox ( "Don't attack friendly tanks!",attacker, 255, 0, 0 ) 
             fixVehicle( target ) 
        end 
   end 
end 
end 
addEventHandler ( "onVehicleDamage", root, teamkill ) 

idk if it will work

Of course it won't work because the event onVehicleDamage have only one argument which is loss. Stop trying to help peoples when you don't even know the basic things.

Just saying that is mean

the man is trying to help ... While you're just writing ...

Posted
So is it impossible to make that script?:( But thanks for your help! maybe with setElementHealth?

Nothing is impossible maybe try onClientVehicleDamge? and remove attacker from the output line. I guess.

Posted
  
addEventHandler("onClientVehicleDamage", root, 
    function(attacker) 
        if getElementModel(source) ~= 432 then return end -- avoid this function from executing in case the vehicle that is being damaged is not a tank(?) 
        if getElementModel(getPedOccupiedVehicle(attacker)) == 432 then -- in case attacker's model is equal to 432 
            if attacker == localPlayer then -- in case the attacker tank's driver is the localPlayer 
                outputChatBox("Don't attack friendly tanks!", 255, 0, 0) -- a warning message is output 
            end 
            cancelEvent() 
        end 
    end 
) 
  

What about this? You could've either way tried to modify the code on your own, lol.

Posted

not wroking:/ Maybe can it make by teams? i mean if there are 2 teams and the team mate shoots the teammate then he will not be demaged?

Posted
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        setTeamFriendlyFire(getTeamFromName("YOUR_TEAM_NAME"), false) 
    end 
) 
  

  • Moderators
Posted

Tanks can't damage other tanks, only the fire of the explosion causes damage. (fire damage can't be detected well and most of the time there is no owner)

That you guys haven't figure that out yet. O_o

  • Moderators
Posted
But i made a script that makes possible that explosion can demage tanks..

Then you have to edit that one... :fadein:

Posted

Here is the script but i dont know how to cancel the event when the rhino is shooting:/

cleint.lua

addEventHandler ( "onClientExplosion", root, function ( x, y, z )  
 for i, v in ipairs ( getElementsByType ( "vehicle" ) ) do  
  local vx, vy, vz = getElementPosition ( v ); 
  if ( getDistanceBetweenPoints3D ( x, y, z, vx, vy, vz ) <= 20 and getElementModel ( v ) == 432 ) then  
  triggerServerEvent ( "OnRhinoDamageFromExplosion", v, (20 / getDistanceBetweenPoints3D ( x, y, z, vx, vy, vz ))*13  ); 
  end 
 end 
end ) 

server.lua

addEvent ( "OnRhinoDamageFromExplosion", true ); 
addEventHandler ( "OnRhinoDamageFromExplosion", root, function ( d )  
 setElementHealth ( source, getElementHealth ( source ) - d ); 
end ); 

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...