General > Developers Corner

Help with custom ULX command.

<< < (2/3) > >>

JamminR:
Yoru original code should be fine.
Again, any errors that would keep it from appearing in the help menu, if your group truly is or inherits admin access, would show in server console at startup.

As for error on run of the command, you likely need to make sure of two things -
1) - Where the Pdata is stored - It likely should be retrieved from the 'server' sv.db file - so, make sure the code only executes on the server side.
2) - Ensure that "XP" exists (ie, not "xp" or "Xp"...). Lua is case sensitive.

kwinkywolf:
Yeah, i've made sure XP exists... I set the data multiple times. I also havethe script running on the server now, and that doesn't work. And there's no errors at all, it simply isn't showing in the menu... So, i'm completely stumped :/

Timmy:

--- Quote from: kwinkywolf on July 04, 2018, 08:52:36 PM ---attempt to call method 'GetPData' (a nil value)
--- End quote ---
Also take a closer look at target_ply. Use functions like type, print and PrintTable to inspect the data inside. You will notice that target_ply is a table. And the player you targeted is inside that table.

You are currently using parameter type cmds.PlayersArg. This type is used when you want to be able to target multiple players. This parameter type will require you to loop through each player inside the returned table and call the desired method(s) on each Player object.

--- Code: ---for i=1, #target_plys do
    target_plys[ i ]:SetPData( 12 )
end
--- End code ---

Alternatively, use cmds.PlayerArg if your command should only target a single player. There is no need to loop when this parameter type is used.

--- Code: ---target_ply:SetPData( 12 )
--- End code ---


--- Quote from: kwinkywolf on July 06, 2018, 08:23:50 AM ---it simply isn't showing in the menu...
--- End quote ---
You can run a command that doesn’t show up in XGUI? That’s odd.
Open the developer console on your game client and run "ulx help". Is your command listed in the output?

JamminR:
Thanks for reminding me Timmy - I've given the exact same answer several times over many years regarding target and PlayerArg vs Args, yet, I missed it now.

kwinkywolf:
Yep, I caught that literally last night haha! Such an easy mistake to make, and yet such a fatal one obviously. Thank you so much though, both of you!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version