Jump to content

[solved]scripts not working


Recommended Posts

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 

Link to comment
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
Link to comment
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) 

Link to comment

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.

Link to comment
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?

Link to comment
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
Link to comment
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

Link to comment
  
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 
  

Link to comment
  
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
Link to comment

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

Link to comment
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) 

Link to comment

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) 
Link to comment
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

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