Author Topic: Help again with RunConsoleCommand  (Read 6697 times)

0 Members and 1 Guest are viewing this topic.

Offline [TBR] Lt Usher

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
    • http://www.itwasntme.co.uk
Help again with RunConsoleCommand
« on: December 29, 2014, 06:52:21 AM »
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: [Select]
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." )

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Help again with RunConsoleCommand
« Reply #1 on: December 29, 2014, 09:47:17 AM »
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.
« Last Edit: December 29, 2014, 11:26:41 AM by Bytewave »
bw81@ulysses-forums ~ % whoami
Homepage

Offline [TBR] Lt Usher

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
    • http://www.itwasntme.co.uk
Re: Help again with RunConsoleCommand
« Reply #2 on: December 29, 2014, 11:57:05 AM »
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