Skip to content

Commit

Permalink
Update v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RattlesHyper committed Jul 27, 2023
1 parent 57d88ec commit 9d60e3a
Show file tree
Hide file tree
Showing 8 changed files with 667 additions and 631 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ TrafficerMC has a variety of features. Some of them are:
- Auto Reconnect
- and way more!

#### Minecraft Version 1.8.x - 1.20

## Media

![](https://media.discordapp.net/attachments/1101173583956422736/1105880170751078400/image.png)
Expand All @@ -42,7 +44,7 @@ TrafficerMC v2.1
TrafficerMC v0.4

# Scripting
Scripting can allow the bot to do things automatically without any user input. It can also help if you are making multiple bots do the same things. To make a script, you would need to go into a text file editor, and apon finishing the script, you save it as a `.txt` file. You can name it anything. Scripts will run after the bot has spawned in.
Scripting can allow the bot to do things automatically without any user input. It can also help if you are making multiple bots do the same things.

## What a script would look like
```
Expand Down Expand Up @@ -142,7 +144,7 @@ delay 1200
chat Hello
```
# Account File
Account filing connects the bots with certain names that aren't set in General tab. It can be useful if you want to bot a server with NameMC names, for example. To make a account file, you would need to go into a text file editor, and apon entering all the usernames, you save it as a `.txt` file. You can name it anything. **Please note that you will still need to set the Max Accounts in General Tab for the bots to join!**
Account filing connects the bots with certain names that aren't set in General tab. It can be useful if you want to bot a server with NameMC names, for example. To make a account file, you would need to go into a text file editor, and apon entering all the usernames, you save it as a `.txt` file. You can name it anything. **Please note that you can set Max Accounts in General Tab or it will use all the names**
## What an account file would look like
```
vampers
Expand Down
7 changes: 7 additions & 0 deletions assets/icons/app/clipboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 52 additions & 43 deletions assets/js/botMain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ipcRenderer, shell } = require("electron")
const { connectBot, delay, salt, addPlayer, rmPlayer, errBot, botApi, sendLog, exeAll, checkVer, startScript, mineflayer, loadTheme, createPopup, formatText } = require( __dirname + '/assets/js/cf.js')
const { connectBot, delay, salt, addPlayer, rmPlayer, errBot, botApi, sendLog, exeAll, checkVer, startScript, mineflayer, loadTheme, createPopup, formatText, selectedList } = require( __dirname + '/assets/js/cf.js')
const antiafk = require( __dirname + '/assets/plugins/antiafk')
process.NODE_TLS_REJECT_UNAUTHORIZED = "0"
let currentTime = Date.now()
Expand Down Expand Up @@ -78,6 +78,10 @@ let idTmob = document.getElementById('kaTm')
let idTanimal = document.getElementById('kaTa')
let idKaToggle = document.getElementById('toggleka')
let idKaLook = document.getElementById('toggleKaLook')
let idAutoSelect = document.getElementById('toggleAutoSelect')
let idCheckOnRespawn = document.getElementById('scriptCheckOnRespawn')
let idCheckOnDeath = document.getElementById('scriptCheckOnDeath')
let idCheckIgnoreFriends = document.getElementById('checkKaIgnoreSelected')

//button listeners
window.addEventListener('DOMContentLoaded', () => {
Expand All @@ -98,7 +102,13 @@ window.addEventListener('DOMContentLoaded', () => {
idBtnLookAt.addEventListener('click', () => {exeAll("look", idLookValue.value)})
idCheckSprint.addEventListener('click', () => {exeAll("sprintcheck", idCheckSprint.checked)})
idBtnDrop.addEventListener('click', () => {exeAll("drop", idDropValue.value)})
idBtnStartScript.addEventListener('click', () => {exeAll('startscript')})
idBtnStartScript.addEventListener('click', () => {
const list = selectedList()
if(list.length === 0) return createPopup("No bot selected")
list.forEach(name => {
startScript(name, idScriptPath.value)
});
})
idStartAfk.addEventListener('click', () => {exeAll('afkon')})
idStopAfk.addEventListener('click', () => {exeAll('afkoff')})
idBtnC.addEventListener('click', () => {saveData(); window.close()})
Expand All @@ -120,7 +130,7 @@ window.addEventListener('DOMContentLoaded', () => {
})


async function newBot(options) {
function newBot(options) {
const bot = mineflayer.createBot(options)
let afkLoaded = false

Expand All @@ -130,7 +140,7 @@ async function newBot(options) {
bot.once('spawn', ()=> {
botApi.emit("spawn", bot.username)
if(idJoinMessage) {bot.chat(idJoinMessage.value)}
if(idScriptCheck.checked && idScriptPath.value) { startScript(bot.username, idScriptPath.files[0].path)}
if(idScriptCheck.checked && idScriptPath.value) { startScript(bot.username, idScriptPath.value)}
});
bot.once('kicked', (reason)=> {
botApi.emit("kicked", options.username, reason)
Expand All @@ -157,31 +167,18 @@ async function newBot(options) {
});

bot.on('windowOpen', (window) => {
idWindow.innerHTML = ""
idWindowTitle.innerHTML = formatText(JSON.parse(window.title))
for (var i = 0; i < window.slots.length; i++) {
const item = window.slots[i]
let dname = ""
if (item) {
if (item.nbt.value.display.value.Name.value) {
displayname = JSON.parse(item.nbt.value.display.value.Name.value)

if (displayname.extra) {
var ext = displayname.extra
ext.forEach(e => {
dname += formatText(e)
});
} else {
dname += formatText(displayname)
}
}
const b = document.createElement("li")
b.innerHTML = `<span style="font-weight: bold;">${i}</span> ${dname} <span style="font-weight: bold;">${item.count}x</span>`
idWindow.appendChild(b)
}
}
sendLog(`[${bot.username}] Window opened`)
})
bot.on('death', function() {
botApi.emit('death', options.username)
bot.once('respawn', function() {
if(idCheckOnDeath.checked && idScriptPath.value) { startScript(bot.username, idScriptPath.value)}
})
})
bot.on('respawn', function() {
botApi.emit('respawn', options.username)
if(idCheckOnRespawn.checked && idScriptPath.value) { startScript(bot.username, idScriptPath.value)}
})

botApi.once(options.username+'disconnect', () => {bot.quit()})
botApi.once(options.username+'reconnect', () => {newBot(options)})
Expand All @@ -193,7 +190,7 @@ async function newBot(options) {
botApi.on(options.username+'stopcontrol', (o) => {bot.setControlState(o, false)})
botApi.on(options.username+'look', (o) => {bot.look(o, 0)})
botApi.on(options.username+'sprintcheck', (o) => {bot.setControlState('sprint', o)})
botApi.on(options.username+'startscript', () => {startScript(bot.username, idScriptPath.files[0].path)})
botApi.on(options.username+'startscript', () => {startScript(bot.username, idScriptPath.value)})

botApi.on(options.username+'afkon', () => {
if(!afkLoaded) {
Expand Down Expand Up @@ -242,6 +239,7 @@ async function newBot(options) {
} else {
bot.attack(entity);
}
sendLog(`<li> <img src="./assets/icons/app/code.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(28%) sepia(100%) saturate(359%) hue-rotate(172deg) brightness(93%) contrast(89%)"> [hit] ${entity.displayName ? entity.displayName : "Unknown Entity"} </li>`)
}
if (entity.kind === "Passive mobs" && idTanimal.checked) {
if (idKaLook.checked) {
Expand All @@ -250,6 +248,7 @@ async function newBot(options) {
} else {
bot.attack(entity);
}
sendLog(`<li> <img src="./assets/icons/app/code.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(28%) sepia(100%) saturate(359%) hue-rotate(172deg) brightness(93%) contrast(89%)"> [hit] ${entity.displayName ? entity.displayName : "Unknown Entity"} </li>`)
}
if (entity.kind === "Vehicles" && idTvehicle.checked) {
if (idKaLook.checked) {
Expand All @@ -258,14 +257,18 @@ async function newBot(options) {
} else {
bot.attack(entity);
}
sendLog(`<li> <img src="./assets/icons/app/code.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(28%) sepia(100%) saturate(359%) hue-rotate(172deg) brightness(93%) contrast(89%)"> [hit] ${entity.displayName ? entity.displayName : "Unknown Entity"} </li>`)
}
if (entity.type === "player" && entity.username !== bot.username && idTplayer.checked) {
const list = selectedList()
if(list.includes(entity.username) && idCheckIgnoreFriends.checked) return;
if (idKaLook.checked) {
bot.lookAt(entity.position, true);
bot.attack(entity);
} else {
bot.attack(entity);
}
sendLog(`<li> <img src="./assets/icons/app/code.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(28%) sepia(100%) saturate(359%) hue-rotate(172deg) brightness(93%) contrast(89%)"> [hit] ${entity.username} </li>`)
}
}
});
Expand All @@ -290,33 +293,36 @@ botApi.on("login", (name)=> {
addPlayer(name)
sendLog(`<li> <img src="./assets/icons/app/arrow-right.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(68%) sepia(74%) saturate(5439%) hue-rotate(86deg) brightness(128%) contrast(114%)"> ${name} Logged in.</li>`)
if(idConnectSound.checked === true) {
var audio = new Audio( __dirname + '/assets/audios/connected.mp3');
audio.play();
playAudio("connected.mp3")
}
})
botApi.on("spawn", (name)=> {
sendLog(`<li> <img src="./assets/icons/app/arrow-right.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(26%) sepia(94%) saturate(5963%) hue-rotate(74deg) brightness(96%) contrast(101%)"> ${name} Spawned.</li>`)
})
botApi.on("kicked", (name, reason)=> {
rmPlayer(name)
sendLog(`<li> <img src="./assets/icons/app/arrow-left.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(11%) sepia(92%) saturate(6480%) hue-rotate(360deg) brightness(103%) contrast(113%)"> [${name}] : ${formatText(JSON.parse(reason))}</li>`)
})
botApi.on("end", (name, reason)=> {
rmPlayer(name)
sendLog(`<li> <img src="./assets/icons/app/alert-triangle.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(100%) sepia(61%) saturate(4355%) hue-rotate(357deg) brightness(104%) contrast(104%)"> [${name}] ${reason}</li>`)
if(idDiconnectSound.checked === true) {
var audio = new Audio( __dirname + '/assets/audios/disconnected.wav');
audio.play();
playAudio("")
}
})
botApi.on("error", (name, err)=> {
errBot(name)
sendLog(`<li> <img src="./assets/icons/app/alert-triangle.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(89%) sepia(82%) saturate(799%) hue-rotate(1deg) brightness(103%) contrast(102%)"> [${name}] ${err}</li>`)
if(idErrorSound.checked === true) {
var audio = new Audio( __dirname + '/assets/audios/error.wav');
audio.play();
playAudio("error.wav")
}
})
botApi.on("spawn", (name)=> {
sendLog(`<li> <img src="./assets/icons/app/arrow-right.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(26%) sepia(94%) saturate(5963%) hue-rotate(74deg) brightness(96%) contrast(101%)"> ${name} Spawned.</li>`)
})
botApi.on("death", (name)=> {
sendLog(`<li> <img src="./assets/icons/app/arrow-right.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(26%) sepia(94%) saturate(5963%) hue-rotate(74deg) brightness(96%) contrast(101%)"> ${name} Died.</li>`)
})
botApi.on("respawn", (name)=> {
sendLog(`<li> <img src="./assets/icons/app/arrow-right.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(26%) sepia(94%) saturate(5963%) hue-rotate(74deg) brightness(96%) contrast(101%)"> ${name} Respawned.</li>`)
})
botApi.on("kicked", (name, reason)=> {
rmPlayer(name)
sendLog(`<li> <img src="./assets/icons/app/arrow-left.svg" class="icon-sm" style="filter: brightness(0) saturate(100%) invert(11%) sepia(92%) saturate(6480%) hue-rotate(360deg) brightness(103%) contrast(113%)"> [${name}] : ${formatText(JSON.parse(reason))}</li>`)
})

// uptime counter
idBtnStart.addEventListener('click', () => {
Expand All @@ -341,7 +347,9 @@ function formatTime(time) {
if (10 > time) return "0" + time;
return time;
}

function playAudio(filename) {
new Audio( __dirname + `./assets/audios/${filename}`).play();
}
// save and restore config
ipcRenderer.on('restore', (event, data) => {
Object.keys(data).forEach(v => {
Expand All @@ -359,7 +367,8 @@ function saveData() {
"botversion": document.getElementById('botversion').value,
"botCount": document.getElementById('botCount').value,
"joinDelay": document.getElementById('joinDelay').value,
"joinMessage": document.getElementById('joinMessage').value
"joinMessage": document.getElementById('joinMessage').value,
'scriptPath': document.getElementById('scriptPath').value
}))
}

Expand Down
Loading

0 comments on commit 9d60e3a

Please sign in to comment.