Recent Posts

Pages: [1] 2 3 ... 10
1
Developers Corner / Re: DarkRP Refund Command
« Last post by Timmy on Today at 10:43:12 AM »
Another question, how would I confirm that it's actually working?

Try to refund yourself from the server console:
Code: [Select]
ulx refund Centurion 100
There won't be any feedback, but the money should be added to your wallet.

Last step would be to use ulx.fancyLogAdmin to log the action and deliver some feedback when you run the command:
Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2.  
  3. function ulx.refund( calling_ply, target_ply, money )
  4.     target_ply:addMoney( money )
  5.     ulx.fancyLogAdmin( calling_ply, "#A refunded $#i to #T", money, target_ply )
  6. end
  7. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund" )
  8. refund:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  9. refund:addParam{ type=ULib.cmds.NumArg, hint="money", min=1, ULib.cmds.round }
  10. refund:defaultAccess( ULib.ACCESS_ADMIN )
  11. refund:help( "Refunds a player the amount specified" )
2
Developers Corner / Re: DarkRP Refund Command
« Last post by [?] The Last Centurion on Yesterday at 11:01:30 AM »
Is this a server side only command? Or a client side only command?
Though it can still live in /sh (shared), if it's either one or the other, you'd need to specify a comparison to ensure it's only being run where it's supposed to (server or client).

Wouldn't it have to run on the server as you'd be giving another player the money? How would I go about specifying a comparison?

Other than that, I actually think it would have worked, but I made it "AddMoney" instead of "addMoney".

-snip-

Thank you, and if I do more Lua in the future, I will keep that print line thing in mind.



Another question, how would I confirm that it's actually working?
3
Developers Corner / Re: DarkRP Refund Command
« Last post by Timmy on Yesterday at 08:50:50 AM »
Make sure to double-check your command setup. You will get odd errors because your command arguments are not being parsed correctly. You intend to have a command that takes 2 parameters, but only have a single cmd:addParam instruction.

Start with a tiny piece of working code. Make small changes and verify that they work correctly. This makes it much easier to pinpoint mistakes! Use print to display the contents of your arguments in the server console.

1. Let's start with the basic command template without parameters.
Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2.  
  3. function ulx.refund( calling_ply )
  4.     print( "Command called by", calling_ply )
  5. end
  6. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund" )
  7. refund:defaultAccess( ULib.ACCESS_ADMIN )
  8. refund:help( "Refunds a player the amount specified" )

2. Now let's set up the first parameter for the the command: a player (not self).
Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2.  
  3. function ulx.refund( calling_ply, target_ply )
  4.     print( "Command called by", calling_ply )
  5.     print( "We're targeting", target_ply )
  6. end
  7. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund" )
  8. refund:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  9. refund:defaultAccess( ULib.ACCESS_ADMIN )
  10. refund:help( "Refunds a player the amount specified" )

3. Now let's set up the second parameter for the the command: a number (bigger than 0, integer).
Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2.  
  3. function ulx.refund( calling_ply, target_ply, money )
  4.     print( "Command called by", calling_ply )
  5.     print( "We're targeting", target_ply )
  6.     print( "We're refunding", money )
  7. end
  8. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund" )
  9. refund:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  10. refund:addParam{ type=ULib.cmds.NumArg, hint="money", min=1, ULib.cmds.round }
  11. refund:defaultAccess( ULib.ACCESS_ADMIN )
  12. refund:help( "Refunds a player the amount specified" )

4. Now that we've verified our arguments are parsed correctly, we can refund the player. Looks like the correct function to give money to a player is Player:addMoney.
Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2.  
  3. function ulx.refund( calling_ply, target_ply, money )
  4.     target_ply:addMoney( money )
  5. end
  6. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund" )
  7. refund:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
  8. refund:addParam{ type=ULib.cmds.NumArg, hint="money", min=1, ULib.cmds.round }
  9. refund:defaultAccess( ULib.ACCESS_ADMIN )
  10. refund:help( "Refunds a player the amount specified" )
4
Developers Corner / Re: DarkRP Refund Command
« Last post by JamminR on Yesterday at 08:24:09 AM »
Few things to research:
--
Is this a server side only command? Or a client side only command?
Though it can still live in /sh (shared), if it's either one or the other, you'd need to specify a comparison to ensure it's only being run where it's supposed to (server or client).
--
Do you have any command anywhere else that is trying to run this command as the game starts?
It's possible ULX might have loaded this part of code before DarkRP initialized it's code, and is being run too soon, before the DarkRp lua exists yet.
--
Tried using format GiveMoney( target_ply, money)?
I've never fully understood the technical why, but I've seen some commands not allow the <target>:<Command>(variable) format.

