Jump to content

After two shots output message


BriGhtx3

Recommended Posts

Posted

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.

Posted

Maybe it's because of setting element data to 'true'. Eventually your player's element data gets 'true' value and it's saved even if you restart resource. So the right way is to set it to 'false' after resource starts and then test your code.

Posted

Put a debug message at the top of the code and see what your element data returns.

EDIT*: BTW is this your full code? You gave a piece of it and it's hard to help you.

Posted

So your the only one condition of getting your leg broken is to be hit in a left leg. Have you checked what element data returns with debug message? It seems that it returns 'true' and script performs its actions including your message with broken leg.

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

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

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

?

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