• Print

Author Topic: Help again with RunConsoleCommand  (Read 10187 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?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Help again with RunConsoleCommand
« Reply #3 on: December 29, 2014, 01:05:31 pm »
Can I be so bold as to ask you to alter as I'm not 100% sure?
I suppose, one moment. I'll edit back when I'm done.

EDIT: Untested, but here 'ya go.
Code: Lua
  1. if SERVER then
  2.         util.AddNetworkString( "ulx_dayz_admin" )
  3.  
  4.         net.Receive( "ulx_dayz_admin",
  5.                 function()
  6.                         game.ConsoleCommand( net.ReadString() )
  7.                 end
  8.         )
  9. end
  10.  
  11. local CATEGORY_NAME  = "Day-Z Admin"
  12. local gamemode_error = "The current gamemode is not Gmod Day-Z!"
  13.  
  14. ------------------------------ Give Credits ------------------------------
  15. function ulx.givecredits( calling_ply, target_plys, credits )
  16.         if not GetConVarString("gamemode") == "dayz" then
  17.                 ULib.tsayError( calling_ply, gamemode_error, true )
  18.         else
  19.                 local affected_plys = {}
  20.  
  21.                 for i=1, #target_plys do
  22.                         local v    = target_plys[ i ]
  23.                         local name = v:Nick()
  24.                
  25.                         local ccstring =        "dz_giveitem item_credits" .. name .. credits .. "\n"
  26.  
  27.                         net.Start( "ulx_dayz_admin" )
  28.                                 net.WriteString( ccstring )
  29.                         net.SendToServer()
  30.  
  31.                         table.insert( affected_plys, v )
  32.                 end
  33.  
  34.                 ulx.fancyLogAdmin( calling_ply, "#A gave #i credit(s) to #T.", affected_plys, credits )
  35.         end
  36.  
  37. end
  38.  
  39. local givecredit = ulx.command( CATEGORY_NAME, "ulx givecredits", ulx.givecredits, "!givecredits" )
  40. givecredit:addParam{ type=ULib.cmds.PlayersArg }
  41. givecredit:addParam{ type=ULib.cmds.NumArg, hint = "credits", min = 1, default = 1 }
  42. givecredit:defaultAccess( ULib.ACCESS_ADMIN )
  43. givecredit:help( "Gives credits to players." )
  44.  
  45. ------------------------------ Give Money ------------------------------
  46. function ulx.givemoney( calling_ply, target_plys, money )
  47.         if not GetConVarString("gamemode") == "dayz" then
  48.                 ULib.tsayError( calling_ply, gamemode_error, true )
  49.         else
  50.                 local affected_plys = {}
  51.  
  52.                 for i=1, #target_plys do
  53.                         local v    = target_plys[ i ]
  54.                         local name = v:Nick()
  55.  
  56.                         local ccstring =        "dz_giveitem item_money" .. name .. credits .. "\n"
  57.  
  58.                         net.Start( "ulx_dayz_admin" )
  59.                                 net.WriteString( ccstring )
  60.                         net.SendToServer()
  61.                
  62.                         table.insert( affected_plys, v )
  63.                 end
  64.  
  65.                 ulx.fancyLogAdmin( calling_ply, "#A gave #i money to #T.", affected_plys, money )
  66.         end
  67.  
  68. end
  69.  
  70. local givemoney = ulx.command( CATEGORY_NAME, "ulx givemoney", ulx.givemoney, "!givemoney" )
  71. givemoney:addParam{ type = ULib.cmds.PlayersArg }
  72. givemoney:addParam{ type = ULib.cmds.NumArg, hint = "money", min = 1, default = 1 }
  73. givemoney:defaultAccess( ULib.ACCESS_ADMIN )
  74. givemoney:help( "Gives money to players." )
« Last Edit: December 29, 2014, 01:14:43 pm 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 #4 on: December 29, 2014, 01:54:37 pm »
Thank you I'll test it and send back update. Thanks again

Offline [TBR] Lt Usher

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
    • http://www.itwasntme.co.uk
Re: Help again with RunConsoleCommand
« Reply #5 on: December 30, 2014, 04:55:32 am »
it's kicking an error

Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/sh/dayzbank.lua:42: attempt to call field 'SendToServer' (a nil value)
[ERROR] addons/ulx/lua/ulx/modules/sh/dayzbank.lua:73: attempt to call field 'SendToServer' (a nil value)
« Last Edit: December 30, 2014, 04:58:44 am by [TBR] Lt Usher »

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Help again with RunConsoleCommand
« Reply #6 on: December 30, 2014, 01:39:29 pm »
it's kicking an error

Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/sh/dayzbank.lua:42: attempt to call field 'SendToServer' (a nil value)
[ERROR] addons/ulx/lua/ulx/modules/sh/dayzbank.lua:73: attempt to call field 'SendToServer' (a nil value)

The issue here is that you haven't defined SendToServer as anything its a nil value it does nothing and it always will do nothing until you define it to do something.
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Help again with RunConsoleCommand
« Reply #7 on: December 30, 2014, 02:51:05 pm »
The issue here is that you haven't defined SendToServer as anything its a nil value it does nothing and it always will do nothing until you define it to do something.
http://wiki.garrysmod.com/page/net/SendToServer

Is that even the addon code I sent? 'Cause that code calls SendToServer on 29 and 60.
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 #8 on: December 30, 2014, 03:11:01 pm »
Yep it's deffinatly the same code and I'm not sure why it's pulling a nill value

Offline [TBR] Lt Usher

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
    • http://www.itwasntme.co.uk
Re: Help again with RunConsoleCommand
« Reply #9 on: December 31, 2014, 04:33:37 am »
nope the new code doesn't work either

Code: [Select]
local CATEGORY_NAME  = "Day-Z Bank 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 ]
local steamid = v:SteamID()
 
local ccstring = ("dz_giveitemid ".. steamid .." item_credits ".. credits .."\n")

if SERVER then
game.ConsoleCommand( ccstring )
end
 
table.insert( affected_plys, v )
end
 
ulx.fancyLogAdmin( calling_ply, "#A gave #T #i credit(s)", 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 = "credits", min = 1, default = 1 }
givecredit:defaultAccess( ULib.ACCESS_ADMIN )
givecredit:help( "Gives credits to players." )
 
------------------------------ 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 ]
local steamid = v:SteamID()
 