6
Developers Corner / Re: DarkRP Refund Command
« Last post by [?] The Last Centurion on Yesterday at 07:34:18 AM »
Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2. local money
  3.  
  4. function ulx.refund( target_ply, money )
  5.                 target_ply:GiveMoney( money )
  6.         end
  7.  
  8. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund", true)
  9. refund:addParam{ type=ULib.cmds.NumArg, hint="money", min=1, ULib.cmds.round, target_ply="!^" }
  10. refund:defaultAccess( ULib.ACCESS_ADMIN )
  11. refund:help( "Refunds a player the amount specified" )

This is the updated code, when typing "!refund (amount) (name)" I get the error "addons/ulx/lua/ulx/modules/sh/refund.lua:5: attempt to index local 'target_ply' (a number value)"


EDIT: I'm trying to fix errors as i get them, will update if it works.

EDIT2: I currently get "addons/ulx/lua/ulx/modules/sh/refund.lua:5: attempt to call method 'AddMoney' (a nil value)" and "addons/ulx/lua/ulx/modules/sh/refund.lua:5: attempt to call method 'GiveMoney' (a nil value)" as errors.
7
Developers Corner / Re: DarkRP Refund Command
« Last post by Timmy on Yesterday at 05:45:31 AM »
Make sure to tell ULX that your command takes a numeric parameter as well:
Code: Lua
  1. refund:addParam{ type=ULib.cmds.NumArg, hint="money", ULib.cmds.round }

Tip: You can choose to hand validation off to ULX:

- Add min=1 if you want the amount of money to always be above 0.
Code: Lua
  1. refund:addParam{ type=ULib.cmds.NumArg, hint="money", min=1, ULib.cmds.round }
- Add target="!^" if you don't want players to target themselves.
Code: Lua
  1. refund:addParam{ type=ULib.cmds.PlayerArg, target="!^" }
See Commands on the ULib documentation for more information on restrictions.
8
Developers Corner / Re: ULX User Group Ranks in a Loading Screen?
« Last post by Timmy on Yesterday at 05:24:01 AM »
There are many ways to implement ULX ranks in a loading screen.

Here's how I would approach this:
1. Create a PHP script that can receive and save data.
2. Create a Lua script that generates a hash table that maps SteamID -> group, serialize it, and send it off to the web server every time a group-related change occurs.
3. Create a PHP script that reads the saved data, deserialize it, and use it to look up the group by SteamID.

The following should get you something to play around with:

Create the following files on your web server:
* index.php
* update.php

Create the following file on your game server:
* lua/autorun/server/loadingscreen.lua

Instructions:
- Set the url variable in loadingscreen.lua equal to the location of the update.php script.
Code: [Select]
local url = "https://example.org/update.php"- Set your sv_loadingurl equal to the location of the index.php script. Append "?steamid=%s" to tell the script about the user's SteamID.
Code: [Select]
sv_loadingurl "https://example.org/index.php?steamid=%s"- Add a user to a group, remove a user from a group or change the name of a group to send data to the web server.
Code: [Select]
ulx adduserid STEAM_0:0:57225082 superadmin
9
Developers Corner / DarkRP Refund Command
« Last post by [?] The Last Centurion on October 21, 2017, 10:41:40 PM »
So I haven't done Lua in a while, so I'm basically new to it. I'm trying to make a command that would take the input of a target and whatever number specified.




Code: Lua
  1. local CATEGORY_NAME = "Admin"
  2. local money
  3.  
  4. function ulx.refund( calling_ply, target_ply, money )
  5.         if calling_ply == target_ply then
  6.                 DarkRP.notify(calling_ply, 1, 5, "You cannot refund yourself.")
  7.         else if money < 0 then
  8.                 DarkRP.notify(calling_ply, 1, 5, "You must enter a number higher than 0!")
  9.         else
  10.                 target_ply:GiveMoney( money )
  11.         end
  12. end
  13.  
  14. local refund = ulx.command( CATEGORY_NAME, "ulx refund", ulx.refund, "!refund", true)
  15. refund:addParam{ type=ULib.cmds.PlayerArg }
  16. refund:defaultAccess( ULib.ACCESS_ADMIN )
  17. refund:help( "Refunds a player the amount specified" )

This is what I have, it should give enough information or example of what I want. I just do not know how to make it work. I currently get an error with line 7 saying "addons/ulx/lua/ulx/modules/sh/refund.lua:5: attempt to compare nil with number" (says line 5 because i added the if statement above it after I got the error).
10
Off-Topic / MOVED: ULX User Group Ranks in a Loading Screen?
« Last post by JamminR on October 21, 2017, 09:57:13 PM »
Pages: [1] 2 3 ... 10