• Issues With Networking & ULX Errors. (2 Questions).
    6 replies, posted
I thought it may be easier to just make one post with two questions, rather than two posts which would clog stuff up. Problem 1 I've been having some problems with this thing i'm making that needs to display information that's stored in the sv.db on the clientside in a DButton. The problem is that the correct info isn't being displayed, it's showing as 0 xp and 0 credits, rather than the 400 xp and 4 credits I currently have , which i've tested with a print on the server. I used an NWInt to transfer the data over, and ti worked just fine previously, however now that i've moved the timer up to the top of my code and i've added the XP int too, it just refuses to display the correct data. I understand that a timer may not be the best way to go about this, but i'll change it once i've got things working on a basic level. Server-side timer.Create( "net", 0.25, 0, function () for k, v in pairs( player.GetAll() ) do -- for k, v in pairs loops through a table of data, and player.GetAll() gets all connected players in a table. local xp = v:GetPData("XP", 0) -- Gets v's current xp. local credits = v:GetPData("Credits", 0) -- Gets v's current credit balance. v:SetNWInt("Credits", credits) -- Sets a network integer for the number of credits that can be passed between the client and server. v:SetNWInt("XP", xp) -- Sets a network integer for the number of XP that can be passed between the client and server. end end ) Client-side timer.Create( "netreceive", 0.25, 0, function() for k, v in pairs( player.GetAll() ) do xp = v:GetNWInt("XP", 0) credits = v:GetNWInt("Credits", 0) end end ) Problem 2 I made a ULX command that's supposed to set your XP to whatever you put in the command, but the command isn't displaying in the ULX Menu, and it's returning the following error on execution... attempt to call method 'GetPData' (a nil value)NAME CENSORED: !setxp ^ 10 I've attempted to put in my exact name, however even that didn't work. I tried looping through the table of players, everything... Still no idea why it isn't working, thought maybe it could be related to the above not working... But probably not. local CATEGORY_NAME = "Combine F3" function ulx.setxp( calling_ply, target_ply, xp ) local oldxp = target_ply:GetPData("XP", 0) local newxp = oldxp + xp target_ply:SetPData("XP", newxp)     ulx.fancyLogAdmin( calling_ply, "#A set #T's xp to #i", target_ply, xp ) end local setxp = ulx.command( "Fun", "ulx setxp", ulx.setxp, "!setxp" ) setxp:addParam{ type=ULib.cmds.PlayersArg } setxp:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="xp", ULib.cmds.round } setxp:defaultAccess( ULib.ACCESS_ADMIN ) setxp:help( "Sets target's XP to given amount." ) The code is currently in it's own file, within lua/ulx/modules/ulx_newcommand.lua And yes, the command exists considering it returns saying I need to include a number or something if I leave it out, and it auto completes in the console.
Bump (Hope i'm allowed to do this, i know some people don't allow it in certain sites)
Yeah the timer thing you've got going on is really bad practice in my opinion. I would personally use Net Library, unless NWVar is absolutely necessary. For the second problem: ULib.cmds.PlayersArg returns a table with targets, not a single player object. Change it to ULib.cmds.PlayerArg.
Awesome! Thanks for the help, I can't believe one blood misplaced letter changed it all entirely, and the guys over at Ulysses even said it was all fine, so i'm chuffed that it works now. Although, I need to use the NWvars sadly, and it still isn't displaying. https://files.facepunch.com/forum/upload/290042/ac6fd689-d471-4859-a2a1-90c9e4c6c70c/image.png ^^ What I want to have changed. All this is on the client within an entity, which is activated when you use on the entity. ^^ Now, as you can see it isn't displaying any of the information i'm sending at all, so i'm wondering whether I've put the NW var stuff or anything in the right place or not? Current XP: 810 XP to next level: 6783.75 Level: 7 Credits: 5 ^^ What should be displayed ^^ I've included the full code for anyone trying to help I know people prefer code blocks and stuff on the post itself, but felt like there was too much code to put here tbh. And the reason i'm giving it to whomever it may concern is because of course, i'm trying to figure out if what I've put is both right and in the correct position in the code? Hopefully I've said enough and cleared it all up to prevent being scrutinized. Serverside Code here Client-Side Code here
Still a problem ^^ (Bumpidie bump)
To be honest at this point I would scratch what you did and redo it but with more thinking before hand. Couple of points : 1.surface.CreateFont shouldn't be inside a function. This will create the fonts multiple times and lag the client. 2.Checking for a level up every 1/4 of a second is a horribly inefficient way to check levels. You should instead create a levelup method that checks xp and levels everytime xp is being given. 3.Not sure where the code from the OP is but nwvars are already synced by default so you shouldnt have to put setnwint inside a timer
Alright matey, thanks for the help anyway! I'll see what I can do about re-doing it
Sorry, you need to Log In to post a reply to this thread.