Hey guys I'm having a problem with 'GetNWInt',
basically If I 'LocalPlayer:GetNWInt("Example")' on client it returns 0, aka It doesn't update
CLIENT FILE:
[CODE]
local ply = LocalPlayer()
print(ply:GetNWInt("Example")) -- This will print '0' every time
if ply:GetNWInt("Example") != 0 then
--stuff-- // This is not running ever
end
[/CODE]
SERVER FILE:
[CODE]
hook.Add("PlayerDeath", "Example_hook", function(vic, infl, ply)
ply:SetNWInt("Example", ply:GetNWInt("Example")+1)
end)
[/CODE]
Are you sure you're running the client code after the server has run?
The third argument of the PlayerDeath hook is the attacker. So you are setting the NWInt on the attacker, you should instead set it on the victim (the person who died) That is probably what you are trying to do, right?
[QUOTE=code_gs;52480616]Are you sure you're running the client code after the server has run?[/QUOTE]
I'm 99% sure.
I'll just draw the number on my HUD just to see if it's working at some point.
[QUOTE=Gmod4phun;52480886]The third argument of the PlayerDeath hook is the attacker. So you are setting the NWInt on the attacker, you should instead set it on the victim (the person who died) That is probably what you are trying to do, right?[/QUOTE]
Nop, it's not what I'm trying to do, I want the Attacker's NWInt to increment.
Edit: code_gs was right. Basically I'm incrementing with a "PlayerDeath" hook and if I do a double kill it won't show a different number on client because it first reads both playerdeaths on servers.
Is there any other solutions for this but timers?
Thanks in advance!
Your code looks fine serverside, just wait clientside before using
[QUOTE=code_gs;52482849]Your code looks fine serverside, just wait clientside before using[/QUOTE]
The only way to do it is with timers right?
[QUOTE=Pwned231;52483831]The only way to do it is with timers right?[/QUOTE]
You don't have to, depends on when you want to use it
[QUOTE=code_gs;52484161]You don't have to, depends on when you want to use it[/QUOTE]
Honestly I would like to use it asap.
The problem is if I make a timer some computers are slower than others, I'm pretty sure 0.1s would be enough tho.
EDIT: What I said it's kinda dumb.
Any suggestions tho?
[QUOTE=Pwned231;52485343]Honestly I would like to use it asap.
The problem is if I make a timer some computers are slower than others, I'm pretty sure 0.1s would be enough tho.
EDIT: What I said it's kinda dumb.
Any suggestions tho?[/QUOTE]
I meant when on the client are you using it, in drawing a HUD?
[QUOTE=code_gs;52486458]I meant when on the client are you using it, in drawing a HUD?[/QUOTE]
Ah, no I'm using it to show the Value in a notification
[QUOTE=Pwned231;52486547]Ah, no I'm using it to show the Value in a notification[/QUOTE]
If you use NW2Vars instead, you can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNWVarProxy]Entity:SetNWVarProxy[/url] to see when it's updated on the client.
[QUOTE=code_gs;52486593]If you use NW2Vars instead, you can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNWVarProxy]Entity:SetNWVarProxy[/url] to see when it's updated on the client.[/QUOTE]
Thanks for the info!
Also is it better to use NW2Vars over NWVars in all cases?
Thanks in Advance :)
Yes, the original plan was for NW2Vars to replace NWVars, but it has seemingly been abandoned.
I made a search on NW2Vars, they would be great, do you know why didn't they replace it the NWVars for NW2Vars yet?
[QUOTE=bigdogmat;52467873]They aren't documented because they're "meant to replace the normal NWVar functions at some point". [B]They also have some bugs currently such as [URL="https://github.com/Facepunch/garrysmod-issues/issues/3137"]this[/URL] and [URL="https://github.com/Facepunch/garrysmod-issues/issues/2992"]this[/URL][/B].
They use the same system internally as [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/NetworkVar]Entity:NetworkVar[/url], so they're prediction friendly unlike normal NWVars. They're also more versatile compared to [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/NetworkVar]Entity:NetworkVar[/url] in a few ways such as not having to manually create slots. [B]Only difference you may notice is that if you set a normal NWVar on a player outside of PVS, it'll update immediately, where as with NW2Var it'll take a few seconds.[/B][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.