• [PS2] Printing PS2_Wallet.points on hud via cl_init.lua
    4 replies, posted
[CODE] local Wallet = LocalPlayer().PS2_Wallet if Wallet == nil then timer.Simple( 60, function() end ) end local text = Wallet.points[/CODE] Trying to get PS2 points to print to the HUD in jailbreak via the cl_init.lua I keep getting [CODE][ERROR] gamemodes/jailbreak/gamemode/cl_init.lua:190: attempt to index local 'Wallet' (a nil value) 1. fn - gamemodes/jailbreak/gamemode/cl_init.lua:190 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:109 [/CODE] when pointshop isn't loaded this will appear. I tried to add the timer to make it wait if the wallet is nil but it doesn't seem to work properly. Surely there must be a proper way to wait for the initialization of PS2 before drawing the hud
[QUOTE=Shendow;52795509][lua] if Wallet == nil then timer.Simple( 60, function() end ) end local text = Wallet.points [/lua] Try to read this code in English. If your wallet doesn't exist, you make a timer that.. does nothing after 60 seconds. With that timer created, you define [I]text[/I] as [I]Wallet.points[/I], but [I]Wallet[/I] doesn't exist, hence the error you get. Creating a timer does NOT delay the execution of lines below. If you want to prevent the code from running before your Wallet doesn't exist or whatever, add a [B]return[/B].[/QUOTE] I figured it would halt execution until the timer stops. I tried to add a return like if wallet == nil then return end but then it returns out of the whole hud drawing and stops drawing the hud. Ideally I just need it to wait for pointshop 2 wallet to initialize somehow. It's executing from inside this function [CODE]hook.Add("HUDPaint", "JB Notifications", function() if LocalPlayer and _DRAWHUD then [/CODE] It draws fine but it spams the console like mad when joining the server
[QUOTE=Shendow;52795719]Just don't draw the PS2 stuff until it loads with a if block: [lua] hook.Add("HUDPaint", "etc", function() // health armor w/e if (Wallet) then // PS2 stuff end // ammo etc end) [/lua][/QUOTE] Thank you for showing me this. I really appreciate it.
Sorry, you need to Log In to post a reply to this thread.