General > Developers Corner
Help again with RunConsoleCommand
[TBR] Lt Usher:
Ok, I'm stuck its struggling to identify the variables i.e. "v" as the target player and "credits" as the value. Please help!
--- Code: ---local CATEGORY_NAME = "Day-Z Admin"
local gamemode_error = "The current gamemode is not Gmod Day-Z"
------------------------------ Give Credits ------------------------------
function ulx.givecredits( calling_ply, target_plys, credits )
if not GetConVarString("gamemode") == "dayz" then ULib.tsayError( calling_ply, gamemode_error, true ) else
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]
RunConsoleCommand("dz_giveitem", "item_credits", v, credits )
table.insert( affected_plys, v )
end
ulx.fancyLogAdmin( calling_ply, "#A gave #T credit to #i.", affected_plys, credits )
end
end
local givecredit = ulx.command( CATEGORY_NAME, "ulx givecredits", ulx.givecredits, "!givecredits" )
givecredit:addParam{ type=ULib.cmds.PlayersArg }
givecredit:addParam{ type=ULib.cmds.NumArg, hint="The credit the player should get.", min=1, default=1 }
givecredit:defaultAccess( ULib.ACCESS_ADMIN )
givecredit:help( "Gives credit to a player." )
------------------------------ Give Money ------------------------------
function ulx.givemoney( calling_ply, target_plys, money )
if not GetConVarString("gamemode") == "dayz" then ULib.tsayError( calling_ply, gamemode_error, true ) else
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]
RunConsoleCommand("dz_giveitem", "item_money", v, money )
table.insert( affected_plys, v )
end
ulx.fancyLogAdmin( calling_ply, "#A gave #T money to #i.", affected_plys, money )
end
end
local givemoney = ulx.command( CATEGORY_NAME, "ulx givemoney", ulx.givemoney, "!givemoney" )
givemoney:addParam{ type=ULib.cmds.PlayersArg }
givemoney:addParam{ type=ULib.cmds.NumArg, hint="The money the player should get.", min=1, default=1 }
givemoney:defaultAccess( ULib.ACCESS_ADMIN )
givemoney:help( "Gives money to a player." )
--- End code ---
Bytewave:
For one, the target_plys table stores Player objects. You would want to use target_plys:Nick() for the player's name.
Second off, you'd probably want to run RunConsoleCommand server-side, probably with net messages. As it stands now, you're running it on the client and server.
[TBR] Lt Usher:
Can I be so bold as to ask you to alter as I'm not 100% sure?
An Error Has Occurred!
array_keys(): Argument #1 ($array) must be of type array, null given
[0] Board index
Go to full version