Jump to content

Problem


boro

Recommended Posts

Hi all i make script, when zombie damage player then set health go slow down, but it don't work please help

setTimer(function() 
       if ( attacker and attacker ~= source and getElementType ( attacker ) == "ped" ) then 
            setElementHealth(source, getElementHealth(source)-1) 
     end 
end, 200, 0) 
  
addEventHandler("onPlayerDamage", getRootElement(),  
        function() 
        end) 
  

Link to comment

Your code is absolutely wrong. Something like this should work:

addEventHandler("onPlayerDamage", getRootElement(), 
    function(attacker) 
        if ( attacker and attacker ~= source and getElementType ( attacker ) == "ped" ) then 
            setTimer( 
                function( player ) 
                    setElementHealth( player, getElementHealth( player ) - 1 ) 
                end, 200, 20, source ) 
        end 
    end) 

Link to comment
  • Moderators

Try both pls:

local myVictimData = {} 
local timerRunning = false 
  
--local player = source reduce ppppiiieeppp bugs.... 
function victim_def(attacker) 
    if attacker and attacker ~= source and getElementType ( attacker ) == "ped" ) then 
         local player = source 
         myVictimData[player]={} 
         timerRunning = true 
         if not damagetimer then 
         setTimer( damagetimer, 200, 0) 
         end 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), victim_def) 
  
function damagetimer () 
    if  timerRunning == false then 
     killTimer (damagetimer) 
    return 
    end 
    local activetimer = 0 
    for k,player in ipairs(myVictimData) do 
    activetimer = activetimer +1 
        local health == getElementHealth(player) 
        if health > 0 then 
            setElementHealth(player, health-1) 
        else 
            killPed(player) 
        end 
    end 
    if activetimer == 0 then  
         timerRunning = false 
    end 
end 
  
function resourceStart () 
setTimer( damagetimer, 200, 0) 
end 
addEventHandler ( "onResourceStart", resourceRoot, resourceStart ) 
  
function on_Player_Quit() -- remove him from the table when he leaves  
    local player = source 
    myVictimData[player] = nil 
end 
addEventHandler ( "onPlayerQuit", getRootElement(),on_Player_Quit) 
  
function on_Player_Wasted () -- remove him from the table when he get killed 
    local player = source; 
    myVictimData[player] = nil 
end 
addEventHandler ( "onPlayerWasted", getRootElement(),on_Player_Wasted) 
  
  

Link to comment
    local myVictimData = {} 
    local timerRunning = false 
      
    --local player = source reduce ppppiiieeppp bugs.... 
    function victim_def(attacker) 
        if attacker and attacker ~= source and getElementType ( attacker ) == "ped"  then 
             local player = source 
             myVictimData[player]={} 
             timerRunning = true 
             if not damagetimer then 
             setTimer( damagetimer, 200, 0) 
             end 
        end 
    end 
    addEventHandler("onPlayerDamage", getRootElement(), victim_def) 
      
    function damagetimer () 
        if  timerRunning == false then 
         killTimer (damagetimer) 
        return 
        end 
        local activetimer = 0 
        for k,player in ipairs(myVictimData) do 
        activetimer = activetimer +1 
            local health == getElementHealth(player) 
            if health > 0 then 
                setElementHealth(player, health-1) 
            else 
                killPed(player) 
            end 
        end 
        if activetimer == 0 then 
             timerRunning = false 
        end 
    end 
      
    function resourceStart () 
    setTimer( damagetimer, 200, 0) 
    end 
    addEventHandler ( "onResourceStart", resourceRoot, resourceStart ) 
      
    function on_Player_Quit() -- remove him from the table when he leaves 
        local player = source 
        myVictimData[player] = nil 
    end 
    addEventHandler ( "onPlayerQuit", getRootElement(),on_Player_Quit) 
      
    function on_Player_Wasted () -- remove him from the table when he get killed 
        local player = source; 
        myVictimData[player] = nil 
    end 
    addEventHandler ( "onPlayerWasted", getRootElement(),on_Player_Wasted) 
      
      

Link to comment

hm now this

[2013-01-01 22:23:55] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:55] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:56] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:62] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:65] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:67] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:69] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:71] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:74] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

[2013-01-01 22:23:76] WARNING: kill\server.lua:19: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got function]

Link to comment

