Jump to content

After two shots output message


BriGhtx3

Recommended Posts

Hey,

when someone shoots at me I want that only after the second bullet which hits me I get a message (in onPlayerDamage):

if weapon then 
if getElementData(player, "shot1") == false then 
setElementData(player, "shot1", true) 
return 
end 
end 
  
if getElementData(player, "shot1") then 
setElementData(player, "shot1", false) 
end 
  
if place == 7 then 
outputChatBox("You broke your left leg", player) 
end 
  

The problem is that the message gets output after the first time I get shot.

Link to comment
function onBrokenLeg ( attacker, weapon, bodypart ) 
  
if weapon then 
if not getElementData(source, "shot1") then 
setElementData(source, "shot1", true) 
return 
end 
end 
  
if getElementData(source, "shot1") then 
setElementData(source, "shot1", false) 
end 
  
if bodypart == 7 then 
outputChatBox("You broke your left leg") 
end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onBrokenLeg ) 

This code works if you get shot twice. Element data 'shot1' must be set to 'false' when your resource starts.

Link to comment
local aShot = { }; 
  
addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( ) 
        for _, pUser in ipairs( getElementsByType 'player' ) do 
            aShot[pUser] = 0; 
        end 
        -- 
        addEventHandler( 'onClientPlayerDamage', root, onShot ); 
        addEventHandler( 'onClientPlayerQuit', root, onLeave ); 
    end 
); 
  
onShot = function( pAttacker, iWeapon, iBPart ) 
    if( pAttacker and iWeapon ) then 
        if( aShot[pAttacker] ) then 
            aShot[pAttacker] = aShot[pAttacker] + 1; 
        end 
        -- 
        if( aShot[pAttacker] == 2 ) then 
            if( iBPart == 7 ) then 
                outputChatBox( 'You broke your left leg!', source, 255, 255, 255, false ); 
                aShot[pAttacker] = 0; 
            end 
        end 
    end 
end 
  
onLeave = function( ) 
    if( aShot[source] ) then 
        aShot[source] = nil; 
    end 
end 

Not tested.

Link to comment
Now I only need one shot.
function onBrokenLeg ( attacker, weapon, bodypart ) 
  
if weapon then 
    if bodypart == 7 and not getElementData(source,"brokenleft") then 
     setElementData(source, "brokenleft", true) 
     outputChatBox("You broke your left leg") 
    end 
end 
  
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onBrokenLeg ) 

?

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