Author Topic: [Custom Commands] @setcounter@[] & @setcost@[]  (Read 1657 times)

0 Members and 1 Guest are viewing this topic.

Marstead

  • Padawan
  • **
  • Posts: 51
  • Karma: +1/-0
    • View Profile
  • Twitch Name: Marstead
[Custom Commands] @setcounter@[] & @setcost@[]
« on: May 20, 2016, 03:53:25 AM »
I would like to have the option to set a variable cost and modify the @counter@ variable for commands, instead of the cost being static and the counter always incrementing by 1.

Use Case: I use custom commands for persistent voting on things like the next game we're going to play. For example, viewers can vote for a game with a command like this:

Code: [Select]
!game01
Cost: 60 Points
/me @user@, you have spent @cost@ points to add 1 vote to Game01. You now have @points@ points. Game01 has @counter@ votes. @savefile@[C:\Google Drive\$voteGame01.txt,@counter@]

This system works really well but it has a flaw in that if viewers have enough points to vote multiple times, they are forced to enter the command many times in a row, spamming chat. I would like them to be able to enter something like:

Code: [Select]
!game01 @target@
@setcost@[60*@target@]
@setcounter@[@counter@+@target@]
/me @user@, you have spent (@cost@*@target@) points to add @target@ vote(s) to Game01. You now have @points@ points. Game01 has @counter@ votes. @savefile@[C:\Google Drive\$voteGame01.txt,@counter@]

In this implementation, when the command is parsed, @setcost@ is checked before anything else. If @setcost@ is specified then the default command cost is overridden and the value in @setcost@ is used instead.

Next, @setcounter@ is checked. If @setcounter@ is specified then the counter is modified by that instead of incrementing by 1.

Then the rest of the command plays out based on the newly modified cost and counter values. An Insufficient Points error will still be issued if the variable cost exceeds the user's total points; the command will not be executed.

This could also be useful for people trying to use the @counter@ variable as a special, command-unique stored number in other novel ways.

Marstead

  • Padawan
  • **
  • Posts: 51
  • Karma: +1/-0
    • View Profile
  • Twitch Name: Marstead
Re: [Custom Commands] @setcounter@[] & @setcost@[]
« Reply #1 on: June 16, 2016, 02:52:07 AM »
Saw this added to the Trello board so wanted to add one additional caveat, to catch a potential bug with this--if no @target@ is specified or an invalid @target@ (anything other than an integer) is specified the command should be executed as if the entered @target@ was 1, basically reverting to the existing command functionality.