Slightly More Advanced !fight Command

Hiya!

I’ve been messing about trying to get something working but I’m not exactly well-versed in coding really anything. When I look at examples I can get an idea of what the command is and what the code does in reference to the elements it contains but I’m still not able to piece things together for this particular command. I created a basic !fight command but I’m not particularly happy with it.

I want to be able to target a user (if no target obviously just default to the sender) for a variable amount of “damage”, where

1.) A random variable response (something like “$(user) targets $(touser) for”,“You hit $(touser) with”,"$(user) smacks $(touser) for")

2.) A random variable numerical value (1-9500, where anything greater than 9000 yields the response “It’s over 9000!” and anything less than 1000 yields the response “It’s not very effective.” at the end of the entire response, anything in between yields no additional text)

3.) A random variable response (something like “points of damage.”,“Health points.”,“Magicka damage.”)

come together to yield a random response (examples):
@Marylande targets @Nightbot for 866 points of Magicka damage. It’s not very effective.
@Marylande smacks @Nightbot for 6820 points of damage.”

I’m so sorry if this seems simple and I’m just spacing it. Any help with this construction would be so much appreciated.

@Marylande Heya, welcome to the community. Try this, hope this is what you want.

!addcom -cd=5 !fight $(eval 
responses = [`health points.`, `points of Magicka damage.`, `points of damage.`]; 
randrespons = responses[Math.floor(Math.random() * responses.length)]; 

subresp = [`@$(user) targets @$(touser) for `, `You hit @$(touser) with `, `@$(user) smacks @$(touser) for `];
randsubresp = subresp[Math.floor(Math.random() * subresp.length)]; 

random = (Math.floor(Math.random() * 9500) + 1); 

if ( random > 9000 ) { 
   message = `It’s over 9000!` 
} else if ( random < 1000 ) { 
   message = `It’s not very effective.` 
} else { 
   message = " " 
} 
randsubresp + " " + random + " " + randrespons + " " + message
)

Recommending you to use Pastebin, and then apply $(urlfetch) variable. As on YouTube, it is not possible to add this command from Live Chat.

Ignore my spelling and grammar. :)

Edit:
Usage:

Ritik: !fight Nightbot
Nightbot: @Ritik targets @Nightbot for 3635 health points.

@Ritik_Ranjan Heya thanks so much for your reply! I tried doing what you said but I could totally be doing this all wrong with no direction at all. I’m not sure. I did !addcom !placeholder $(urlfetch insertlinkitwouldntletmehere) and received the response [Response must be less than 400 characters]. I’m doing this from Discord.

@Marylande Hmm… this type of ERROR I was expecting. Anyways, type this in the chat. It will work

!addcom -cd=5 !fight $(eval subresp = [`@$(user) targets @$(touser) for `, `You hit @$(touser) with `, `@$(user) smacks @$(touser) for `]; $(urlfetch json https://pastebin.com/raw/peP6wkhF))

By the way, if you are using it in Discord then to ping someone use <@$(userid)> instead of @$(user)

1 Like

Ah thank you so much for all of your help! I added some responses to the command and it works so wonderfully! Thanks so much! <3 <3

@Ritik_Ranjan Do you happen to know if there is a way to add logic to this to allow the query to be unmentionable?

As in, if I say
“!fight @Marylande

Nightbot says
“Marylande kicks Marylande for 2611 points of Health damage.”

without pinging the target? I’ve tried $(query) but that seems to just copy the same text and in Discord it auto pings anyway with the @Marylande in front of it. I’m wondering if there’s a way to remove the @ character before its response.

@Marylande Heya, sorry, I don’t know how to do that :’(
Me too use Nightbot in my DC server but it is only for show. I am poor in Discord integration.

Hey @Marylande and @Ritik_Ranjan!

To remove the @ either use $(eval `$(query)`.replace(`@`,``)), or if it’s the first argument, use $(touser), it’ll automatically remove the @.

Awh no way! You’ve helped me so much thank you! <3

@Emily Thank you for your time, I don’t think that using $(touser) variable will help in Discord especially.

Suppose, there is a command !hi

Ritik: !hi @TestUser#0000
Nightbot: Hi @TestUser

And that TestUser will be pinged, even tho you are using the $(touser) variable. :|

Edit: Also, $(eval `$(query)`.replace(`@`,``)) will not help. Because it would return the <!UserID> in Discord

Oh right, it’s on Discord, I forgot about that, my bad, I don’t have a solution then as I’m unsure how to get the username with Nightbot when it comes from Discord… :thinking:

Do you know if there’s a way for Nightbot to read the targetid and remove @ before posting? I’m not sure what Nightbot sees exactly with our statements. Lol.

On Discord, Nightbot sees <@!USER_ID>, with USER_ID being a big number, and it’s not possible to get the username without @mentioning the user as far as I know, it’s possible with some bots specifically made for Discord tho’, but Nightbot isn’t one of them, unless I’m not aware of a functionality that’s not detailed in the documentation.

1 Like

Ohhhh okay that makes a lot of sense. So Nightbot is essentially just responding back exactly the userid just as it’s input and then Discord is changing the appearance based on the intended tag. Even if you were to add some kind of logic to recognize when there’s an @ and remove it before posting it would still just send off a string of numbers and Discord wouldn’t change it to text because of it missing an essential part of how tagging actually works. Silly Discord. :rofl:

Thank you so much for all of your help! I appreciate it! :heart:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.