• Print

Author Topic: Custom !votesong error  (Read 8335 times)

0 Members and 1 Guest are viewing this topic.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Custom !votesong error
« on: October 29, 2015, 02:01:28 pm »
After Timmy made me a !youtube command to play audio the owner of my server requested a !votesong ID and I have it figured out except that when I join the server I get an error saying that on line 6 the then has to be closer to the =. With little to none experience with variables and some strings Im not sure how I can fix this :/

Code: Lua
  1. local CATEGORY_NAME = "Advanced Simplicty"
  2.  
  3. function ulx.votesong( calling_ply, string )
  4.         v = v + 1
  5.         PrintMessage( HUD_PRINTTALK, "A vote has been started to play a song! If you wish to vote to play the song, type, !votesong " .. string .. "" )
  6.         if v = 3 then
  7.                 game.ConsoleCommand( "ulx youtube " .. string .. "" )
  8.                 ulx.fancyLogAdmin( "Console has passed the request to play the music!" )
  9.                 if ply:IsUserGroup( "superadmin" ) then
  10.                         hook.Add( "VetoSay", "VetoSong", function( calling_ply, text )
  11.                                 text = string.lower( text )
  12.                                         if ( text = "!vetosong" ) then
  13.                                                 v = 0
  14.                                                 return ""
  15.                                         end
  16.                         end )
  17.                 end
  18.         end
  19. end
  20. local votesong = ulx.command( "ulx votesong", ulx.votesong, "!votesong" )
  21. votesong:defaultAccess( ULib.USER )
  22. votesong:help( "Type !votesong ID to play audio from youtube." )
  23.  

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Custom !votesong error
« Reply #1 on: October 29, 2015, 02:59:10 pm »
In most programming languages (lua included), the '=' operator is only used for assignment. You use var = val to assign the value 'val' to the variable 'var'. I assume you are trying to compare 'v' with '3'. For this, you would use the comparison operator '=='. So line 6 would be "if v == 3 then".

Edit:

Also you misspelled simplicity.
« Last Edit: October 29, 2015, 03:03:02 pm by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #2 on: October 29, 2015, 05:11:29 pm »
In most programming languages (lua included), the '=' operator is only used for assignment. You use var = val to assign the value 'val' to the variable 'var'. I assume you are trying to compare 'v' with '3'. For this, you would use the comparison operator '=='. So line 6 would be "if v == 3 then".
Oh, ok! Thanks!
Edit:
Also you misspelled simplicity.
Never would have noticed haha!

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #3 on: October 29, 2015, 05:36:41 pm »
This is just something somewhat separate, but when I add it to the server, the command doesnt exist. Just to use "ulx help". Code for the following two:

Code: Lua
  1. -- This is just a note I put in here for help, this is trying to make it so if you type !addons it gives you the link.
  2. local CATEGORY_NAME = "Advanced Simplicity"
  3.  
  4. function ulx.addons( calling_ply, command )
  5.         ply:ChatPrint( "Copy and paste this into your browser! [url]http://steamcommunity.com/sharedfiles/filedetails/?id=498863022[/url]" )
  6.         ulx.fancyLogAdmin( calling_ply, "#A has just requested the download to the addon pack, request yours by typing !addons")
  7. end
  8. local addons = ulx.command( "ulx addons", ulx.addons, "!addons" )
  9. addons:defaultAccess( ULib.USER )
  10. addons:help( "Prints the collect URL. !addons" )
