I just ran into a problem while coding.
This code:
[lua]local ent = LocalPlayer():GetEyeTrace().Entity
if ent then
local health = ent:GetNWInt("Health")
if health > 0 then
draw.SimpleText(tostring(health), "HUDSmall", ScrW()/2, ScrH()/2-50, Color(255,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
end[/lua]
Breaks all of these functions:
[lua]GetGlobalInt("round")[/lua]
For about 5 seconds, then it goes back to normal.
I went around it by adding a loading screen, but I don't really want a loading screen. Is there anyway to get around this?
Why not using round as a nwint / nwstring too?
Because
[lua]SETTINGS.round[1] = {} -- Creation of a new round will make you have to change the [1] portion to the next number.
SETTINGS.round[1].name = "Build a Boat. %t" -- Use %t anywhere you want to show the timeleft.
SETTINGS.round[1].length = 99999999 -- Time in seconds of how long the round lasts. 120 is equivalent to 2 minutes.
SETTINGS.round[1].loadout = {"weapon_physgun","weapon_fl_tool","weapon_fl_prophealer"} -- List of weapons you will get when you spawn.
SETTINGS.round[1].allowspawnmenu = true -- Allow the player to open up the spawn menu.
SETTINGS.round[1].allowspawnprop = true -- Allow the player to spawn objects.
SETTINGS.round[1].allowbuyweapon = true -- Allow the player to buy weapons.
SETTINGS.round[1].allowundo = true -- Allow the player to spam the undo button to remove their boat.
SETTINGS.round[1].allowrespawn = true -- Alow the player to respawn.
SETTINGS.round[1].TimeToRespawn = 4 -- How long it takes for the player to respawn.
SETTINGS.round[1].ForceRespawn = true -- Force the player to respawn once the round has started.[/lua]
I have no idea how to explain that in words. Please expand my vocabulary.
Well, I spotted 1 wrong thing:
GetGlobalInt("round")
round is a variable stored under a table
2nd:
I suggest you use a way as usermessage / datastreams / NWInts.
I don't know the whole code, not even if that is a gamemode or an addon, so there isn't much else I can say.
Here's how I would access the round.
SETTINGS.round[GetGlobalInt("round") ]
Which is not "round is a variable stored under a table".
Sure, there is a round stored under a table but these are two different things.
GetGlobalInt("round") breaks from the first code I mentioned, assuming that it doesn't break without the first code.
[QUOTE=BoingBoing;19874846]GetGlobalInt("round") breaks from the first code I mentioned, assuming that it doesn't break without the first code.[/QUOTE]...Then try removing the first code and see what happens?
I told you, it works without the first code.
All I need right now is to have it both working without using a loading screen.
Here is the whole function:
[lua]// _Muffin's fonts.
surface.CreateFont( "coolvetica", 30, 500, true, false, "HUDSmall" )
surface.CreateFont( "coolvetica", 50, 500, true, false, "HUDMedium" )
surface.CreateFont( "coolvetica", 60, 500, true, false, "HUDLarge" )
surface.CreateFont( "coolvetica", 80, 500, true, false, "HUDHuge" )
local pasthealth = 100
local healthflash = 0
function GM:HUDPaint()
if SETTINGS.round[GetGlobalInt("round")] then
surface.SetDrawColor( 0, 0, 0, 170) --Red
surface.DrawRect(0 , 0, ScrW(), 70 )
draw.SimpleText(string.Replace(SETTINGS.round[GetGlobalInt("round")].name,"%t",string.ToMinutesSeconds(GetGlobalInt("time"))), "HUDLarge", ScrW() / 2, 40, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
if GetRound().drawhealth then
if pasthealth ~= LocalPlayer():Health() then
healthflash = 200
pasthealth = LocalPlayer():Health()
end
if healthflash > 0 then
healthflash = math.Clamp(healthflash - 3,0,healthflash)
end
draw.WordBox( 8, 5, ScrH()-100, SETTINGS.HealthName..": "..LocalPlayer():Health(), "HUDSmall", Color(255,healthflash,healthflash,255), Color(255,255,255,170) )
end
draw.WordBox( 8, 5, ScrH()-50, SETTINGS.MoneyName..": "..LocalPlayer():GetNWInt("Cash"), "HUDSmall", Color(0,255,0,255), Color(255,255,255,170) )
local ent = LocalPlayer():GetEyeTrace().Entity
if ent then
local health = ent:GetNWInt("Health")
if health > 0 then
draw.SimpleText(tostring(health), "HUDSmall", ScrW()/2, ScrH()/2-50, Color(255,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
end
else
draw.WordBox( 8, ScrW()/2-170, ScrH()/2-50, "LOADING", "HUDHuge", Color(255,55,55,255), Color(255,255,255,170) )
end
end[/lua]
In case you want to look at it even more.
[lua]string.ToMinutesSeconds(CurTime()-GetGlobalInt("start_time"))[/lua]
I know it doesn't solve your problem, but you should do time like this to prevent useless networking.
That kind of makes it unsynced.
CurTime() is synced to a degree. So your point is pretty invalid.
Alright, new thing learned.
This still doesn't solve my problem.
You should probably use the default parameter when using networked values.
Also, define 'breaks'.
Do they not update? Do they return nil? Do they return seemingly unpredictable values?
Please give us some debug output.
Returns 0.
Sorry, you need to Log In to post a reply to this thread.