• Print

Author Topic: DarkRP setmoney / other ulx commands  (Read 9681 times)

0 Members and 1 Guest are viewing this topic.

Offline Legendahkiin

  • Newbie
  • *
  • Posts: 2
  • Karma: 2
DarkRP setmoney / other ulx commands
« on: December 28, 2015, 08:29:43 am »
As we use ULX in our server, I'd like to implement some of the darkRP commands to ULX too, instead of having to go into console and doing it that way (we use a different scoreboard than FAdmin).
The first thing I want to do is implement the setmoney command, as it's a basic command that I, personally, am in need of.

The command "works", however rp_setmoney returns the message "Invalid Argument", and I can't really see why -- and this is my first time "making a ulx command".
Code: Lua
  1. local CATEGORY_NAME = "DarkRP"
  2.  
  3. ---------------------------- Set money -----------------------------------
  4.  
  5. function ulx.setmoney( calling_ply, target_ply, amount)
  6.         --calling_ply:ConCommand( "rp_setmoney " .. tostring(target_ply) .. " " .. tostring(amount) ) -- First I tried ConCommand, and it didn't work.
  7.         calling_ply:RunConsoleCommand( "rp_setmoney", tostring(target_ply), tostring(amount)) -- Tried this too, also didn't work
  8.  
  9.         ulx.fancyLogAdmin( calling_ply, "#A set the money of #T to #i.", target_ply, amount )
  10. end
  11.  
  12. local setmoney = ulx.command( CATEGORY_NAME, "ulx setmoney", ulx.setmoney, "!setmoney" )
  13. setmoney:addParam{ type=ULib.cmds.PlayerArg }
  14. setmoney:addParam{ type=ULib.cmds.NumArg, min=0, max=10000, default=10000, hint="money", ULib.cmds.optional }
  15.  
  16. setmoney:defaultAccess( ULib.ACCESS_ADMIN )
  17. setmoney:help( "Sets money for the specified person." )
  18.  

I think it's probably related to addParam, as I haven't fully understood that myself :&
If I've posted in the wrong section or anything, please excuse me.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: DarkRP setmoney / other ulx commands
« Reply #1 on: December 28, 2015, 09:12:12 am »
Always use print() on objects that you're not sure about. If you used print(tostring(target_ply)), you'd see immediately why it isn't working. Depending on how rp_setmoney accepts targets, you probably want to use Nick() (though this is problematic for complex names) or UniqueID().

You'd probably be better off looking at how rp_setmoney works and call the relevant API directly instead of going through the console.
Experiencing God's grace one day at a time.

Offline monkeymacman

  • Newbie
  • *
  • Posts: 44
  • Karma: 13
Re: DarkRP setmoney / other ulx commands
« Reply #2 on: December 28, 2015, 09:19:57 am »
There is also a function player:setDarkRPVar("money", amount) so you could use that on target_ply as well there is also player:addMoney(amount) which can be used with negatives to make add and take money commands, and you can use player:getDarkRPVar("money") to view their money amount which you could use to make a viewmoney command
« Last Edit: December 28, 2015, 09:23:47 am by monkeymacman »

Offline Legendahkiin

  • Newbie
  • *
  • Posts: 2
  • Karma: 2
Re: DarkRP setmoney / other ulx commands
« Reply #3 on: December 28, 2015, 11:04:21 am »
Always use print() on objects that you're not sure about. If you used print(tostring(target_ply)), you'd see immediately why it isn't working. Depending on how rp_setmoney accepts targets, you probably want to use Nick() (though this is problematic for complex names) or UniqueID().
There is also a function player:setDarkRPVar("money", amount) so you could use that on target_ply as well there is also player:addMoney(amount) which can be used with negatives to make add and take money commands, and you can use player:getDarkRPVar("money") to view their money amount which you could use to make a viewmoney command

You'd probably be better off looking at how rp_setmoney works and call the relevant API directly instead of going through the console.

Thanks for the responses -- I didn't realize something so simple.
I'll definitely use print() more often to debug / fix my things -- thanks to both of you. :)

  • Print