Looking to Read Random Line to change a Text File


#1

So far, this is what I’ve got:

(readfilerand ./bossatk.txt)

That will read from a Text File that says this:

(@sender) attacks for (# 1,10000 (writefile bosshp.txt, false, (echo)) Damage!

…but I’m only getting a response from the Bot that says the User attacks for X Damage. It’s reading the text file, but inside the text file, there’s a command to writefile of bosshp.txt. That part doesn’t seem to be working. I’m not even sure if I’ve got the command right…

The BossHP.txt file basically starts at 1400000. I want to subtract from that number based on the number generated from the command above, then save the file. What would that command look like…?


#2

What you’re trying to achieve here is too complex for a basic command.

Commands are parsed using if/else statements in a “chain” so to speak. The code goes through each statement looking for specific tags in an order (I don’t know the order I just know there is one).

So, if “(readfilerand)” is after “(writefile)”, that means you won’t be able to use the two together without running writefile first, and that wouldn’t give you the results your after.

Truth be told, this seems like a really easy custom script to write though. Perhaps if you explained (in detail) what all you want accomplished I could look into getting something setup for you.


#4

Thanks a ton.

I basically have a command on PhantomBot that says !bossatk that reads from a Text File called bossatk.txt

Then I have a text file called bosshp.txt with the number 1800000 and a second text file called viewerhp.txt at 98000. Neither of these numbers can exceed these two values.

Basically, when a User attacks, I need the command to either say that the User has attacked for (#1,10000) Damage, or the user was countered for (#1,10000) Damage. Whether they Attack or whether they are countered, that’s random. If the User attacks, then the number is subtracted from bosshp.txt. If the User is countered, then that number is reduced from viewerhp.txt, then saves the file.

Finally, I have a !bossrstr command that will choose a number from (#1,10000) and add the resulting number to viewerhp.txt and save the file (notifying the User how much was restored)


#5

With the use of a script I don’t think bossatk.txt will be needed as that’ll be controlled by the script.

What I’m thinking here is this:

On the first bot startup, the bot will create two variables in the database. One for the viewer’s HP, and one for the Boss’s HP. These values will also be saved to their appropriate text files.

Then when users do !bossatk they get about a 50/50 shot at attacking or being attacked by the boss (for 1-10000 dmg randomly). This will also update the appropriate text file.

Admins may do !bossatk reset which will set BOTH the boss’s HP and the Viewer’s HP back to default.

If a user does !bossrstr, the Viewer HP goes back up a random number between 1-10000.

Does this sound like what you’re after?


#6

Right on the nose. :slight_smile:


#7

Alright, I’ve finished writing the script. It should be what you want but note that it is untested.

For this script to work, you must place it in /scripts/custom/commands/bossAtkCommand.js – you may have to create the sub-folders.

It is highly recommended that you create a backup before you run this (nothing should break but in case it does). You should also shut off your bot before you add the script in, and restart after it’s in place.

bossAtkCommand.js (4.3 KB)
^^ Click the above text to download it

If you get errors/issues let me know.


#8

Awesome! Thanks for the help. I’ll change some of the chat responses around and give it a try and let you know if it works.


#9

Err, I missed one. Where would I add a value if I want to include the following:

User attacks, but the attack was absorbed for X! (X Health was restored to Boss HP)


#10

The code I included doesn’t have anything to restore boss HP.

You’d have to add it somewhere in the attackUser function though.


#11

Okay, so is this pretty easy to enable in the Control Panel? I’m still figuring the Bot out.


#12

It should be enabled by default, but if it isn’t you can go in the control panel, click the dashboard panel. Then click “Twitch Modules”, and finally look for ./custom/commands/bossAtkCommand.js in the list (you can use ctrl + f to save time)


#13

Hmm, I double checked the chat command I’m supposed to use in the .js file and the directory where the js file is supposed to be, but typing on Twitch Chat doesn’t seem to work. I can confirm the bot is working on my channel though.


#14

:S it’s working on my end:

img

Are you sure it’s placed in the correct folder? Are there any errors in the bot’s console?


#15

Maybe it just doesn’t let the streamer type the command. If I try typing it into my channel, I don’t get a response.

The directory I put it in is

C:\Users\Aaron\Documents\PhantomBot\scripts\custom\commands


#16

It should, my picture shows me (the streamer) typing the command.

Restart your bot and watch all the text that appears. Specifically when it’s loading all the modules.

Try and see if you can find the line that looks like this:


#17

Oh, I see what’s going on. There’s a launch program in the main folder that I have to turn on first, but it’s giving me this:

[12-03-2017 @ 18:29:00.881 GMT] [ERROR] oAuth token doesn’t match the bot’s Twitch account name.
[12-03-2017 @ 18:29:00.885 GMT] [ERROR] Please go to http://twitchapps.com/tmi and generate a new token.
[12-03-2017 @ 18:29:00.885 GMT] [ERROR] Be sure to go to twitch.tv and login as the bot before getting the token.
[12-03-2017 @ 18:29:00.885 GMT] [ERROR] After, open the botlogin.txt file and replace the oauth= value with the token.


#18

As the error states, your oauth token is incorrect.

In your browser, login as the bot on https://twitch.tv

Then go to http://twitchapps.com/tmi and generate a new OAUTH.

Next, open \PhantomBot\config\botlogin.txt and find the oauth= value. Replace everything after the equals sign with your new oauth.


#19

Yup, I just managed to fix it and can confirm the bot is working. I apologize for asking so much from you but could you please add one more field to that .js file?

I’m comfortable with changing things around as needed, but I don’t have a clue where to start with adding commands from a blank slate.

Basically, I need a 5 minute cooldown after a user types this and a command where if the user attacks, they have a chance of getting that attack absorbed (between 1-10,000), healing the Boss HP. (I apologize for missing this earlier)


#20

The cooldown can be configured by the bot (!coolcom does that).

So you want the !bossatk command to have a chance to heal the boss? Note that when I give you a new copy of the script you’ll have to make your changes again.


#21

Yes, I haven’t made any adjustments to the .js file yet. Thanks again :slight_smile: