• net.Send doesnt works
    9 replies, posted
the net.Send at [CODE]if table.Count(tableticket) > 0 then FindsAPlayerToday(ply ,"superadmin", "admin", "helper") net.Start("adminalert") net.Send(player.GetByID(1)) print("sent data -adminalert- to ") end[/CODE] doesnt works my current code [SERVERSIDE]: [CODE] AddCSLuaFile ("shared.lua"); function FindsAPlayerToday( ply, target, target2, target3 ) v = {} print("players found"..v.." with "..n) if table.Count(v) == 0 then n = 1 end if table.Count(v)>0 then n = table.Count(v)+1 end for i = 1,table.Count(player.GetAll()) do if player.GetByID(i):GetUserGroup() == target1 or player.GetByID(i):GetUserGroup() == target2 or player.GetByID(i):GetUserGroup() == target3 then v[n] = player.GetByID(i) end end end if SERVER then howmuch = 1 tableticket = {} util.AddNetworkString("openticket") util.AddNetworkString("stringcall") util.AddNetworkString("adminalert") net.Receive("Stringcall" , function(len , ply) print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket)) if table.Count(tableticket) == 0 then tableticket[1] = net.ReadString() end if table.Count(tableticket)>0 then howmuch = howmuch+1 tableticket[howmuch] = net.ReadString() end end) -- if there is a alert sends it to all admins if table.Count(tableticket) > 0 then FindsAPlayerToday(ply ,"superadmin", "admin", "helper") net.Start("adminalert") net.Send(player.GetByID(1)) print("sent data -adminalert- to ") end hook.Add("PlayerSay", "chatticket", function(ply, text, public) if text == "/ticket" then net.Start("openticket") net.Send(ply) print("sent data -ticket- from client") end end) end[/CODE]
player.GetByID(1) will not always work if you are alone on the server. Use Entity(1) - That will select the first player.
no it didnt solve the problem
You are trying to send the net message before the server has fully started. Use InitPostEntity or Initialize hooks to send your message.
[code]if table.Count(tableticket) > 0 then for k,v in pairs(player.GetAll()) do if v:IsAdmin() or v:IsUserGroup("helper") then net.Start("adminalert") net.Send(v) print("sent data -adminalert- to " ..v:Nick()) end end end[/code] I'm not that good with Lua but this should work. Edit: Nevermind, I see now where the issue lies.
[QUOTE=Robotboy655;47670978]You are trying to send the net message before the server has fully started. Use InitPostEntity or Initialize hooks to send your message.[/QUOTE] i have tried it but still not working. And i cant understand why only "net.Start("adminalert")" doesnt works other net.Start() funchtions are working well
[QUOTE=anka067;47671047]i have tried it but still not working. And i cant understand why only "net.Start("adminalert")" doesnt works other net.Start() funchtions are working well[/QUOTE] As I told you, you are trying to sent the message to player.GetByID(1), which at the very first second of server's life, will return NOTHING or something like that. Use Entity(1) and send the net message from one of the two hooks I posted above.
i have tried all of them but still not working :/ my current code : [CODE] AddCSLuaFile ("shared.lua"); function FindsAPlayerToday( ply, target, target2, target3 ) v = {} print("players found"..v.." with "..n) if table.Count(v) == 0 then n = 1 end if table.Count(v)>0 then n = table.Count(v)+1 end for i = 1,table.Count(player.GetAll()) do if player.GetByID(i):GetUserGroup() == target1 or player.GetByID(i):GetUserGroup() == target2 or player.GetByID(i):GetUserGroup() == target3 then v[n] = player.GetByID(i) end end end if SERVER then howmuch = 1 tableticket = {} util.AddNetworkString("openticket") util.AddNetworkString("stringcall") util.AddNetworkString("adminalert") net.Receive("Stringcall" , function(len , ply) print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket)) if table.Count(tableticket) == 0 then tableticket[1] = net.ReadString() end if table.Count(tableticket)>0 then howmuch = howmuch+1 tableticket[howmuch] = net.ReadString() end end) -- if there is a alert sends it to all admins hook.Add("Initialize", "servercheck", function() if table.Count(tableticket) > 0 then FindsAPlayerToday(ply ,"superadmin", "admin", "helper") net.Start("adminalert") net.Send(Entity(1)) print("sent data -adminalert- to ") end end) hook.Add("PlayerSay", "chatticket", function(ply, text, public) if text == "/ticket" then net.Start("openticket") net.Send(ply) print("sent data -ticket- to client "..ply:Nick()) end end) hook.Add("Initialize", "servercheck", function() end [/CODE]
You should send a message only when you know whom to. I think you wanted to make something like this: [CODE]net.Receive("Stringcall" , function(len , ply) print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket)) table.insert(tableticket, net.ReadString()) for k, v in pairs(player.GetAll()) do if v:IsAdmin() or v:IsUserGroup("helper") then net.Start("adminalert") net.Send(v) print("sent data -adminalert- to ", v) end end end)[/CODE]
[QUOTE=GIG;47671246]You should send a message only when you know whom to. I think you wanted to make something like this: [CODE]net.Receive("Stringcall" , function(len , ply) print("got string data from client. count is : "..table.Count(tableticket)..table.ToString(tableticket)) table.insert(tableticket, net.ReadString()) for k, v in pairs(player.GetAll()) do if v:IsAdmin() or v:IsUserGroup("helper") then net.Start("adminalert") net.Send(v) print("sent data -adminalert- to ", v) end end end)[/CODE][/QUOTE] It worked! Thanks for helping .
Sorry, you need to Log In to post a reply to this thread.