I'm trying to call net.Start(Kills) to the server, so it then can save the kills inside a TXT on the client. The only problem is I'm getting this error. I'm calling util.AddNetworkString("Kills") in a function that starts everytime a player dies, but there is this error trying to prevent me from sending a variable to the server that then saves that variable in a TXT on the client.
Show your code.
I already have a function that counts the kills of the player, but it's not working.
[editline]21st August 2013[/editline]
Clientside:
[code]
function KillSound(um)
local Killing = um:ReadShort()
if Killing == 5 then
draw.RoundedBox( 0, ScrW()/2.5, ScrH()/24, ScrW()/2, ScrH()/1.5, Color(60, 60, 60, 255) )
surface.PlaySound("headhunter.wav")
end
if Killing == 10 then
surface.PlaySound("rampage.wav")
end
if Killing == 15 then surface.PlaySound("godlike.wav") end
if CLIENT then
[B] net.Start(Killing)
net.SendToServer()[/B]
end
end
usermessage.Hook("refreshkill",KillSound)
[/code]
Serverside:
[code]
function GM:PlayerDeath(vic, inf, atc)
local aw = nil
if atc:IsPlayer() and atc:GetActiveWeapon() then
aw = atc:GetActiveWeapon()
end
if atc:IsPlayer() and (atc!=vic)then
vic.Killing = 0
atc.Killing = (atc.Killing or 0) + 1
umsg.Start("refreshkill",atc)
umsg.Short(atc.Killing)
umsg.End()
local atc_stid = atc:UniqueID()
local vic_stid = vic:UniqueID()
else
end
[B] net.Receive("killz", function(length, client)
print("It works!")
end)
file.Write("dontlookatme.txt", killz)[/B]
end
[/code]
[QUOTE=sackcreator54;41912780]I'm trying to call net.Start(Kills) to the server, so it then can save the kills inside a TXT on the client. The only problem is I'm getting this error. I'm calling util.AddNetworkString("Kills") in a function that starts everytime a player dies, but there is this error trying to prevent me from sending a variable to the server that then saves that variable in a TXT on the client.[/QUOTE]
No, call util.AddNetworkString ONLY ONCE PER STRING. Add it to the top of the file, and make sure you're adding that on the server, not the client.
-snip-
Those usermessages are for something else, a team selection, it has nothing to do with net messages.
[editline]21st August 2013[/editline]
[QUOTE=Big Bang;41912809]No, call util.AddNetworkString ONLY ONCE PER STRING. Add it to the top of the file, and make sure you're adding that on the server, not the client.[/QUOTE]
If I add it to the top of my serverside file, will it execute outside a function?
Why the hell you post code unrelated to your question?
Here's an example of sorts for you.
Clientside:
[code]
net.Receive( "refreshkill", function ( len )
local Killing = tonumber( net.ReadString() )
if Killing == 5 then
surface.PlaySound("headhunter.wav")
end
if Killing == 10 then
surface.PlaySound("rampage.wav")
end
if Killing == 15 then surface.PlaySound("godlike.wav") end
-- save file here or something
end )
[/code]
Serverside:
[code]
util.AddNetworkString("refreshkill")
function GM:PlayerDeath(vic, inf, atc)
if atc:IsPlayer() and (atc != vic)then
vic.Killing = 0
atc.Killing = (atc.Killing or 0) + 1
net.Start("refreshkill")
net.WriteString(atc.Killing)
net.Send( ply )
end
end
[/code]
[QUOTE=sackcreator54;41912835]will it execute outside a function?[/QUOTE]
Yes, code outside of functions executes when the file loads.
[QUOTE=Robotboy655;41912854]Why the hell you post code unrelated to your question?
Here's an example of sorts for you.
Clientside:
[code]
net.Receive( "refreshkill", function ( len )
local Killing = tonumber( net.ReadString() )
if Killing == 5 then
surface.PlaySound("headhunter.wav")
end
if Killing == 10 then
surface.PlaySound("rampage.wav")
end
if Killing == 15 then surface.PlaySound("godlike.wav") end
end )
[/code]
Serverside:
[code]
util.AddNetworkString("refreshkill")
function GM:PlayerDeath(vic, inf, atc)
if atc:IsPlayer() and (atc != vic)then
vic.Killing = 0
atc.Killing = (atc.Killing or 0) + 1
net.Start("refreshkill")
net.WriteString(atc.Killing)
net.Send( ply )
else
end
end
[/code][/QUOTE]
I want to send a variable FROM the client TO the server. This looks like it is sending from the server and the client is retrieving it.
[editline]21st August 2013[/editline]
I tried saving the file via client, but it doesn't work.
[QUOTE=sackcreator54;41912860]I want to send a variable FROM the client TO the server. This looks like it is sending from the server and the client is retrieving it.[/QUOTE]
Use the same principle but instead of net.Send use net.SendToServer
Where the util.AddNetworkString wouldn't matter since it is a serverside function anyways.
Getting same error in console.
Serverside
[code]
net.Receive( "refreshkill", function ( len )
local netKills = tonumber( net.ReadString() )
file.Write("dontlookatme.txt", netKills)
end)
function GM:PlayerDeath(vic, inf, atc)
local aw = nil
if atc:IsPlayer() and atc:GetActiveWeapon() then
aw = atc:GetActiveWeapon()
end
if atc:IsPlayer() and (atc!=vic)then
vic.Killing = 0
atc.Killing = (atc.Killing or 0) + 1
umsg.Start("refreshkill",atc)
umsg.Short(atc.Killing)
umsg.End()
local atc_stid = atc:UniqueID()
local vic_stid = vic:UniqueID()
else
end
end
[/code]
Clientside
[code]
function KillSound(um)
local Killing = um:ReadShort()
if Killing == 5 then
draw.RoundedBox( 0, ScrW()/2.5, ScrH()/24, ScrW()/2, ScrH()/1.5, Color(60, 60, 60, 255) )
surface.PlaySound("headhunter.wav")
end
if Killing == 10 then
surface.PlaySound("rampage.wav")
end
if Killing == 15 then surface.PlaySound("godlike.wav") end
if CLIENT then
net.Start("refreshkill")
net.WriteString(Killing)
net.SendToServer( ply )
end
end
[/code]
You didn't add the util.AddNetworkString in the server code anywhere... like everyone told you to do.
util.AddNetworkString("refreshkill") needs to be somewhere outside of your functions in the body of the server Lua file so it is executed on runtime. net.SendToServer also takes no arguments. You're also doing net.WriteString with a number. Try net.WriteInt(Killing, 8) and net.ReadInt(8), also there's NO reason to be sending the server the information you just sent the client, this is redundant. Usermessages, while not necessarily deprecated yet, are superseded by the Net library and there is no reason to mix the two up in your code.
What I mean is that you should be doing this instead:
Serverside:
[code]
function GM:PlayerDeath(vic, inf, atc)
if atc:IsPlayer() and (atc!=vic)then
vic.Killing = 0
atc.Killing = (atc.Killing or 0) + 1
net.Start("refreshkill", atc)
net.WriteInt(atc.Killing, 8)
net.Send(atc)
file.Write("dontlookatme.txt", atc.Killing)
end
end
[/code]
Clientside:
[code]
net.Receive("refreshkill", function()
local Killing = net.ReadInt(8)
if Killing == 5 then
surface.PlaySound("headhunter.wav")
elseif Killing == 10 then
surface.PlaySound("rampage.wav")
elseif Killing == 15 then
surface.PlaySound("godlike.wav")
end
end[/code]
Sorry, you need to Log In to post a reply to this thread.