• How to execute a function clientside and get the result serverside ?
    3 replies, posted
I might have asked my question the wrong way but anyway i will explain further below, I'm making a swep to get the ScrW() and ScrH() of the aimed player and save it into a file (yes that's a bit weird) So far my swep is really simple and i'm able to get the aimed player by using a traceline but i have no idea how to do it, however i tried this : function SWEP:PrimaryAttack()   local tr = util.TraceLine( util.GetPlayerTrace( self.Owner ) )   print(tr.Entity)   if SERVER and IsValid(tr.Entity)  and tr.Entity:IsPlayer() then     tr.Entity:SendLua("LocalPlayer():SetVar(\"test\", ScrW())")     print(tr.Entity:GetTable()['test'])   end end But it returns nil serverside. I might no have understand how this kind of things works... sorry in advance Thanks in advance for any answer.
Use a netmessage, like this <Swep primary fire> net.Start("Fetch screen width") net.Send(self.Owner) <Swep primary fire> function SWEP:ShootWidth(wide) MsgN("our width is "..wide) end if CLIENT then net.Receive("Fetch screen width", function() net.Star("Fetch screen width") net.WriteInt(ScrW(), 64) net.SendToServer() end) else net.Receive("Fetch screen width", function(l, ply) local width = net.ReadInt(64) ply:GetActiveWeapon():ShootWidth(width) end) end
If i want to get the player screenwidth i send the player i'm aiming at entity so ? Thanks a lot for this answer it will help me a lot
util.AddNetworkString("SendMeScreen") util.AddNetworkString("SendMyScreenToThisGuy") util.AddNetworkString("HeresYourScreenDude") function SWEP:PrimaryAttack()      if(SERVER) then           local ent = self.Owner:GetEyeTrace().Entity           if(ent:IsPlayer()) then                                net.Start("SendMeScreen")                     net.WriteEntity(self.Owner)                net.Send(ent)           end      end end net.Receive("SendMyScreenToThisGuy", function()      local info = net.ReadTable()      local receiver = net.ReadEntity()      net.Start("HeresYourScreenDude")           net.WriteTable(info)      net.Send(receiver) end) if(SERVER) then return end net.Receive("SendMeScreen", function()      local messanger = net.ReadEntity()       if(messanger:IsPlayer()) then           net.Start("SendMyScreenToThisGuy")                net.WriteTable( {scrW(), scrH()} )                net.WriteEntity(messanger)           net.SendToServer()      end       end) net.Receive("HeresYourScreenDude", function()      local tab = net.ReadTable()      local width = tab[1]      local height = tab[2]      print("Oh shit, this guy has a width of "..tostring(width).." and a height of "..tostring(height)) end)
Sorry, you need to Log In to post a reply to this thread.