#TypeError not a function

1 messages · Page 1 of 1 (latest)

olive socket
#

What version of the script APIs are you using in the manifest.json?

crystal steeple
#
{
  "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" ]
}
crystal steeple
night echo
#

How is bot defined?

crystal steeple
crystal steeple
night echo
crystal steeple
#
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()

night echo
#

hmm, bot is the simulated player, correct?

crystal steeple
#

yeah

night echo
#

how are you running that function?

#

normalBot I mean

crystal steeple
#

calling it in the afterEvents.playerSpawn event

night echo
#

hm, that’s really interesting

olive socket
night echo
crystal steeple
#

ooh let me try changing how I call the function to when I spawn the simulatedPlayer

night echo
#

That should work

crystal steeple
#

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

crystal steeple
night echo
#

huh

crystal steeple
#

not a clue ¯_(ツ)_/¯

snow jayBOT
#
Debug Result

There is an error in this [code](#1223434091030904996 message):

<repl>.js:51:23 - error TS18046: 'e' is of type 'unknown'.

51       console.warn(e, e.stack)
                         ~