• Print

Author Topic: Help please.  (Read 6001 times)

0 Members and 1 Guest are viewing this topic.

Offline Unknown Gamer

  • Jr. Member
  • **
  • Posts: 79
  • Karma: -2
    • TrueKnife TTT
Help please.
« on: September 21, 2014, 08:17:39 pm »
Hey,
I need some help with my code. Its suppsed to be when someone types !yes into chat. it returns "Get denied. No." in console. Any help with my code would be appreacitated :)

Code: [Select]
function ulx.response( PrintMessage )
Player:PrintMessage( HUD_PRINTCONSOLE, "Get denied. No." )
end
end

local response = ulx.response( CATEGORY_NAME, "ulx response", ulx.response, "!yes" )
response:addParam{ type=ULib.cmds.PlayersArg }
response:defaultAccess ( ULib.ACESS.ADMIN )
response:help ( "A test script for creepy" )

This is my first code from scratch. So I may not get things a be a newb.
« Last Edit: September 23, 2014, 12:30:44 pm by BuilderGaming »
Newb Coder. Soon to get better

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Stupid Question -_-
« Reply #1 on: September 21, 2014, 09:16:58 pm »
If it's not obvious looking over our actual code files, see "NEW STUFF HERE" section of post from some years ago.
How-To/Comparison - ULX SVN vs old ULX release command structure
(Though, technically "new" when that post was written, we've been using the "new" style almost 5 years now)
Oh, and there's a heavily commented file attachment to that post of a previous converted "rocket" command MrPresident wrote.
Comments should be reasonably self explanatory.

Other good posts are the stickies at the top of our developer forum, where I moved your question to.
Want to patch or work on a Ulysses project? Use our codestyle.
ULib Documentation
Resources to get started with Lua
« Last Edit: September 21, 2014, 09:20:38 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Unknown Gamer

  • Jr. Member
  • **
  • Posts: 79
  • Karma: -2
    • TrueKnife TTT
Re: Help please.
« Reply #2 on: September 25, 2014, 12:42:33 pm »
*BUMP*
Newb Coder. Soon to get better

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Help please.
« Reply #3 on: September 25, 2014, 01:51:57 pm »
JamminR just gave you a bunch of resources to help you, yet you bump the thread.
For what?
Out of the Garry's Mod business.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help please.
« Reply #4 on: September 25, 2014, 11:19:45 pm »
He posted code change. But, yeah, rather than 'bump', he should have posted a question or statement.
He's not paying attention/learning to read what Gmod errors are telling him.
Gmod would give him 3 errors off the bat.
One about table not expected, one about null variable, one about end of line/function.
1) He's using ULX 'playerSArg...which passes a table of players (even if table only has one player), not a single player .
2) He's not defining the variable for what Player is tied to in the print message.
3) He's also got two "end"s in the function that would only need one at this point.
« Last Edit: September 25, 2014, 11:23:38 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Unknown Gamer

  • Jr. Member
  • **
  • Posts: 79
  • Karma: -2
    • TrueKnife TTT
Re: Help please.
« Reply #5 on: September 26, 2014, 01:32:36 pm »
Still kinda don't get it. Could someone replicate what my code should look like so I can see what it should look like?
Newb Coder. Soon to get better

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Help please.
« Reply #6 on: September 26, 2014, 02:51:58 pm »
Sounds like you want someone to make it for you.
Out of the Garry's Mod business.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Help please.
« Reply #7 on: September 26, 2014, 02:53:50 pm »
I'm bored so I might try and through a rough script together for you, no promise though.
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 Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Help please.
« Reply #8 on: September 26, 2014, 03:09:14 pm »
When someone types "!yes" into chat, "Get denied. No." is put into their console
I removed the player argument, so you can't do "!yes Garry", for example (assuming someone named Garry is in your server)

Code: Lua
  1. function ulx.response( calling_ply )
  2.         calling_ply:PrintMessage( HUD_PRINTCONSOLE, "Get denied. No." )
  3. end
  4.  
  5. local response = ulx.command( CATEGORY_NAME, "ulx response", ulx.response, "!yes", true )
  6. response:defaultAccess( ULib.ACCESS_ALL )
  7. response:help( "A test script for creepy" )

Offline Unknown Gamer

  • Jr. Member
  • **
  • Posts: 79
  • Karma: -2
    • TrueKnife TTT
Re: Help please.
« Reply #9 on: September 26, 2014, 03:34:28 pm »
When someone types "!yes" into chat, "Get denied. No." is put into their console
I removed the player argument, so you can't do "!yes Garry", for example (assuming someone named Garry is in your server)

Code: Lua
  1. function ulx.response( calling_ply )
  2.         calling_ply:PrintMessage( HUD_PRINTCONSOLE, "Get denied. No." )
  3. end
  4.  
  5. local response = ulx.command( CATEGORY_NAME, "ulx response", ulx.response, "!yes", true )
  6. response:defaultAccess( ULib.ACCESS_ALL )
  7. response:help( "A test script for creepy" )

Thank You! I kind of get it. Learned a little from this. Thanks Guys :D
Newb Coder. Soon to get better

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help please.
« Reply #10 on: September 26, 2014, 09:27:50 pm »
Study up on variables, both defined in function, and passed to function.
ULX will always pass calling_ply (this isn't true of lua itself in general)
Here's example of YOUR code, commented to show exactly what should be fixed (somewhat apparent in zmaster, but perhaps not clear to a new coder)

Code: [Select]
function ulx.response( PrintMessage ) -- THE part inside (), is passed TO the function from WHATEVER your calling the function.
-- in the case of ulx, var1, var2.... , var1 is ALWAYS 99% going to be the calling player, hence, we often name it calling_ply, so change "PrintMessage" to calling_ply
Player:PrintMessage( HUD_PRINTCONSOLE, "Get denied. No." ) -- "Player:" is not defined. Null. You could do, before this line, Player == calling_ply, or better yet, just use calling_ply:PrintMessage( ...)
end -- one too many ends....remove it. You didn't use any other if/then/for logic statements that need an end
end -- ends the function.

local response = ulx.response( CATEGORY_NAME, "ulx response", ulx.response, "!yes" )
response:addParam{ type=ULib.cmds.PlayersArg } -- Don't need this line. It would pass var2, in this case, a table of players, we often name the var target_ply
response:defaultAccess ( ULib.ACESS.ADMIN ) -- Tell Ulib the default group needed.
response:help ( "A test script for creepy" ) -- Obvious, adds to the help menu.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print