I got a client side Multi Choice Which contains the players which are online,and when a user chooses someone it’ll send him a request automatically.
How can I send the request to someone, and open the window for him?
I’m using net to send it to the server, but from the server, im not sure how to send it, to the other client.
Thanks for the help.
I may be wrong as I’ve just started using Net, so anyone feel free to correct me.
So once you’ve sent the message from the client to the server, that message would have to contain the name of the person who you want to send the message to which you could get from whoever they selected.
So then in net.receive on the server side, you would pass the playername they chose to a function eg. sendToPlayer( playerName )
local function sendToPlayer( playerName ) for k, v in pairs(player.GetAll()) do if v:Nick() == playerName then net.Start("playerMessage") NET STUFF net.Send(v) end end end
On receive on the client-side end you’d need to make create the HUD with whatever you pass to it through the net.Send
Anyone correct me if there’s a better way to do this and this is just of the top of my head so I don’t even know if it works.
Yeah thought about it, could be, But since it’ll need to go over all of the players all the time, it wont be very efficient i was wondering if there is any other way.
Get the client to net.WriteEntity() their target to the server, then make the server send a message to the net.ReadEntity().
Ok since im using a “DMultiChoice”, This is my code:
for k,v in pairs(ply:GetAll()) do if k:SteamID != ply:SteamID List:AddChoice(k:Name()) end List:OnSelect(index,value,data) TradingSending:Close() ply:PrintMessage( HUD_PRINTTALK, "You have send a Trading request to: " ..value) ply:PrintMessage( HUD_PRINTTALK, "Please wait until " ..value.. "approves the request.") net.Start("sendsecondside") net.WriteString(ply:Nick()) net.WriteString(value) net.SendToServer()
Then how would i send the entity instead of the name?
I would send to the server the player’s Unique ID instead of the player’s nick and then on server I would get the Player’s object with player.GetByUniqueID, that would consume much less processing power, than looping though all the players objects.
Client: Sends to server player’s UniqueID
Server: Receives player’s UniqueID, get player’s object with it and send a Net message to this specific player with the data that would be used on the window
Client: Receives the message with data that would be used on the the window
Or you know, like a normal person, just use the player entity that is sent to the server automatically.