Counting command


#1

PhantomBot Version: 2.4.2 (Revision: 5c75a7b2)
OS Version: Windows 10
Java Version: 1.8.0_191-b12
Browser and Version (for Panel Support):
Stock PhantomBot: Yes/No (Yes if you have not modified the scripts or Java Core)

I want to make a custom command which will work like this:
Caster: !paczka 10
User !paczka
Bot: I got 10 paczka
Caster: !paczka 6
User: !paczka
Bot: I got 6 paczka

I got it on Moobot and it uses ther command Arg - so admin can change that arg, but user can only see hwats the Arg value


#2

Two options. Either you can repurpose the death counter module, alias the commands and rewrite the lang file. It’s much easier than it sounds.

Alternatively:
!addcom set-paczka (writefile paczka.txt, false, (echo))

This will take whatever you put after !set-paczka and put it on the first line in the file paczka.txt in the addons file. This will always replace the first line if you use false, true will add a new line each time.

Then: !addcom paczka I got (readfile paczka.txt) paczka will return that line with the contents of the file in the brackets.


#3

!addcom paczka (runcode if(event.getArgs()[0] !== undefined && $.isAdmin(event.getSender().toLowerCase()) && !isNaN(parseInt(event.getArgs()[0]))) { $.inidb.set('paczka', 'paczka_count', parseInt(event.getArgs()[0])); } else { $.say('I got ' + $.inidb.get('paczka', 'paczka_count') + ' paczka'); })

Usage:

Admins can do !paczka # where # is a number.

Everyone else doing the command will get the response “I got # paczka”.

If the command is ran without an admin doing !paczka # it will say you have null paczka.


#4

ok, i like the way file text file, gonna try it on weekend. Thx man


#5

Where do i put this part from !addcom ?
im totally neewbie in programming.
Do i have to make another .js file ? or add this in existing one ? (guess it have to be comands.js)


#6

Just copy and paste whole message (this is a single line) to your chat.


#7

Thx man :slight_smile:
And after i copy/paste it it will add a comand in .js file ?


#8

No. You can see this command in a usual Custom Commands tab in your PhantomBot Panel. This command just uses tag (runcode). Everything you do via your chat doesn’t modifies any script in your bot.


#9

i put this into chat - Chatty exaclly - and it says copmmand has been created.
But when i put !paczka into chat - nothing happend


#10

When you run the command can you please show me the output in the console? If runCode fails it outputs an error in the console.


#11

ok i got it. After pasting in chat !addom i got this
[ERROR] [init.s:317] (hook.call, command, . /commands/customCommands.js) TypeError: Cannot find default value object.


#12

Did you run !paczka # where # is a number?

I said that it wouldn’t work correctly unless you did that first


#13

Error from above occurred when i paste the !addcom, not when i write !paczka


#14

Add that command via your Panel, what’s the problem?


#15

Solved


closed #16

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