-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Hi everyone,
I'm working on a Minecraft MakeCode (or Python) base protection script.
I'm having trouble getting the code to run correctly—especially with player functions and API compatibility.
If anyone has experience with Minecraft MakeCode or Python scripting for Minecraft, your help would be greatly appreciated!
This is my first time posting here. Thank you in advance!
(If helpful, here’s a snippet of my code and the errors I'm seeing:)
and here the code
CONFIGURATION
base_owner = "mahmoudA"
base_center = positions.create(0, 64, 0)
base_radius = 10
protection_active = True
def distance_sq(pos1, pos2):
dx = positions.get_x(pos1) - positions.get_x(pos2)
dy = positions.get_y(pos1) - positions.get_y(pos2)
dz = positions.get_z(pos1) - positions.get_z(pos2)
return dx * dx + dy * dy + dz * dz
def repel_player(p):
pos = player.position(p)
dx = positions.get_x(pos) - positions.get_x(base_center)
dz = positions.get_z(pos) - positions.get_z(base_center)
dist = (dx * dx + dz * dz) ** 0.5
if dist == 0:
dist = 0.01
new_x = positions.get_x(base_center) + (dx / dist) * (base_radius + 1)
new_z = positions.get_z(base_center) + (dz / dist) * (base_radius + 1)
new_y = positions.get_y(pos)
new_pos = positions.create(new_x, new_y, new_z)
player.teleport(p, new_pos)
player.say(p, "You are not allowed inside this base!")
def owner_buff(p):
player.say(p, "Welcome home, " + base_owner + "!")
player.give_item(p, DIAMOND_SWORD, 1)
def guard_base():
if not protection_active:
return
all_players = players.get_all()
for p in all_players:
pos = player.position(p)
dist = distance_sq(pos, base_center)
if player.name(p) == base_owner:
if dist < base_radius * base_radius:
owner_buff(p)
else:
if dist < base_radius * base_radius:
repel_player(p)
def run_guard_loop():
while True:
guard_base()
loops.pause(1000)
run_guard_loop() ]
Problems39
Line 8: can't find called function 'positions.get_x' 2
Line 8: module 'positions' has no attribute 'get_x' 2
Line 9: can't find called function 'positions.get_y' 2
Line 9: module 'positions' has no attribute 'get_y' 2
Line 10: can't find called function 'positions.get_z' 2
Line 10: module 'positions' has no attribute 'get_z' 2
Line 14: too many arguments in call to 'player.position'
Line 14: types not compatible: (_: number, _: number, : number) => Position and Position
Line 15: can't find called function 'positions.get_x' 2
Line 15: module 'positions' has no attribute 'get_x' 2
Line 16: can't find called function 'positions.get_z' 2
Line 16: module 'positions' has no attribute 'get_z' 2
Line 20: can't find called function 'positions.get_x'
Line 20: module 'positions' has no attribute 'get_x'
Line 21: can't find called function 'positions.get_z'
Line 21: module 'positions' has no attribute 'get_z'
Line 22: can't find called function 'positions.get_y'
Line 22: module 'positions' has no attribute 'get_y'
Line 24: too many arguments in call to 'player.teleport'
Line 25: too many arguments in call to 'player.say'
Line 28: too many arguments in call to 'player.say'
Line 29: can't find called function 'player.give_item'
Line 29: module 'player' has no attribute 'give_item'
Line 34: can't find called function 'players.get_all'
Line 34: name 'players' is not defined
Line 34: unknown object type; cannot lookup attribute 'get_all'
Line 36: too many arguments in call to 'player.position'
Line 36: types not compatible: (: number, _: number, _: number) => Position and Position
Line 38: too many arguments in call to 'player.name'
I am trying to fix it with ai because I don't know how to code
any comment would help!