• Displaying another players arrest timer
    8 replies, posted
I am currently wondering if there is a way to display another players time remaining in jail above their heads, of course I have tried figuring it out myself this is what I've got: surface.SetFont( "MInfoFont" ) local StartArrested = CurTime() local ArrestedUntil = msg:ReadFloat() time = string.FormattedTime( math.ceil( ( ArrestedUntil - ( CurTime() - StartArrested ) ) * 1 / game.GetTimeScale() ), "%02i:%02i") local width, height = surface.GetTextSize( DankConfig.ArrestedTopMSG ) local yPos = 0 cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.2 ) draw.RoundedBox( 0, - ( width / 2 ), yPos, width + 10, 2, DankConfig.FirstColor ) draw.SimpleText( DankConfig.ArrestedTopMSG, "MInfoFont", 0, yPos - 20, DankConfig.SecondColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) draw.SimpleText( "Time Remaining: " .. time, "MInfoFont", 0, yPos + 20, DankConfig.WantedColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) cam.End3D2D() That simply throws me with an error: [ERROR] addons/darkrpmodification/lua/darkrp_modules/sw_hud/cl_hud.lua:1343: attempt to index global 'msg' (a nil value)   1. fn - addons/darkrpmodification/lua/darkrp_modules/sw_hud/cl_hud.lua:1343    2. unknown - addons/ulib/lua/ulib/shared/hook.lua:109 Now I know it's throwing that error due to trying to read a nil value but I am wondering instead of using the usermessage.hook("GotArrested" function(msg) end) to call the time of a players arrest is there any other way of doing that I could possibly use to display not the local players time remaining but another players.
My guess is that "time" is a global variable and you just modified it which returned an unrelated error. I suggest you change the time to something like: local theTime = XZY
local ArrestedUntil = msg:ReadFloat() means you are trying to read something networked. You don't do this in a "Paint" hook. Can you post all the code?
That is all the code the rest is simply checking if certain requirements are met before being drawn. What I am trying to get to do is simply call the same as: usermessage.Hook("GotArrested", function(msg) StartArrested = CurTime() ArrestedUntil = msg:ReadFloat() surface.SetFont( "MInfoFont" ) local width, height = surface.GetTextSize( "You have been arrested/detained!" ) Arrested = function() time = string.FormattedTime( math.ceil( ( ArrestedUntil - ( CurTime() - StartArrested ) ) * 1 / game.GetTimeScale() ), "%02i:%02i") if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then elseif not localplayer:getDarkRPVar("Arrested") then Arrested = function() end end draw.RoundedBox( 0, ScrW() / 2 - ( width / 2 ), 200, width + 20, 3, DankConfig.FirstColor ) draw.SimpleText( "You have been arrested/detained!","MInfoFont", (ScrW() / 2), 180, DankConfig.SecondColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) draw.SimpleText( "Time Remaining: " .. time,"SInfoFont", (ScrW() / 2), 220, DankConfig.SecondColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end end) As this draws a timer on the local players hud all I want is another way of displaying the timer in a cam.Start3D2D so other players can see it.
Maybe if you want other players to see it you need to network msg to them. I guess in the original one it only networked it to the player viewing it and now all other players.
How would I get the usermessage.Hook("GotArrested") from the server I have absolutely no idea where to being with that.
Do some detective stuff, CTRL+F "net.WriteFloat" and find out why the piece of code you inspired your from works.
I've tried writing the networking for it, but it still doesn't help from what I've got: Clientside: local Arrested = function() end usermessage.Hook("GotArrested", function(msg) StartArrested = CurTime() ArrestedUntil = msg:ReadFloat() surface.SetFont( "MInfoFont" ) local width, height = surface.GetTextSize( "You have been arrested/detained!" ) Arrested = function() time = string.FormattedTime( math.ceil( ( ArrestedUntil - ( CurTime() - StartArrested ) ) * 1 / game.GetTimeScale() ), "%02i:%02i") if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then elseif not localplayer:getDarkRPVar("Arrested") then Arrested = function() end end draw.RoundedBox( 0, ScrW() / 2 - ( width / 2 ), 200, width + 20, 3, DankConfig.FirstColor ) draw.SimpleText( "You have been arrested/detained!","MInfoFont", (ScrW() / 2), 180, DankConfig.SecondColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) draw.SimpleText( "Time Remaining: " .. time,"SInfoFont", (ScrW() / 2), 220, DankConfig.SecondColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) net.Start( "DankArrestedTimer" ) net.WriteFloat( time ) end end) Thats where I'm trying to take the float from I try and call it later in the script with: net.Start( "DankArrestedTimer" ) net.ReadFloat( time ) Serverside: util.AddNetworkString( "DankArrestedTimer" ) It still throws me the same error: [ERROR] addons/darkrpmodification/lua/darkrp_modules/sw_hud/cl_hud.lua:1368: attempt to concatenate global 'time' (a nil value)   1. fn - addons/darkrpmodification/lua/darkrp_modules/sw_hud/cl_hud.lua:1368    2. unknown - addons/ulib/lua/ulib/shared/hook.lua:109 I presume I'm reading it wrong or calling it wrong, I just can't figure it out and it's frustrating :/
why are you using usermessage instead of net? If you want to put this players head, function have to be in hook. It is HUDPaint hook I think.
Sorry, you need to Log In to post a reply to this thread.