try this one, maybe it'll work

        local myVictimData = {} 
        local timerRunning = false 
          
        --local player = source reduce ppppiiieeppp bugs.... 
        function victim_def(attacker) 
            if attacker and attacker ~= source and getElementType ( attacker ) == "ped"  then 
                 local player = source 
                 myVictimData[player]={} 
                 timerRunning = true 
                 if not damagetimer then 
                 setTimer( damagetimer, 200, 0) 
                 end 
            end 
        end 
        addEventHandler("onPlayerDamage", getRootElement(), victim_def) 
          
        function damagetimer () 
            if  timerRunning == false then return end 
             if isTimer(damageTimer) then killTimer (damagetimer) end 
            local activetimer = 0 
            for k,player in ipairs(myVictimData) do 
            activetimer = activetimer +1 
                local health = getElementHealth(player) 
                if health > 0 then 
                    setElementHealth(player, health-1) 
                else 
                    killPed(player) 
                end 
            end 
            if activetimer == 0 then 
                 timerRunning = false 
            end 
        end 
          
        function resourceStart () 
        setTimer( damagetimer, 200, 0) 
        end 
        addEventHandler ( "onResourceStart", resourceRoot, resourceStart ) 
          
        function on_Player_Quit() -- remove him from the table when he leaves 
            local player = source 
            myVictimData[player] = nil 
        end 
        addEventHandler ( "onPlayerQuit", getRootElement(),on_Player_Quit) 
          
        function on_Player_Wasted () -- remove him from the table when he get killed 
            local player = source; 
            myVictimData[player] = nil 
        end 
        addEventHandler ( "onPlayerWasted", getRootElement(),on_Player_Wasted) 
          
          

Edited by Guest
Link to comment
  • Moderators
  
  
           local myVictimData = {} 
            local timerRunning = false 
              
            --local player = source reduce ppppiiieeppp bugs.... 
            function victim_def(attacker) 
                if attacker and attacker ~= source and getElementType ( attacker ) == "ped"  then 
                     local player = source 
                     myVictimData[player]={} 
                     timerRunning = true 
                     if not isTimer(dmgtimer) then 
                     dmgtimer = setTimer( damagetimer, 200, 0) 
                     end 
                end 
            end 
            addEventHandler("onPlayerDamage", getRootElement(), victim_def) 
              
            function damagetimer () 
                if  timerRunning == false then  
                if isTimer(dmgtimer) then killTimer (dmgtimer) end 
                return end 
                  
                local activetimer = 0 
                for k,player in ipairs(myVictimData) do 
                activetimer = activetimer +1 
                    local health = getElementHealth(player) 
                    if health > 0 then 
                        setElementHealth(player, health-1) 
                    else 
                        killPed(player) 
                    end 
                end 
                if activetimer == 0 then 
                     timerRunning = false 
                end 
            end 
              
            function resourceStart () 
             dmgtimer = setTimer( damagetimer, 200, 0) 
            end 
            addEventHandler ( "onResourceStart", resourceRoot, resourceStart ) 
              
            function on_Player_Quit() -- remove him from the table when he leaves 
                local player = source 
                myVictimData[player] = nil 
            end 
            addEventHandler ( "onPlayerQuit", getRootElement(),on_Player_Quit) 
              
            function on_Player_Wasted () -- remove him from the table when he get killed 
                local player = source; 
                myVictimData[player] = nil 
            end 
            addEventHandler ( "onPlayerWasted", getRootElement(),on_Player_Wasted) 
  
          

Edited by Guest
Link to comment
addEventHandler ( "onPlayerDamage", root, 
    function ( attacker ) 
        if attacker then 
            if getElementType ( attacker ) == "player" and attacker ~= source then  
                if isTimer ( theTimer ) then killTimer ( theTimer ) end 
                local player = source 
                theTimer = setTimer ( Damage, 1000, 0, player ) 
            end 
        end 
    end 
) 
  
function Damage ( player ) 
    local health = getElementHealth ( player ) 
    if health > 5 then 
        setElementHealth ( player, health -1 ) 
    else 
        killPed ( player ) 
        if isTimer ( theTimer ) then killTimer ( theTimer ) end 
    end 
    fadeCamera ( player, false, 1.0, 255, 0, 0 ) 
    setTimer ( fadeCamera, 500, 1, player, true, 0.5 )   
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...