• How to get player variable from server?
    9 replies, posted
Hello guys, I'm running DarkRP and I've got some scripts that introduce "hacks" into the game. For example, player buys a moneyprinter. On SERVER following code is being executed: [CODE] .... local rnd = math.Rand( 0, 1 ) if (rnd < self.Params.WantedChance) then owner.hacks = owner.hacks + 1 if !owner:isWanted( ) then owner:wanted( owner, "Owning Printer '".. self.Params.PrintName .. "'") end end .... [/CODE] I repeat, this code is server-side. Now, I'm coding a "most-wanted" 3D2D Panel and I need a way to get the 'hacks' from server without re-coding any shit. It's my CLIENT code for "most-wanted" panel: [CODE] function drawWantedList( ) ... for id, ply in pairs(player.GetAll()) do draw.SimpleText(id.." "..ply:Nick() , "CV25", 15, 80+(id*40) , Color(255,255,255,255), 0, 0) draw.SimpleText( ply.hacks , "CV25", 335, 80+(id*40) , Color(255,255,255,255), 0, 0) -- ply.hacks return nil here, any suggestions how to get this value without major code changes? end ... end [/CODE] Any suggestions? Thanks!
I don't quite understand what the "hack" is supposed to do... It seems that on the server it'll make a player wanted for owning a printing if the random number falls within a certain level? On the client you want that list of players to be displayed? Now for ply.hacks to exist on the client ( if set on the server ) it'd need to be networked. I'd recommend changing the mod slightly ( if owner:wanted automatically "wants" the player then some form of networking may already be included.... if not, I'd recommend networking the player to either all players, or players that need to know and maintaining the list ) Manage the list of players... On player connected, send the list if all get it, or if only certain players get it send it on Player Changed Team if new team is the right team... Update as usual ( remove when not wanted / PlayerDeath, etc... ). Client receiver would add / remove players from the list based on the managed list then simply for k, v in pairs( wantedPlayerList ) do ... end
[QUOTE=Acecool;46905343]I don't quite understand what the "hack" is supposed to do... It seems that on the server it'll make a player wanted for owning a printing if the random number falls within a certain level? On the client you want that list of players to be displayed? Now for ply.hacks to exist on the client ( if set on the server ) it'd need to be networked. I'd recommend changing the mod slightly ( if owner:wanted automatically "wants" the player then some form of networking may already be included.... if not, I'd recommend networking the player to either all players, or players that need to know and maintaining the list ) Manage the list of players... On player connected, send the list if all get it, or if only certain players get it send it on Player Changed Team if new team is the right team... Update as usual ( remove when not wanted / PlayerDeath, etc... ). Client receiver would add / remove players from the list based on the managed list then simply for k, v in pairs( wantedPlayerList ) do ... end[/QUOTE] "hacks" is the variable that stores num of player's law violations. Until now I did not need it on client side, but now I need it to be accessible on client.
That's a very much unfitting name. What about, hmm, "NumLawViolations" or "LawViolationsCount" or even "LawsBroken".. But "hacks".. ?!
[QUOTE=freakyy;46905462]That's a very much unfitting name. What about, hmm, "NumLawViolations" or "LawViolationsCount" or even "LawsBroken".. But "hacks".. ?![/QUOTE] I know, but it's a bit hard to change it's name because of number of places where it's used. I don't even remember some of them.
to answer the original question, you can send an empty net message from the client to server, and then in the receive function on the server, send the data back
[QUOTE=igodsewer;46905482]I know, but it's a bit hard to change it's name because of number of places where it's used. I don't even remember some of them.[/QUOTE] Go download grep.
[QUOTE=PortalGod;46905563]to answer the original question, you can send an empty net message from the client to server, and then in the receive function on the server, send the data back[/QUOTE] I had this idea, but I think that sending net messages on every tick (panel is being drawed on "PostDrawOpaqueRenderables" hook) would seriously fuck up my server. Am I wrong?
Re-read my response... Manage the list.. When you add a wanted player send that message either to all players or to those that get the updates. When a player joins the server sync the list with the player that joined. When a player is removed from the list ( either via PlayerDeath, etc ) then remove the player from the list and update the players. You don't need to send the data every tick, only send the change when it happens instead of constantly refreshing the list.
[QUOTE=Acecool;46907951]Re-read my response... Manage the list.. When you add a wanted player send that message either to all players or to those that get the updates. When a player joins the server sync the list with the player that joined. When a player is removed from the list ( either via PlayerDeath, etc ) then remove the player from the list and update the players. You don't need to send the data every tick, only send the change when it happens instead of constantly refreshing the list.[/QUOTE] I understand now. Thanks!
Sorry, you need to Log In to post a reply to this thread.