#TypeError not a function
1 messages · Page 1 of 1 (latest)
{
"format_version": 2,
"header": {
"name": "§bCosmic Simulator Pack",
"description": "§aCosmic Simulator §cV1.09 \n§6Custom PvP Bots",
"uuid": "584d55ee-a5f8-4814-b890-9c8140ad0530",
"version": [ 1, 0, 9 ],
"min_engine_version": [ 1, 14, 0 ]
},
"modules": [
{
"description": "§aCosmic Simulator §cV1.09",
"type": "data",
"uuid": "7a939fcc-a22d-471b-a8ee-084ee03f05b0",
"version": [ 1, 0, 0 ]
},
{
"description": "Cosmic API",
"language": "javascript",
"type": "script",
"uuid": "d578d424-2103-4184-bdd6-dcfcb38db11b",
"version": [0, 0, 1],
"entry": "main/index.js"
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.10.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.2.0-beta"
},
{
"module_name": "@minecraft/server-gametest",
"version": "1.0.0-beta"
},
{
"module_name": "@minecraft/common",
"version": "1.1.0"
}
],
"capabilities": [ "script_eval" ]
}
all betas besides the @minecraft/common module
How is bot defined?
its an argument within in a function; function is called on afterEvents.playerSpawn, the bot has a specific name which is how I grab it
Mind showing that part?
which part, the playerSpawn?
The part that’s not working for you
import { SimulatedPlayer, register } from '@minecraft/server-gametest'
import { BlockPermutation, GameMode, ItemStack, Player, Vector, system, world } from '@minecraft/server'
/**
*
* @param {SimulatedPlayer} bot the bot
*/
export function normalBot(bot){
const run = system.runInterval(() => {
try {
if(!bot.isValid()){
system.clearRun(run)
return
}
const player = world.getPlayers({scoreOptions: [{objective: 'pvp_bot', minScore: 1}]})[0]
const {x: px,y: py,z: pz} = player.location
const {x: bx,y: by,z: bz} = bot.location
const dx = px - bx;
const dz = pz - bz;
const dy = (py + 1) - (by + 1);
const distance = Math.sqrt(dx**2 + dz**2);
let move = false;
//target is player and player is bot
const angleRadians = Math.atan2(dz, dx) - Math.PI / 2;
const deltaXZ = Math.sqrt((px - bx) ** 2 + (pz - bz) ** 2);
let vertAngle = -1 * Math.atan2(dy, deltaXZ) * (180 / Math.PI);
let angleDegrees = angleRadians * (180 / Math.PI);
if (angleDegrees < 0) {
angleDegrees += 360;
}
// bot.lookAtEntity(player)
bot.setRotation({x: vertAngle, y: angleDegrees})
bot.nameTag = `${bot.name}\n${bot.getComponent('minecraft:health').currentValue}`
if(distance > 5){
bot.isSprinting = true
bot.jump()
}
if(distance < 5){
bot.attack()
}
if(distance > 2){
move = true
player.isSprinting ? bot.isSprinting = true : bot.isSprinting = false
player.isSprinting && player.isJumping ? bot.jump() : null
}else move = false
bot.moveRelative(0,move ? 1 : 0,1)
} catch (e) {
console.warn(e, e.stack)
}
})
}
its the part thats just bot.attack()
hmm, bot is the simulated player, correct?
yeah
calling it in the afterEvents.playerSpawn event
hm, that’s really interesting
I don't know if the playerSpawn event will give you a SimulatedPlayer object. Why don't you use the Simulated Player when you create it?
oh wait, pretty sure the player property on playerSpawn returns Player and not the SimulatedPlayer class
Yeah ^^
ooh let me try changing how I call the function to when I spawn the simulatedPlayer
That should work
yeah Ill check in a sec, but on my other pack that I was testing the bot I was grabbing the object from the playerSpawn event and it worked fine so not sure why it wouldnt work fine now
Nope calling it when the bot is created doesnt help. Same error happens
huh
not a clue ¯_(ツ)_/¯
There is an error in this [code](#1223434091030904996 message):
[36m<repl>.js[0m:[33m51[0m:[33m23[0m - [31merror[0m[30m TS18046: [0m'e' is of type 'unknown'.
[7m51[0m console.warn(e, e.stack)
[7m [0m [31m ~[0m