Jump to content

Problem


boro

Recommended Posts

Posted

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) 
  

I'll help When I Can.

Posted

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) 

Owner of [HUN]Magyar Play Szerver 1.4, IP: 31.220.43.153:22003

  • Moderators
Posted

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) 
  
  

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

[2013-01-01 22:08:10] SCRIPT ERROR: kill\server.lua:6: 'then' expected near ')'

[2013-01-01 22:08:10] WARNING: Loading script failed: kill\server.lua:6: 'then' expected near ')'

I'll help When I Can.

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

Posted

lol now this error

[2013-01-01 22:19:46] SCRIPT ERROR: kill\server.lua:25: unexpected symbol near '=='

[2013-01-01 22:19:46] WARNING: Loading script failed: kill\server.lua:25: unexpected symbol near '=='

I'll help When I Can.

Posted
local health == getElementHealth(player) 

Remove one of the "=".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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]

I'll help When I Can.

Posted (edited)

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
  • Moderators
Posted (edited)

test it again.

If it doesn't work, check with outputDebugString("") what went wrong when you don't have any erros.

Edited by Guest

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted (edited)
  
  
           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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
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 

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