I make new custom HUD for my Dark rp server, but when anyone joined to server in next 5-10 second he getting some lua errors:
[quote]
[ERROR] addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:58: attempt to index field 'DarkRPVars' (a nil value)
1. v - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:58
2. unknown - lua/includes/modules/hook.lua:84
[/quote]
[code]
58: draw.SimpleText("Job: "..LocalPlayer().DarkRPVars.job,"TargetID", 35, ScrH() - 96, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
[/code]
I'm going to take a wild guess and assume this is running in a hook like HUDPaint without a check to see if LocalPlayer() is valid.
If the client hasn't fully initialized yet (prior to InitPostEntity IIRC), LocalPlayer() will be invalid and cause errors like this.
If this is the case, you should probably add a check in your hook like this:
[CODE]
hook.Add( "HUDPaint", "CustomRPHUD", function()
if ( !IsValid( LocalPlayer() ) ) then return; end
-- continue doing HUD stuff
end )[/CODE]
I may be entirely wrong in assuming though. If you can provide anymore information, it should help out.
[QUOTE=Mista Tea;44550727]I'm going to take a wild guess and assume this is running in a hook like HUDPaint without a check to see if LocalPlayer() is valid.
If the client hasn't fully initialized yet (prior to InitPostEntity IIRC), LocalPlayer() will be invalid and cause errors like this.
If this is the case, you should probably add a check in your hook like this:
[CODE]
hook.Add( "HUDPaint", "CustomRPHUD", function()
if ( !IsValid( LocalPlayer() ) ) then return; end
-- continue doing HUD stuff
end )[/CODE]
I may be entirely wrong in assuming though. If you can provide anymore information, it should help out.[/QUOTE]
LocalPlayer() is a valid entity client-side and HUDPaint updates every frame so, people shouldn't be getting spammed with errors repeatedly unless, he's doing something wrong.
What version of DarkRP are you running? If you're running one of the newest, you should be able to do "LocalPlayer():getDarkRPVar("money")"
[QUOTE=hsrodkey;44551862]LocalPlayer() is a valid entity client-side and HUDPaint updates every frame so, people shouldn't be getting spammed with errors repeatedly unless, he's doing something wrong.
What version of DarkRP are you running? If you're running one of the newest, you should be able to do "LocalPlayer():getDarkRPVar("money")"[/QUOTE]
The line that is causing an error is trying to get the job not money but otherwise you are right.
[QUOTE=hsrodkey;44551862]LocalPlayer() is a valid entity client-side and HUDPaint updates every frame so, people shouldn't be getting spammed with errors repeatedly unless, he's doing something wrong.[/QUOTE]
I'm aware that LocalPlayer() is a valid entity clientside.
However, I particularly remember having to add IsValid() checks when I was first learning how to write HUDs over a year ago because there is a definite time period in which the LocalPlayer() has not yet been initialized on the client, causing errors when trying to use it until InitPostEntity.
Looking back at my old code, I even see that I switched to adding the HUDPaint hook inside an InitPost Entity hook so that I could do away with checking if the LocalPlayer() was valid yet.
I am not able to replicate this problem anymore, so either something has changed, or am I going crazy.
Either way, sorry for being misleading. :suicide:
[B]EDIT:
[/B]Gonna assume that Agree is for the going crazy part :)
[QUOTE=AnonTakesOver;44552180]The line that is causing an error is trying to get the job not money but otherwise you are right.[/QUOTE]
You can do, "LocalPlayer():getDarkRPVar("job")" too. Try that and let me know if it, is fixed. I'm hoping that it's not a big issue.
[QUOTE=Mista Tea;44552252]I'm aware that LocalPlayer() is a valid entity clientside.
However, I particularly remember having to add IsValid() checks when I was first learning how to write HUDs over a year ago because there is a definite time period in which the LocalPlayer() has not yet been initialized on the client, causing errors when trying to use it until InitPostEntity.
Looking back at my old code, I even see that I switched to adding the HUDPaint hook inside an InitPost Entity hook so that I could do away with checking if the LocalPlayer() was valid yet.
I am not able to replicate this problem anymore, so either something has changed, or am I going crazy.
Either way, sorry for being misleading. :suicide:
[B]EDIT:
[/B]Gonna assume that Agree is for the going crazy part :)[/QUOTE]
I have also ran into the issue of LocalPlayer() not been valid yet, in HudPaint & Think hooks loading before this is initialized.
The issue the OP is having needs a check on IsValid(LocalPlayer()) and LocalPlayer().DarkRPVars.
Sorry, you need to Log In to post a reply to this thread.