Jump to content

[solved]scripts not working


Recommended Posts

Posted

Hey, this should work

function medkit(attacker, weapon) 
     --if weapon == (medkitid) then 
     timer = setTimer(heal, 3000, 20, source) 
     --end 
end 
 addEventHandler ( "onPlayerDamage", root,medkit) 
  
 function heal(player) 
    health = getElementHealth (player) 
    if (health < 100) then setElementHealth(player,health+5) 
    else if (isTimer(timer)) then killTimer(timer) end 
    end 
 end 

Posted
Hey, this should work
function medkit(attacker, weapon) 
     --if weapon == (medkitid) then 
     timer = setTimer(heal, 3000, 20, source) 
     --end 
end 
 addEventHandler ( "onPlayerDamage", root,medkit) 
  
 function heal(player) 
    health = getElementHealth (player) 
    if (health < 100) then setElementHealth(player,health+5) 
    else if (isTimer(timer)) then killTimer(timer) end 
    end 
 end 

that's work , but i wanted it to heal +5 every 5 sec not +5 heal every shot theplayer got
Posted
function medkit(attacker, weapon) 
    if weapon == (medkitid) then 
       healTimer = setTimer( 
              function() 
              heal = getElementHealth(source) 
              if (heal < 100) then 
                 setElementHealth(source, heal+5) 
              elseif (isTimer(healTimer)) then  
                  killTimer(healTimer) 
             end 
        end, 5000, 20, source) 
    end 
end 
addEventHandler("onPlayerDamage", root, medkit) 

 

 

Posted

what I've made heals you +5 hp in every 3 secs after you get any damage, but you have to write an if statement with the medickit's weapon id, about while loop I am sure LUA has time/date function for that, but you should stick to the setTimer function because it's way more easier.

Posted
function medkit(attacker, weapon) 
    if weapon == (medkitid) then 
       doHeal = true 
       while (doHeal) do 
              health = getElementHealth(source) 
              if (health < 100) then 
                 setElementHealth(source, health + 5) 
              else 
                  doHeal = false 
             end 
    end 
end 
addEventHandler("onPlayerDamage", root, medkit) 

Not tested, but if you want while shouldn't this work then?

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted (edited)
what I've made heals you +5 hp in every 3 secs after you get any damage, but you have to write an if statement with the medickit's weapon id, about while loop I am sure LUA has time/date function for that, but you should stick to the setTimer function because it's way more easier.

oh, my bad its working perfectly ,thnx

but i don't know why it heals +5 like 3 times in the same sec , can you help me?

Edited by Guest
Posted
function medkit(attacker, weapon) 
    if weapon == (medkitid) then 
       doHeal = true 
       while (doHeal) do 
              health = getElementHealth(source) 
              if (health < 100) then 
                 setElementHealth(source, health + 5) 
              else 
                  doHeal = false 
             end 
    end 
end 
addEventHandler("onPlayerDamage", root, medkit) 

Not tested, but if you want while shouldn't this work then?

not working but thnx anyway

Posted
  
function medkit(attacker, weapon)      
    timer = setTimer(heal, 3000, 1, source)      
end 
addEventHandler ( "onPlayerDamage", root,medkit) 
  
function heal(player) 
    health = getElementHealth (player) 
    if (health < 100) then setElementHealth(player,health+5) 
    elseif (isTimer(timer)) then killTimer(timer)  
    end 
end 
  

Posted (edited)
  
function medkit(attacker, weapon)      
    timer = setTimer(heal, 3000, 1, source)      
end 
addEventHandler ( "onPlayerDamage", root,medkit) 
  
function heal(player) 
    health = getElementHealth (player) 
    if (health < 100) then setElementHealth(player,health+5) 
    elseif (isTimer(timer)) then killTimer(timer)  
    end 
end 
  

that only works once

Edited by Guest
Posted

now i mad this

function wio(player) 
 health = getElementHealth (player) 
if (health>100) then 
setElementHealth(player,health+1) 
end 
end 
addEventHandler ("onPlayerDamage",root,wio) 
function oiu(player) 
timer=setTimer(wio,400,30) 
end 
addEventHandler("onPlayerDamage",root,oiu)  

and then (bad argument @ 'getElementHealth expexted element at argument 1, got nil])

can you fix it and tell me why is this happening

Posted
function wio() 
    health = getElementHealth(source) 
    if health > 100 then 
       setElementHealth(source, health+1) 
    end 
end 
addEventHandler("onPlayerDamagae", root, wio) 
  
function oiu() 
   timer = setTimer(wio, 400, 30, source) 
end 
addEventHandler("onPlayerDamagae", root, oiu) 

 

 

Posted

try this

Timer = {} 
addEventHandler("onPlayerDamage", root,function () 
if isTimer(Timer[source]) then killTimer(Timer[source]) end 
Timer[source] = setTimer ( function (source) 
local Health = getElementHealth (source) 
if Health < 100 then 
if isElement(source) then  
setElementHealth (source,Health+5) 
end 
elseif isElement(source) then killTimer(Timer[source])  
outputChatBox ("Your Health Full",source,255,0,0) 
end 
end,3000,0,source) 
end) 

لا اله الا انت سبحانك اني كنت من الظالمين

TehLMGN.png?1

My Group : https://www.facebook.com/groups/992678147519191/

Posted
try this

Timer = {} 
addEventHandler("onPlayerDamage", root,function () 
if isTimer(Timer[source]) then killTimer(Timer[source]) end 
Timer[source] = setTimer ( function (source) 
local Health = getElementHealth (source) 
if Health < 100 then 
if isElement(source) then  
setElementHealth (source,Health+5) 
end 
elseif isElement(source) then killTimer(Timer[source])  
outputChatBox ("Your Health Full",source,255,0,0) 
end 
end,3000,0,source) 
end) 

thnx, thats just what i needed

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