In the browser, you import yolkbot using either:
<script type="module"> tags)window.yolkbot) (Tampermonkey)Dynamic import is the preferred method of importing yolkbot in the browser. It allows you to import only the parts you need, and it works with modern browsers.
let { Bot } = await import('https://esm.sh/yolkbot@latest/browser');
let { Dispatches: { ChatDispatch, SpawnDispatch } } = await import('https://esm.sh/yolkbot@latest/browser');
This must be placed in a <script type="module"> tag in your HTML file, like so:
<script type="module">
let { Bot, Dispatches: { SpawnDispatch } } = await import('https://esm.sh/yolkbot@latest/browser');
let bot = new Bot();
bot.on('gameReady', () => {
bot.dispatch(new SpawnDispatch());
});
bot.join('my bot name', 'game-code-here');
</script>
If you want to use yolkbot in a global context, you can import it using a <script> tag. This will make yolkbot available globally as window.yolkbot.
<script src="http://raw.yolkbot.xyz/browser/build/global.js"></script>
<script>
let bot = new window.yolkbot.Bot();
bot.on('gameReady', () => {
bot.dispatch(new window.yolkbot.Dispatches.SpawnDispatch());
});
bot.join('my bot name', 'game-code-here');
</script>
To use the Global Import in Tampermonkey, you can use the @require directive in your Tampermonkey script:
// ==UserScript==
// @name My Yolkbot Script
// @description A script that uses yolkbot
// @author You
// @require http://raw.yolkbot.xyz/browser/build/module.js
These are all the things that can be imported.
let {
Bot, // the Bot class
GamePlayer, // represents an empty bot.player object, only useful for typing
Matchmaker, // the Matchmaker class
Dispatches, // the Dispatches object with each dispatch, use Dispatches.ChatDispatch
// or destructure dispatches!
Dispatches: {
ChatDispatch, // this would let you refer to ChatDispatch without the "Dispatches." prefix
SpawnDispatch // this would let you refer to SpawnDispatch without the "Dispatches." prefix
},
// you can do the same destructuring thing with all of the things like API, Comm, etc that are objects
API, // the API object with each API function, use API.loginAnonymously, API.loginWithCredentials, etc
Comm, // the Comm object with each comm class, use Comm.CommIn, Comm.CommOut, Comm.Code, etc
Packet, // the Packet object with each packet class, use Packet.BootPacket, Packet.ChatPacket, etc
Constants, // all of the constants, use Constants.IsBrowser, Constants.GunList, etc
Guns, // all of the guns: Eggk-47, Scrambler, etc
Items, // the item array
Maps // the map array
} = await import('https://esm.sh/yolkbot@latest/browser');
// or "= window.yolkbot" if using the global import
Browsers (& Tampermonkey) do not support proxies, so you will be unable to pass a proxy to a Bot.
In the browser, you import yolkbot using either:
<script type="module"> tags)window.yolkbot) (Tampermonkey)Dynamic import is the preferred method of importing yolkbot in the browser. It allows you to import only the parts you need, and it works with modern browsers.
let { Bot } = await import('https://esm.sh/yolkbot@latest/browser');
let { Dispatches: { ChatDispatch, SpawnDispatch } } = await import('https://esm.sh/yolkbot@latest/browser');
This must be placed in a <script type="module"> tag in your HTML file, like so:
<script type="module">
let { Bot, Dispatches: { SpawnDispatch } } = await import('https://esm.sh/yolkbot@latest/browser');
let bot = new Bot();
bot.on('gameReady', () => {
bot.dispatch(new SpawnDispatch());
});
bot.join('my bot name', 'game-code-here');
</script>
If you want to use yolkbot in a global context, you can import it using a <script> tag. This will make yolkbot available globally as window.yolkbot.
<script src="http://raw.yolkbot.xyz/browser/build/global.js"></script>
<script>
let bot = new window.yolkbot.Bot();
bot.on('gameReady', () => {
bot.dispatch(new window.yolkbot.Dispatches.SpawnDispatch());
});
bot.join('my bot name', 'game-code-here');
</script>
To use the Global Import in Tampermonkey, you can use the @require directive in your Tampermonkey script:
// ==UserScript==
// @name My Yolkbot Script
// @description A script that uses yolkbot
// @author You
// @require http://raw.yolkbot.xyz/browser/build/module.js
These are all the things that can be imported.
let {
Bot, // the Bot class
GamePlayer, // represents an empty bot.player object, only useful for typing
Matchmaker, // the Matchmaker class
Dispatches, // the Dispatches object with each dispatch, use Dispatches.ChatDispatch
// or destructure dispatches!
Dispatches: {
ChatDispatch, // this would let you refer to ChatDispatch without the "Dispatches." prefix
SpawnDispatch // this would let you refer to SpawnDispatch without the "Dispatches." prefix
},
// you can do the same destructuring thing with all of the things like API, Comm, etc that are objects
API, // the API object with each API function, use API.loginAnonymously, API.loginWithCredentials, etc
Comm, // the Comm object with each comm class, use Comm.CommIn, Comm.CommOut, Comm.Code, etc
Packet, // the Packet object with each packet class, use Packet.BootPacket, Packet.ChatPacket, etc
Constants, // all of the constants, use Constants.IsBrowser, Constants.GunList, etc
Guns, // all of the guns: Eggk-47, Scrambler, etc
Items, // the item array
Maps // the map array
} = await import('https://esm.sh/yolkbot@latest/browser');
// or "= window.yolkbot" if using the global import
Browsers (& Tampermonkey) do not support proxies, so you will be unable to pass a proxy to a Bot.