Random Gif Alerts


#1

Is it possible to set up a command that executes a random gif alert, like pulling a line from a file? I would like to set up a !boo command that plays a different jumpscare/sound each time.


#2

I tried using !random for this and got the following error:

[ERROR] [init.js:319] (hook.call, command, ./games/random.js) TypeError: Cannot find function replaceFirst in object (alert boo.gif,11).


#3

!random already exists, so that will just cause a command conflict. If you still have a custom command called !random, then I’d delete it to prevent future errors.

To set the random gif, this should be possible since the last update, as the readfile variable will now parse variables within.


Having got all that out of the way, this is what you’ll need to do.

Get your gifs and sounds in MP3 format, each pair will need to have an identical name, case sensitive. Keep them to one word names, all lowercase.

Upload all these alerts to the ./config/alerts folder in your bot.

Create a text file, and add (alert alertname.gif), with each different alert on it’s own line. Save this text file to the addons folder in the bot.

You can now create your command, which will need to look like this: !addcom boo (readfilerand ./textfilename.txt). This will select a random line from the text file you created. As these are all simply gif commands, nothing will be printed in chat, but whichever line gets randomly selected will fire that gif alert.


EDIT (Because I forgot when originally writing this): To get these alerts to show up on your screen, you will need to point a browser source to localhost(or your server’s IP):baseport/alerts. For example: 127.0.0.1:25000/alerts


If you do want it to print something in chat, then you would need to add that line in the txt file, not the command itself. If you always want it to be the same, you’ll need to add it multiple times. Obviously for this sort of command you probably don’t want any advanced warning. If you do add text, put it before the (alert) text.


#4

Updated to 2.3.9 and I still get the error if I try and put a gif alert into a !random text line like so:

$.lang.register('randomcommand.1', '(alert boo.gif,2)');
$.lang.register('randomcommand.2', '(alert boo2.gif,2)');
$.lang.register('randomcommand.3', '(alert boo3.gif,4)');

I imagine you aren’t supposed so put gif alerts there.

So I moved on to using the readfierand as you suggested and it only reads the first line of the txt file (ignoring the other ten) and also ignores the seconds command. So instead of playing (alert boo.gif,2) for 2 seconds it loops it for more like 10.

The solution was to do away with the seconds command and then it reads it randomly like intended and works well enough for my purposes. Thank you for the help!


#5

Good to know it’s working. :slight_smile: No idea why it would be doing that with the time thing, didn’t actually know that was a thing, but yeah, if you don’t add any time specifier to it, then it will play the whole sound.