Jump to content

Anti teamkill


Xwad

Recommended Posts

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 ) 

Link to comment

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 ) 
  

Link to comment

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 ) 
  
  

Link to comment

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 
) 
  

Link to comment

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) 

Link to comment
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

Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
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 ...

Link to comment
  
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.

Link to comment
  • Moderators

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

Link to comment

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 ); 

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