• Lua help
    4 replies, posted
Firstly: I am Russian, and I do not know English very well. Therefore, I use Google translator. Sorry for my English Generally. My script is a HUD, and in theory it should always be updated. My script is updated only when I update the script manually via lua_openscript_cl. How to fix it? Pls. Here code: local ply = LocalPlayer() local rindct = { { x = 0, y = 63 }, { x = 0, y = 0 }, { x = 864*( ply:Health() / ply:GetMaxHealth() ), y = 0 }, { x = 763*( ply:Health() / ply:GetMaxHealth() ), y = 63 } } local rindct_shdw = { { x = 0, y = 63 }, { x = 0, y = 34 }, { x = 810*( ply:Health() / ply:GetMaxHealth() ), y = 34 }, { x = 764*( ply:Health() / ply:GetMaxHealth() ), y = 63 } } hook.Add( "HUDPaint", "PolygonTest", function() surface.SetDrawColor( 254, 0, 0, 255 ) draw.NoTexture() surface.DrawPoly( rindct ) surface.SetDrawColor( 29, 29, 29, (6375/100) ) draw.NoTexture() surface.DrawPoly( rindct_shdw ) end ) I'm still a beginner in coding, so don't beat me pls ,_,
Im not quite sure if this works in a singleplayer server but putting your script in lua/client/ may autoupdate once you save the file. Note: You may need to restart / rejoin AFTER you put the script in lua/client/ Correct me if im wrong.
lua / autorun / client is autorun at login. Is not it so? I meant that the work of my script looks like this: 1. Run (lua_openscript_cl) 2. Getting a Damage / Increasing Health 3. Updating does NOT occur (Health indicator did not budge) 4. Manual script update via  lua_openscript_cl 5.The indicator is updated (moves from a place) 6. A repetition from the 2nd point. But I need to restart the script via lua_openscript_cl was not necessary. And he restarted himself, without the console. Automatically.
It's because you declared them out of the function inside the hook. That means they will not be updated. Just move the variables inside the function and it will work. local ply = LocalPlayer() hook.Add( "HUDPaint", "HudTest", function() local rindct = { { x = 0, y = 63 }, { x = 0, y = 0 }, { x = 864*( ply:Health() / ply:GetMaxHealth() ), y = 0 }, { x = 763*( ply:Health() / ply:GetMaxHealth() ), y = 63 } } local rindct_shdw = { { x = 0, y = 63 }, { x = 0, y = 34 }, { x = 810*( ply:Health() / ply:GetMaxHealth() ), y = 34 }, { x = 764*( ply:Health() / ply:GetMaxHealth() ), y = 63 } } surface.SetDrawColor( 254, 0, 0, 255 ) draw.NoTexture() surface.DrawPoly( rindct ) surface.SetDrawColor( 29, 29, 29, (6375/100) ) draw.NoTexture() surface.DrawPoly( rindct_shdw ) end )
Thanks very much
Sorry, you need to Log In to post a reply to this thread.