Player Functions

SquidScript Player Functions

We have a wide variety of built-in functions for accessing and setting data for the player in Minecraft.

Player Position

Get

lua
-- Getting player position
local position = mc.player.getPosition()
if position ~= nil then
    print("Player Position: X=" .. position[1] .. ", Y=" .. position[2] .. ", Z=" .. position[3])
else
    print("Player not found.")
end

Set

lua
-- Set player position
mc.player.setPosition(100, 64, 100)
print("Player position set to X=100, Y=64, Z=100")

Player Health

Get

lua
-- Get player health
local health = mc.player.getHealth()
if health ~= nil then
    print("Player Health: " .. health)
else
    print("Player not found.")
end

Player Name

lua
-- Get player name
local name = mc.player.getName()
if name ~= nil then
    print("Player Name: " .. name)
else
    print("Player not found.")
end

Player UUID

lua
-- Get player UUID
local uuid = mc.player.getUUID()
if uuid ~= nil then
    print("Player UUID: " .. uuid)
else
    print("Player not found.")
end

Player Gamemode

Get

lua
-- Get player gamemode
local gamemode = mc.player.getGamemode()
if gamemode ~= nil then
    print("Player Gamemode: " .. gamemode)
else
    print("Player not found.")
end

Set

lua
-- Set player gamemode to creative
mc.player.setGamemode("creative")
print("Player gamemode set to creative")

Player XP

lua
-- Get player XP
local xp = mc.player.getXP()
if xp ~= nil then
    print("Player XP: " .. xp)
else
    print("Player not found.")
end

Player Saturation

Get

lua
-- Get player saturation
local saturation = mc.player.getSaturation()
if saturation ~= nil then
    print("Player Saturation: " .. saturation)
else
    print("Player not found.")
end

Set

lua
-- Set player saturation
mc.player.setSaturation(5.0)
print("Player saturation set to 5.0")

Player Speed

Get

lua
-- Get player speed
local speed = mc.player.getSpeed()
if speed ~= nil then
    print("Player Speed: " .. speed)
else
    print("Player not found.")
end

Set

lua
-- Set player speed
mc.player.setSpeed(0.1)
print("Player speed set to 0.1")

Player Food Level

Get

lua
-- Get player food level
local foodLevel = mc.player.getFoodLevel()
if foodLevel ~= nil then
    print("Player Food Level: " .. foodLevel)
else
    print("Player not found.")
end

Set

lua
-- Set player food level
mc.player.setFoodLevel(20)
print("Player food level set to 20")

Player Flying

Set

lua
-- Set player flying
mc.player.setFlying(true)
print("Player flying enabled")

Crosshair Target

Get

lua
-- Get crosshair target
local crosshairTarget = mc.player.getCrosshairTarget()
if crosshairTarget ~= nil then
    print("Crosshair Target: Type=" .. crosshairTarget[1] .. ", Name=" .. crosshairTarget[2])
else
    print("No target in crosshair.")
end

Hit Entity In Crosshair

lua
local hitResult = mc.player.hitEntityInCrosshair()
if hitResult ~= nil then
    print(hitResult)
else
    print("No entity hit.")
end

Player Attack Cooldown

Get

lua
-- Get attack cooldown
local attackCooldown = mc.player.getAttackCooldown()
if attackCooldown ~= nil then
    print("Attack Cooldown: " .. attackCooldown)
else
    print("Player not found.")
end

Is On Ground

Get

lua
-- Check if player is on ground
local onGround = mc.player.isOnGround()
if onGround ~= nil then
    print("Is On Ground: " .. tostring(onGround))
else
    print("Player not found.")
end

Is On Fire

Get

lua
-- Check if player is on fire
local onFire = mc.player.isOnFire()
if onFire ~= nil then
    print("Is On Fire: " .. tostring(onFire))
else
    print("Player not found.")
end

Is Gliding

Get

lua
-- Check if player is gliding
local isGliding = mc.player.isGliding()
if isGliding ~= nil then
    print("Is Gliding: " .. tostring(isGliding))
else
    print("Player not found.")
end