I want program a game mode and I've got some problem. I want to send a variable from the server side to the cliend side. The problem is the game writes for "util.AddNetworkString(money)" --> a nil value. Please help my I can't get the what is the problem.
SERVER SIDE:
local ply = FindMetaTable("Player")
local money = 0
util.AddNetWorkString("money")
function GM:OnNPCKilled (npc_zombie, ply)
money = money + 100
sendMoneyClient()
end
function getMoneyCount()
print(money)
end
function sendMoneyClient()
net.Start("money")
net.WriteInt(money, 4)
net.Broadcast()
end
concommand.Add("money", getMoneyCount)
CLIENT SIDE [cl_init.lua]:
AddCSLuaFile("shared.lua")
--Más fájlok
AddCSLuaFile("rounds/cl_rounds.lua")
AddCSLuaFile("money/cl_money.lua")
AddCSLuaFile("shared.lua")
--AddCSLuaFile("characterselect/cl_characterselect.lua")
--cl_init.lua
local money = 0
net.Receive("money", function (len)
money = net.ReadInt(4)
end)
surface.CreateFont ("GoodFont", {
font = "Arial",
size = 50,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
hook.Add("HUDPaint", "Drawmyhud", function ()
draw.SimpleText(money.."$", "GoodFont", 1850, 10 , Color(255, 255, 51))
end)
It's [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/AddNetworkString]util.AddNetworkString[/url] and NOT util.Add[B]NetWork[/B]String
Basically make the W in Network lowercase, and you should be good to go
EDIT: Looking into your code a bit more, I'd recommend you use a Network variable instead of networking manually each time money is added.
You can do this using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNWInt]Entity:SetNWInt[/url] or [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNW2Int]Entity:SetNW2Int[/url]
For future reference and to prevent confusion, you should give a bit of backstory as to what you're attempting to do and use [code] tags around your code.
>Entity: SetNW2Int.
Is there such a thing?
[QUOTE=Pypsikan;52591304]>Entity: SetNW2Int.
Is there such a thing?[/QUOTE]
[url]https://facepunch.com/showthread.php?t=1497739&p=49339610&viewfull=1#post49339610[/url]
Sorry, you need to Log In to post a reply to this thread.