Code: Lua
  1. -- This is just a note I put in here for help, this command is the following one above but changed for the double ==
  2. local CATEGORY_NAME = "Advanced Simplicity"
  3.  
  4. function ulx.votesong( calling_ply, string )
  5.         v = v + 1
  6.         PrintMessage( HUD_PRINTTALK, "A vote has been started to play a song! If you wish to vote to play the song, type, !votesong " .. string .. "" )
  7.         if v == 3 then
  8.                 game.ConsoleCommand( "ulx youtube " .. string .. "" )
  9.                 ulx.fancyLogAdmin( "Console has passed the request to play the music!" )
  10.                 if ply:IsUserGroup( "superadmin" ) then
  11.                         hook.Add( "VetoSay", "VetoSong", function( calling_ply, text )
  12.                                 text = string.lower( text )
  13.                                         if ( text = "!vetosong" ) then
  14.                                                 v = 0
  15.                                                 return ""
  16.                                         end
  17.                         end )
  18.                 end
  19.         end
  20. end
  21. local votesong = ulx.command( "ulx votesong", ulx.votesong, "!votesong" )
  22. votesong:defaultAccess( ULib.USER )
  23. votesong:help( "Type !votesong ID to play audio from youtube." )
  24.  

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Custom !votesong error
« Reply #4 on: October 29, 2015, 09:15:58 pm »
This is just something somewhat separate, but when I add it to the server, the command doesnt exist. Just to use "ulx help". Code for the following two:

Code: Lua
  1. -- This is just a note I put in here for help, this is trying to make it so if you type !addons it gives you the link.
  2. local CATEGORY_NAME = "Advanced Simplicity"
  3.  
  4. function ulx.addons( calling_ply, command )
  5.         ply:ChatPrint( "Copy and paste this into your browser! [url]http://steamcommunity.com/sharedfiles/filedetails/?id=498863022[/url]" )
  6.         ulx.fancyLogAdmin( calling_ply, "#A has just requested the download to the addon pack, request yours by typing !addons")
  7. end
  8. local addons = ulx.command( "ulx addons", ulx.addons, "!addons" )
  9. addons:defaultAccess( ULib.USER )
  10. addons:help( "Prints the collect URL. !addons" )
Code: Lua
  1. -- This is just a note I put in here for help, this command is the following one above but changed for the double ==
  2. local CATEGORY_NAME = "Advanced Simplicity"
  3.  
  4. function ulx.votesong( calling_ply, string )
  5.         v = v + 1
  6.         PrintMessage( HUD_PRINTTALK, "A vote has been started to play a song! If you wish to vote to play the song, type, !votesong " .. string .. "" )
  7.         if v == 3 then
  8.                 game.ConsoleCommand( "ulx youtube " .. string .. "" )
  9.                 ulx.fancyLogAdmin( "Console has passed the request to play the music!" )
  10.                 if ply:IsUserGroup( "superadmin" ) then
  11.                         hook.Add( "VetoSay", "VetoSong", function( calling_ply, text )
  12.                                 text = string.lower( text )
  13.                                         if ( text = "!vetosong" ) then
  14.                                                 v = 0
  15.                                                 return ""
  16.                                         end
  17.                         end )
  18.                 end
  19.         end
  20. end
  21. local votesong = ulx.command( "ulx votesong", ulx.votesong, "!votesong" )
  22. votesong:defaultAccess( ULib.USER )
  23. votesong:help( "Type !votesong ID to play audio from youtube." )
  24.  
  • You're missing a category name. ulx.command expects 4-ish arguments: category, concommand, function, and saycommand, in that order. You're missing the first.
  • The access level for "user" is ULib.ACCESS_ALL
  • You're missing a parameter statement for your votesong thing. You never actually take into account what they vote for. See here for a small template to help you a bit with that.
bw81@ulysses-forums ~ % whoami
Homepage

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #5 on: October 30, 2015, 04:15:51 am »
I feel so stupid .-.
How did I miss that?!?

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #6 on: October 30, 2015, 04:19:23 am »
You're missing a parameter statement for your votesong thing. You never actually take into account what they vote for.
I somewhat get what you mean, although I have never used parameters. After Timmy made me the command it plays the actual title from the video in chat, but Im not sure how you put that in. Little help, please?

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Custom !votesong error
« Reply #7 on: October 30, 2015, 03:07:06 pm »
I somewhat get what you mean, although I have never used parameters. After Timmy made me the command it plays the actual title from the video in chat, but Im not sure how you put that in. Little help, please?

