NightDev Community Forums

Custom SCP command

Usage:
!scp [Number]
or just
!scp

What it does:
This command allows you to do two things:

  • Quickly getting the link to a specific SCP article from the wiki by using the command together with the article’s number

  • Getting a link to a random SCP by not adding any arguments to the command (or if your argument is invalid)

Here is the code:

Edit: Improved code by RokettoJanpu:

$(eval z=4090;a=parseInt(decodeURIComponent(`$(querystring)`),10);a>0&&a<=z?(b=`Your desired SCP`,c=a):(b=`Random SCP`,c=Math.ceil(Math.random()*z));b+`: https://www.scp-wiki.net/scp-`+c.toString().padStart(3,`0`))

My original code:

$(eval randc = "Random SCP:"; if("$(query)" > 0 && "$(query)" < 4090){randc = "Your desired SCP:"} randc;) http://www.scp-wiki.net/scp-$(eval var out = ""; if("$(query)" > 0 && "$(query)" < 4090){out = "$(query)";} else{out = (Math.round(Math.random() * 4090))} if(out == 0){out = 1;} out2 = out; if(out < 100){out = "0" + out;} if(out2 < 10){out = "0" + out;} out;)

(It’s not very efficient or good-looking but it works nonetheless. Just know that I basically made this through trial and error.)

To add the command, just copy this and post it in your channel’s chat:

Spoiler

!commands add -cd=5 -ul=everyone !scp $(eval z=4090;a=parseInt(decodeURIComponent($(querystring)),10);a>0&&a<=z?(b=Your desired SCP,c=a):(b=Random SCP,c=Math.ceil(Math.random()*z));b+: https://www.scp-wiki.net/scp-+c.toString().padStart(3,0))

I set the highest available SCP number to 4090 because after that point the article numbers start being unused. If you want you can manually increase this number in the code once more SCPs have been added to the site.
Edit: Looking at the wiki right now, it actually seems like the first empty articles start appearing shortly after number 4150 so you may change it to this number right away. Although 60 more SCPs aren’t that big of a difference.

I’m proud I got this to work out how I wanted it to, considering I barely have any coding experience, and I wanted to share it here in case someone else could find it useful too.

I’m also open for tips on how to improve the code or add extra functionality.
For example, I think it would be cool if it also posted the “nickname” of the article along with the link or maybe even the first sentence of the description. But this is definitely too complicated for me. Maybe some of you here could get it to work though.

Anyways, have a nice day

Nicely done! Your code does the job just fine. I’ve posted a revision below that more efficiently deals with the leading zeros when the input number is less than 3 digits long.

$(eval z=4090;a=parseInt(decodeURIComponent(`$(querystring)`),10);a>0&&a<=z?(b=`Your desired`,c=a):(b=`Random`,c=Math.ceil(Math.random()*z));b+` SCP: https://www.scp-wiki.net/scp-`+c.toString().padStart(3,`0`))

For anyone curious how to change the upper search limit, note this line in the code:

z=4090;

When more SCP articles are published, feel free to change this number as you see fit.

Thank you for the improvement!

Also, mind if I ask how to put text into one line with a scroll bar like you did in your comment? I can’t figure out how to make that in this text editor ^^`

This forum uses Markdown to provide options for formatting posts. To format my code, I put three backticks above and below the code like so:

image

Resulting in:

// some code here...

Thanks, that’s good to know.
When I make another post here I’ll definitely make use of that.