Jump to content

Hunger Sistem Error


mancebomozo

Recommended Posts

Posted

It's about making a system by which users are hungry and will lower the life every hour, forcing them to eat.

  
function texto(texto)  
    outputChatBox ( "Aviso: " .. texto ) 
end 
  
setTimer(texto,3600000,0,"Tienes hambre, come un poco") 
  
  
function startResource() 
    local nivel = getElementData (source, "nivel") 
    if nivel == 1 then 
        setElementHealth  ( source, getElementHealth  ( source ) - 70 ) 
    end 
    setTimer(startResource, 3600000, 0, true) 
     
     
end 
addEventHandler("onResourceStart", getResourceRootElement(), startResource) 

Help please someone tell me the error

  • Moderators
Posted

Check your bugs:(admin)

/debugscript 3

I am not sure, but should this not be a:1

setTimer(startResource, 10000,1, true) --14 

Because, he is already triggering him zelf again.

Don't you need to use: localPlayer ? localPlayer = getLocalPlayer ( )

  
Player = getLocalPlayer ( ) 
  
      
    function texto(texto) 
        outputChatBox ( "Aviso: " .. texto ) 
    end 
      
    setTimer(texto,3600000,0,"Tienes hambre, come un poco") 
      
      
    function startResource() 
        local nivel = getElementData (player, "nivel") 
        if nivel == 1 then 
            setElementHealth  ( player, getElementHealth  ( player ) - 70 ) 
        end 
        setTimer(startResource, 3600000, 1, true) 
    end 
    addEventHandler("onResourceStart", getResourceRootElement(), startResource) 
  

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

That means you don't have set the element data yet, you have to set the element data first or to zero, bevore this script can be executed.

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

You did not said it was serverside,

But as I said, the element data must first be exist.

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

you can try this:

  
  
function texto(texto) 
    outputChatBox ( "Aviso: " .. texto ) 
end 
  
setTimer(texto,3600000,0,"Tienes hambre, come un poco") 
  
  
function startResource() 
    for k,player in ipairs(getAlivePlayers())  
        local nivel = getElementData (player, "nivel") 
            if nivel == 1 then 
                setElementHealth  ( player, getElementHealth  ( player ) - 70 ) 
            end 
        setTimer(startResource, 3600000, 1, true) 
    end 
end 
  
addEventHandler("onResourceStart", getResourceRootElement(), startResource) 
  

I don't think this is going to work because....

I am to tired to rebuild it :(

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

 

  Useful functions  3x 

  Tutorials  4x 

 

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