• Player meta func everywhere ?
    4 replies, posted
On sv local meta = FindMetaTable("Player") function meta:Example() self:HelloWorld(self:GetName()) end function PrintName(name) return name end How to run Example func on client side ? because it work only on server side. And function "PrintName" work only on server side.
If you want a meta function that can be both run on client and server, it needs to be in the shared file. Right now it's only in the server file (sv), so it can only be ran server side.
Ok, can u write example for how me get data from server using net and player meta ? For example i writed code, but i don't get "Hello" string, only nil. -- SH local meta = FindMetaTable( "Player" ) function meta:GetSomeVariable() local data = "" net.Start("GetSomeVar") print("Sended!") net.WriteEntity(self) net.SendToServer() net.Receive("SendData",function() print("Received!") data = net.ReadString() end) return data end -- SV local str = "Hello" net.Receive("GetSomeVar",function() local ply = net.ReadEntity() net.Start("SendData") net.WriteString(str) net.Send(ply) end) -- CL print(LocalPlayer():GetSomeVariable()) I need get data from server using ply meta. Maybe someone know a better method than mine ?
--SV util.AddNetworkString("Request.Var") --SH local meta = FindMetaTable("Player") function meta:GetVar()     //All net operations are async aswell, due to physics constraints     //You are supposed to initialize the var before     return self._cached end net.Receive("Request.Var", function(l, ply)     if SERVER then         ply._cached = 2 + 2         //We can use the same net message as dual link between realms         net.Start("Request.Var")         net.WriteInt(ply._cached, 2)         net.Send(ply)     else         //Now meta:GetVar() returns 4 and not nil         ply._cached = net.ReadInt(2)         //If we have setup a callback, we run it         if (ply._callFunc) then             ply._callFunc(ply._cached)             //We mark the job as done             ply._callFunc = nil         end     end end) --CL function meta:RequestVar(callBack)     net.Start("Request.Var")     net.SendToServer()     if (callBack) then         //We save the callback, this is just an example scenario         self._callFunc = callBack     end end local ply = LocalPlayer() ply:RequestVar() --Requests the var MsgN(ply:GetVar()) --Will print nil //Async example ply:RequestVar(function(var)     //Once we get the variable sync, this function will be ran     MsgN(var) --Will print 4     MsgN(ply:GetVar()) --Will print 4 end) 
It depends on what you're actually trying to accomplish, the meta tables seems like a dumb approach to do that. Also net.Receive on the server has the ply who sent the message as the second argument, your code is not safe.
Sorry, you need to Log In to post a reply to this thread.