• Entity specific umsg and hook
    7 replies, posted
So I wont bore you with great details, but I need a umsg on the init.lua of my entity to send a string to the cl_init.lua, which is fairly simple, until it is more than likely that two identical entities will be spawned. [B]What I have:[/B] Server side: [CODE]function ENT:UpdatePhase(np) phase = np umsg.Start( "updatePhase", player.GetAll() ) umsg.String( phase ) umsg.End() end[/CODE] (I'm going to change to broadcast eventually) Client side: [CODE] usermessage.Hook( "updatePhase", doThings )[/CODE] [B]What I'm looking for:[/B] [CODE]function ENT:UpdatePhase(np) phase = np umsg.Start( "updatePhase" .. uniqueCode(), player.GetAll() ) umsg.String( phase ) umsg.End() end[/CODE] Client side: [CODE] usermessage.Hook( "updatePhase".. uniqueCode(), doThings )[/CODE] Thanks for any help! EDIT: This is the problem, only one of these is displaying the correct information, then other is displaying it's "twin's": [url]https://dl.dropboxusercontent.com/u/7703917/2014-02-28_00003.jpg[/url] The server knows better, however the client doesn't.
You could send the entity in the usermessage and use the same identifier for the messages. [url]http://wiki.garrysmod.com/page/umsg/Entity[/url]
[CROSSOUT]Scheiße, why didn't I think of that? You're the best! Thanks[/CROSSOUT] edit: Hmm, that can't work because the client wouldn't know which entity is telling the client about itself
By the way I'd look into net messages, if I recall correctly they're more efficient than usermessages. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
[QUOTE=Jeezy;44086104]By the way I'd look into net messages, if I recall correctly they're more efficient than usermessages. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url][/QUOTE] Net messages allow more data; 64kb opposed to 255 bytes with umsg. Additionally, net-message are sent instantly ( same frame ) whereas umsgs are sent the next frame.
Ohhh, Acecool again :P (you replied to another thread of mine not long ago) So you guys recommend that I do it through the net library? Is there no id or something that both the client and server know about an entity? And how would I be able to go about doing it through the net library? It look like nearly the same thing
It pretty much is, although net library doesn't take RecipientFilters; it uses a table of players if you choose to send data to a list of players from the server. So it can be one player by their self, or a list of many. You can use net.WriteEntity and net.ReadEntity although I have see users have issues with this method where they send the data to the client right after creating the entity and it arrives as a NULL entity; to combat this you write the EntIndex( ) of the newly created entity in a message and then use Entity( net.ReadX( ) ) where X is the number type you use. Even though the back-end uses this same method, for some odd reason it does resolve the issue when doing it manually. A basic net library script bearing in mind that when you create a network string, it can be used on both the client and server as a receiver: Server [lua]util.AddNetworkString( "MyNetMessage" ); net.Receive( "MyNetMessage", function( length, Player ) local _inString = net.ReadString( ) net.Start( "MyNetMessage" ); net.WriteString( _inString .. "1, 2, 3..." ); net.Broadcast( ); // Sends to all clients which is identical to :: net.Send( player.GetAll( ) ) -- net.Send( Entity( 1 ) ) // Will send to the first player -- net.Send( { Entity( 1 ), Entity( 2 ) } ) // Will send to the first and second players end );[/lua] Client [lua] net.Receive( "MyNetMessage", function( length ) print( net.ReadString( ) ); // We sent a message to the server, the server rebounded the message back to the client with additional data -- output should be Testing1, 2, 3... end ); net.Start( "MyNetMessage" ); net.WriteString( "Testing" ); net.SendToServer( ); [/lua]
[QUOTE=Acecool;44086142]Net messages allow more data; 64kb opposed to 255 bytes with umsg. Additionally, net-message are sent instantly ( same frame ) whereas umsgs are sent the next frame.[/QUOTE] Sorry acecool, but i can't send entities on "The same frame" [lua] timer.Simple(0.1,function() //With less than 0.05 sent is nil net.Start("BeamCreated") net.WriteTable({a,b}) net.SendPVS() end) [/lua] PS: please guys...If i try to edit a lua code it fucking breaks, itremove tags and spaces...Please... (I will test your solution about entindex)
Sorry, you need to Log In to post a reply to this thread.