General > Developers Corner
Help with custom ULX command.
kwinkywolf:
Hello to whomever may be reading this and thank you,
I can't seem to figure out how to set up custom ulx commands.
I'm working on an XP/Credit shop system with levelling and perks and so on, and I want to be able to set, add, remove and do other things with credits, xp and levels by using ULX considering I thought it would be easier than making my own arguments in a chat command.
The code below is all I have so far for the ULX stuff, i've simply put it on the bottom of the serverside script I have running, could someone please share some advice? I understand it's documented, but I can barely find a decent documentation for someone brand new to the idea of Ulib and ULX.
--- Code: ---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( CATEGORY_NAME, "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." )
--- End code ---
JamminR:
What help are you needing? Does your command run? If not, what errors?
kwinkywolf:
The command doesn't work, and doesn't appear in the menu. There's absolutely no errors, as if I didn't add it.
JamminR:
I see no reason this should not appear.
The most common, if you are including it in your own code, is if your files are executing before ULib and ULX have started.
An error during server startup, in server console, would show that.
You could guarantee ULib and ULX was operational/running by moving the code to a ulx modules folder within your own addon.
gmod/addons/your_addon_name/lua/ulx/modules/your_file.lua
kwinkywolf:
Ok! Awesome, so the command now works and responds to me typing !setxp, however it doesn't show in the ULX Menu, and when I try to run the command it returns the following error in the console...
attempt to call method 'GetPData' (a nil value)[GGG]Kwinky Wolf: !setxp kwinky 5
Code on the line it's reporting to be the problem...
--- Code: --- local oldxp = target_ply:GetPData("XP", 0)
--- End code ---
Now, i'm unsure as to why it's failing to get the data, but i'm convinced it's to do with it not being able to find the player. So I tried to use "" and type in my full name letter for letter, spaces included and caps and yet it still didn't work. Thought I may have needed to do something like a for loop to loop through all players, but that didn't work either...
--- Code: --- function ulx.setxp( calling_ply, target_ply, xp )
for k, v in pairs( player.GetAll() ) do
if v = target_ply then
local oldxp = v:GetPData("XP", 0)
local newxp = oldxp + xp
target_ply:SetPData("XP", newxp)
end
end
ulx.fancyLogAdmin( calling_ply, "#A set #T's xp to #i", target_ply, xp )
end
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version