Bytewave gave you a template for a basic ULX command with a parameter.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #8 on: October 30, 2015, 03:08:17 pm »
Bytewave gave you a template for a basic ULX command with a parameter.
Except I dont know how to change the parameter to what I need :-[

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Custom !votesong error
« Reply #9 on: October 30, 2015, 04:09:44 pm »
Well in the addParam function the first argument is "type = type". If you checked out the handy docs you would find these lovely things:

    cmds.BaseArg
    cmds.BoolArg
    cmds.CallingPlayerArg
    cmds.NumArg
    cmds.PlayerArg
    cmds.PlayersArg
    cmds.StringArg

You probably want to set 'type' to one of those.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #10 on: October 30, 2015, 04:36:07 pm »
Sorry I have to be short but I am using my iPhones hot spot. Even after reading that I dont get what you mean .-. Im not 10/10 lua expert or 1/10 I know a decent amount of it. I know some. Im glad that you are helping, :), but I dont understand what you mean. This way, people know what you vote for, and your helping with that but, Im not sure how to do it myself.. I have 2 scripts, both in 1 file. How would I take the song title from the -- YouTube part and below and implement that into the -- VoteSong part so people know what they vote for? Now hopefully this is a better look on how Im doing to code and how it can be done?

Code: Lua
  1. -- VoteSong
  2. function ulx.votesong( calling_ply, string )
  3.         v = v + 1
  4.         PrintMessage( HUD_PRINTTALK, "A vote has been started to play a song! If you wish to vote to play the song, type, !votesong " .. string .. "" )
  5.         if v == 3 then
  6.                 game.ConsoleCommand( "ulx youtube " .. string .. "" )
  7.                 ulx.fancyLogAdmin( "Console has passed the request to play the music!" )
  8.                 if ply:IsUserGroup( "superadmin" ) then
  9.                         hook.Add( "VetoSay", "VetoSong", function( calling_ply, text )
  10.                                 text = string.lower( text )
  11.                                         if ( text = "!vetosong" ) then
  12.                                                 v = 0
  13.                                                 return ""
  14.                                         end
  15.                         end )
  16.                 end
  17.         end
  18. end
  19. local votesong = ulx.command( CATEGORY_NAME, "ulx votesong", ulx.votesong, "!votesong" )
  20. votesong:defaultAccess( ULib.ACCESS_ALL )
  21. votesong:help( "Type !votesong ID to play audio from youtube." )
  22. -- End of VoteSong
  23. -- YouTube
  24. ply:ChatPrint( "Changed code for some reason I dont know. This is not the command." )
  25. -- End of YouTube
« Last Edit: October 30, 2015, 05:12:41 pm by WispySkies »

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Custom !votesong error
« Reply #11 on: October 30, 2015, 04:43:59 pm »
If you can't follow the simple instruction of setting a variable equal to something, you don't know a "decent amount" of lua.

votesong:addParam( type = cmds.StringArg )

put that somewhere under line 19.

Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #12 on: October 30, 2015, 04:53:59 pm »
If you can't follow the simple instruction of setting a variable equal to something, you don't know a "decent amount" of lua.

votesong:addParam( type = cmds.StringArg )

put that somewhere under line 19.
Im not bothering how to figure out the Params at the moment. If I take the time, yes, but Ive just started lua and Im trying bits and pieces and expanding what I know. I know this is dragging on, but that would make the vote say the song title?

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Custom !votesong error
« Reply #13 on: October 30, 2015, 05:06:33 pm »
Im not bothering how to figure out the Params at the moment. If I take the time, yes, but Ive just started lua and Im trying bits and pieces and expanding what I know. I know this is dragging on, but that would make the vote say the song title?

I'm not sure, I'm not bothering proof-reading your entire code. From a precursory look it doesn't seem so, because you're just running "ulx youtube" with the string argument at the end. Unless your youtube command has some next gen algorithm for finding the correct youtube video supplied a name, that won't work.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Custom !votesong error
« Reply #14 on: October 30, 2015, 05:11:14 pm »
I'm not sure, I'm not bothering proof-reading your entire code. From a precursory look it doesn't seem so, because you're just running "ulx youtube" with the string argument at the end. Unless your youtube command has some next gen algorithm for finding the correct youtube video supplied a name, that won't work.
Alright then! Thanks for the help, but Im just not going to use it. Its not a big deal anyway :P Although, I really appreciate it.

  • Print