• HUD Networked String Problem
    19 replies, posted
I'm working on a custom gamemode and trying to use networked variables for names etc. on the HUD only their not working. It's all set when a player joins the server so what am I doing wrong? Am I missing something? [code]draw.DrawText("Name: "..ply:GetNetworkedString("rpname"),"ScoreboardText",10,10,Color(255,255,255,255),0)[/code] I've also tried GetNWString("rpname") and calling it from a function that returns the variable to no avail.
My first guess is that you either missnamed the variables, or you didn't set it. If you can show us the relevant code from the spawn!
[QUOTE=commander204;23284046]My first guess is that you either missnamed the variables, or you didn't set it. If you can show us the relevant code from the spawn![/QUOTE] Thanks for the fast reply. The function is in a shared file, they are set on the server because when I use: [code]lua_run Msg(player.GetByID(1):GetNWString("rpname"))[/code] It returns the correct value, it just doesn't seem to work the same for the client. The following is called from PlayerInitialSpawn in init.lua: [code]function sql_value_stats(ply) local steamID=ply:SteamID() local result=sql.Query("SELECT * FROM player_info WHERE unique_id='"..steamID.."'") if result then ply:SetNetworkedString("unique_id",steamID) ply:SetNetworkedInt("money",tonumber(result[1]['money'])) ply:SetNetworkedString("rpname",tostring(result[1]['name'])) -- setting the variable ply:SetNetworkedBool("canCP",tostring(result[1]['canCP'])) ply:SetNetworkedInt("rank",tostring(result[1]['rank'])) Msg("Details Loaded.\n") else Msg("Error loading details.\n") Msg(sql.LastError().."\n") end end[/code] And trying to use it in cl_init.lua: [code]function myhud() local ply=LocalPlayer() if !ply:Alive() then return end if(ply:GetActiveWeapon()==NULL or ply:GetActiveWeapon()=="Camera") then return end local money=ply:GetMoney() draw.RoundedBox(6,5,5,200,110,Color(126,128,128,255)) draw.DrawText("Name: "..ply:GetNetworkedString("rpname"),"ScoreboardText",10,10,Color(255,255,255,255),0) draw.DrawText("CID: "..ply:UniqueID(),"ScoreboardText",10,30,Color(255,255,255,255),0) draw.DrawText("Role: "..team.GetName(ply:Team()),"ScoreboardText",10,50,Color(255,255,255,255),0) draw.DrawText("Health: "..ply:Health(),"ScoreboardText",10,70,Color(255,255,255,255),0) draw.DrawText("Credits: "..money,"ScoreboardText",10,90,Color(255,255,255,255),0) end hook.Add("HUDPaint","myhud",myhud)[/code] The money is also a network variable which is not working where the function GetMoney() is set in the same file as where the net vars are set with: [code]local meta=FindMetaTable("Player") function meta:GetMoney() return self:GetNetworkedInt("money") end[/code] It was just another way of testing methods of working to see if it would at all... it didn't.
Don't use SetNetworked and GetNetworked they always never want to work for me, just do SetNW and GetNW and see if that fixes it.
[QUOTE=Drew P. Richard;23285224]Don't use SetNetworked and GetNetworked they always never want to work for me, just do SetNW and GetNW and see if that fixes it.[/QUOTE] No luck I'm afraid... -.-
You can't get a networked int clientside if it's been set serverside or vice versa. It has to be set shared. Also, GetNWInt and GetNetworkedInt are the exact same function.
[QUOTE=dooboo2;23285834]You can't get a networked int clientside if it's been set serverside or vice versa. It has to be set shared. Also, GetNWInt and GetNetworkedInt are the exact same function.[/QUOTE] You can set it on both sides, serverside will be set on both sides, clientside only on clientside.
[QUOTE=dooboo2;23285834]You can't get a networked int clientside if it's been set serverside or vice versa. It has to be set shared. Also, GetNWInt and GetNetworkedInt are the exact same function.[/QUOTE] It is a shared file... or at least should be in init.lua theres: [code]include("sh_player.lua") AddCSLuaFile("sh_player.lua")[/code] And in cl_init.lua: [code]include("sh_player.lua")[/code] The file is called sh_player.lua... just in case...
[QUOTE=dooboo2;23285834]You can't get a networked int clientside if it's been set serverside or vice versa. It has to be set shared. Also, GetNWInt and GetNetworkedInt are the exact same function.[/QUOTE] Do you read the function name? [b]Networked[/b] means it will be the same on the client and server! (atleast it should be!) /offtopic To get back to your problem, I think it's just you don't set it, or you set it nil, do a PrintTable(result) in there and tell us what it output(ted?)
[QUOTE=commander204;23286087]To get back to your problem, I think it's just you don't set it, or you set it nil, do a PrintTable(result) in there and tell us what it output(ted?)[/QUOTE] Not entirely sure how I'm sposed to print the table result, I know whats in them because I'm using sqlite3 to get the contents of the database table (all of one player... me! XD) which has all the right info in it. The variables are set. In (server) console when you output them individually, i.e: [code]lua_run Msg(player.GetByID(1):GetNWString("rpname"))[/code] Outputs: Mainman The same with the money, on the client however; [code]lua_run_cl LocalPlayer():ChatPrint(player.GetByID(1):GetNWString("rpname"))[/code] Returns nothing and [code]lua_run_cl LocalPlayer():ChatPrint(player.GetByID(1):GetNWInt("money"))[/code] Returns 0.
That is really weird.
In your original code above, you used ply instead of LocalPlayer().
[QUOTE=Jamie932;23296732]In your original code above, you used ply instead of LocalPlayer().[/QUOTE] I did set ply to localplayer() for ease of use, check the code from cl_init.lua. Glad to see I'm not the only one that can't work this out.
[QUOTE=Dave_Parker;23297402]Where do you SET the variable in SQL? Also do some debugging, I think it's in your use of SQL PrintTable(result)[/QUOTE] For the 2nd/3rd time, the variables are set, they can be output from the server console and they are in the database. The problem is that the client cannot seem to read the variables.
Is this going to be one of those un-answerable problems where no-one knows the answer then when it's fixed we all facepalm?
Really weird!
[QUOTE=mainman46;23312252]Is this going to be one of those un-answerable problems where no-one knows the answer then when it's fixed we all facepalm?[/QUOTE] of course don't forget the :doh:!
I just asked a question very similar to this on the Ulysses forums... see it here: [url]http://forums.ulyssesmod.net/index.php/topic,4824.0.html[/url] Anyways, the suggestion made to me was that I was attempting to read a LocalPlayer() variable before the player had fully initialized on the server, and I should write a function to hook an event that happens after initialization (like spawn or initialspawn) and execute the getting of the networked variable you need there. I might go on further to guess that your hook should call a function that checks another hook for the function you want to do, like hooking "HUDPaint" to call a function that adds a check for "Player.Alive", then doing what you want it to do.
Thanks I'm looking into that now, will post back if it works or not. [editline]10:45AM[/editline] OK, apparently that broke it, I put a timer function between the hook & the function so the hook called the timer which called the function... no HUD what so ever appeared. Also the HUD has other LocalPlayer() based elements that work fine, i.e. Health & team.
Sorry, you need to Log In to post a reply to this thread.