local ccstring = "dz_giveitemid ".. steamid .." item_money ".. money .."\n"
 
if SERVER then
game.ConsoleCommand( ccstring )
end
 
table.insert( affected_plys, v )
end
 
ulx.fancyLogAdmin( calling_ply, "#A gave #T #i money", 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 = "money", min = 1, default = 1 }
givemoney:defaultAccess( ULib.ACCESS_ADMIN )
givemoney:help( "Gives money to players." )

Error:

Code: [Select]
Bad SetLocalOrigin(13963.000000,19502.000000,34.000000) on gmod_hands (602)
[TBR] Lt Usher gave Themself 1 credit(s)
ServerLog: [ULX] [TBR] Lt Usher gave Themself 1 credit(s)
Player STEAM_0 doesn't exist in the database! They've never joined the server!

From what I can make of it is the steam id is not infilling in full please help!
« Last Edit: December 31, 2014, 07:18:45 am by [TBR] Lt Usher »

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: Help again with RunConsoleCommand
« Reply #10 on: December 31, 2014, 10:30:08 am »
Silly question, but are you testing in single player?

Offline [TBR] Lt Usher

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
    • http://www.itwasntme.co.uk
Re: Help again with RunConsoleCommand
« Reply #11 on: December 31, 2014, 04:02:42 pm »
No, it's hosted on a test bed server

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help again with RunConsoleCommand
« Reply #12 on: December 31, 2014, 04:20:57 pm »
GameConsole command is likely choking on the colon ":" in the steamid.
Partial reason IMO that Gmod went to using player ids.
There are ways around it, I don't remember off top of my head.
Might try escaping out some quotes so it tries to wrap the colon in quotes?
Quote
local ccstring = ("dz_giveitemid \"".. steamid .."\" item_credits ".. credits .."\n")
Does dz_giveitemid have to be passed a steam ID?
Can't it handle a name or player object? (if it's only steamid, bad design imo)

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline [TBR] Lt Usher

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
    • http://www.itwasntme.co.uk
Re: Help again with RunConsoleCommand
« Reply #13 on: December 31, 2014, 10:38:21 pm »
Unfortunately it will only take a steamid as it enters Into a MySQL database, dz_giveitem works with players name but didn't have much luck there either for some reason?

  • Print