Skip to content

Player

Player Class

The Player class represents a player character in the game. It inherits from Creature and provides player-specific functionality.

Constructor

Player(identifier)
ParameterTypeDescription
identifiernumber/stringPlayer ID, name, or userdata

Returns: Player object or nil if not found


Type Checking

isPlayer()

Returns true if the object is a player.

if creature:isPlayer() then
local player = creature:getPlayer()
end

Account & Identity

MethodReturnsDescription
getGuid()numberPlayer’s unique database ID
getName()stringCharacter name
getIp()numberIP address as integer
getAccountId()numberAccount ID
getAccountType()numberAccount type (1-6)
setAccountType(type)booleanSet account type
getLastLoginSaved()numberLast login timestamp
getLastLogout()numberLast logout timestamp

Level & Experience

MethodReturnsDescription
getLevel()numberCurrent level
getExperience()numberTotal experience
addExperience(exp, sendText)-Add experience
removeExperience(exp, sendText)-Remove experience
-- Add 1000 exp with message
player:addExperience(1000, true)
-- Remove 500 exp silently
player:removeExperience(500, false)

Health & Mana

MethodReturnsDescription
getHealth()numberCurrent health
getMaxHealth()numberMaximum health
setMaxHealth(health)-Set max health
addHealth(amount)-Add/remove health
getMana()numberCurrent mana
getMaxMana()numberMaximum mana
setMaxMana(mana)-Set max mana
addMana(amount)-Add/remove mana
getBaseMaxHealth()numberBase max health (no bonuses)
getBaseMaxMana()numberBase max mana (no bonuses)

Magic Level

MethodReturnsDescription
getMagicLevel()numberCurrent magic level
getBaseMagicLevel()numberBase magic level (no bonuses)
getManaSpent()numberMana spent for magic level
addManaSpent(amount)-Add mana spent
removeManaSpent(amount)-Remove mana spent

Skills

MethodReturnsDescription
getSkillLevel(skillType)numberSkill level
getEffectiveSkillLevel(skillType)numberSkill with bonuses
getSkillPercent(skillType)numberProgress percent
getSkillTries(skillType)numberSkill tries
addSkillTries(skillType, tries)-Add skill tries
removeSkillTries(skillType, tries)-Remove skill tries
getSpecialSkill(skillType)numberSpecial skill value
addSpecialSkill(skillType, value)-Add special skill

Skill Types:

  • SKILL_FIST, SKILL_CLUB, SKILL_SWORD, SKILL_AXE
  • SKILL_DISTANCE, SKILL_SHIELDING, SKILL_FISHING

Special Skills:

  • SPECIALSKILL_CRITICALHITCHANCE
  • SPECIALSKILL_CRITICALHITAMOUNT
  • SPECIALSKILL_LIFELEECHCHANCE
  • SPECIALSKILL_LIFELEECHAMOUNT
  • SPECIALSKILL_MANALEECHCHANCE
  • SPECIALSKILL_MANALEECHAMOUNT

Soul & Stamina

MethodReturnsDescription
getSoul()numberCurrent soul points
addSoul(amount)-Add soul points
getMaxSoul()numberMaximum soul points
getStamina()numberStamina in minutes
setStamina(minutes)-Set stamina

Capacity

MethodReturnsDescription
getCapacity()numberMax capacity
setCapacity(cap)-Set capacity
getFreeCapacity()numberAvailable capacity

Vocation & Sex

MethodReturnsDescription
getVocation()VocationVocation object
setVocation(vocation)-Set vocation (ID or object)
getSex()numberSex (0=female, 1=male)
setSex(sex)-Set sex

Town & Guild

MethodReturnsDescription
getTown()TownHome town
setTown(town)-Set home town
getGuild()GuildPlayer’s guild
setGuild(guild)-Set guild
getGuildLevel()numberGuild rank level
setGuildLevel(level)-Set guild rank level
getGuildNick()stringGuild nickname
setGuildNick(nick)-Set guild nickname

Group & Premium

MethodReturnsDescription
getGroup()GroupPlayer group
setGroup(group)-Set group
getPremiumEndsAt()numberPremium end timestamp
setPremiumEndsAt(timestamp)-Set premium end
-- Check premium
if player:getPremiumEndsAt() > os.time() then
print("Player has premium")
end

Bank & Money

MethodReturnsDescription
getBankBalance()numberBank balance
setBankBalance(balance)-Set bank balance
getMoney()numberMoney in inventory
addMoney(amount)booleanAdd money to inventory
removeMoney(amount)booleanRemove money

Storage

MethodReturnsDescription
getStorageValue(key)numberStorage value (-1 if not set)
setStorageValue(key, value)-Set storage value
-- Quest example
if player:getStorageValue(1000) == -1 then
player:setStorageValue(1000, 1)
player:sendTextMessage(MESSAGE_INFO_DESCR, "Quest started!")
end

Items & Inventory

MethodReturnsDescription
addItem(itemId, count, canDropOnMap, subType, slot)ItemAdd item
addItemEx(item, canDropOnMap, slot)ReturnValueAdd existing item
removeItem(itemId, count, subType, ignoreEquipped)booleanRemove items
getItemCount(itemId, subType)numberCount of item
getItemById(itemId, deepSearch, subType)ItemFind item
getSlotItem(slot)ItemGet equipped item

Slots: CONST_SLOT_HEAD, CONST_SLOT_NECKLACE, CONST_SLOT_BACKPACK, CONST_SLOT_ARMOR, CONST_SLOT_RIGHT, CONST_SLOT_LEFT, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING, CONST_SLOT_AMMO

-- Add item
local item = player:addItem(2160, 10) -- 10 crystal coins
-- Check slot
local armor = player:getSlotItem(CONST_SLOT_ARMOR)
if armor then
print("Wearing: " .. armor:getName())
end

Depot & Storage Containers

MethodReturnsDescription
getDepotChest(depotId, autoCreate)ContainerDepot chest
getDepotItemCount()numberTotal depot items
getInbox()ContainerInbox container
getStoreInbox()ContainerStore inbox
getRewardChest()ContainerReward chest

Messaging

MethodDescription
sendTextMessage(type, message)Send text message
sendChannelMessage(author, message, type, channelId)Send channel message
sendPrivateMessage(target, message, type)Send private message
channelSay(target, type, message, channelId)Say in channel
sendCancelMessage(message)Send cancel message
popupFYI(message)Show popup

Message Types: MESSAGE_STATUS_DEFAULT, MESSAGE_STATUS_WARNING, MESSAGE_INFO_DESCR, MESSAGE_STATUS_CONSOLE_BLUE, MESSAGE_STATUS_CONSOLE_RED


Outfits & Mounts

MethodReturnsDescription
addOutfit(lookType)-Add outfit
addOutfitAddon(lookType, addon)-Add addon
removeOutfit(lookType)-Remove outfit
removeOutfitAddon(lookType, addon)-Remove addon
hasOutfit(lookType, addon)booleanCheck outfit
canWearOutfit(lookType, addon)booleanCan wear outfit
sendOutfitWindow()-Open outfit dialog
addMount(mountId)-Add mount
removeMount(mountId)-Remove mount
hasMount(mountId)booleanCheck mount

Blessings

MethodReturnsDescription
hasBlessing(blessing)booleanCheck blessing
addBlessing(blessing, count)-Add blessing
removeBlessing(blessing)-Remove blessing

Spells

MethodReturnsDescription
canLearnSpell(spellName)booleanCan learn spell
learnSpell(spellName)-Learn spell
forgetSpell(spellName)-Forget spell
hasLearnedSpell(spellName)booleanHas learned spell
getInstantSpells()tableList of known spells
canCast(spell)booleanCan cast spell

Combat & PvP

MethodReturnsDescription
getSkull()numberSkull type
setSkull(skull)-Set skull
getSkullTime()numberSkull time remaining
setSkullTime(time)-Set skull time
getDeathPenalty()numberDeath penalty percent
isPzLocked()booleanHas PZ lock
hasChaseMode()booleanChase mode enabled
hasSecureMode()booleanSecure mode enabled
getFightMode()numberFight mode

House

MethodReturnsDescription
getHouse()HousePlayer’s house (if in one)
sendHouseWindow(house, listId)-Open house dialog
setEditHouse(house, listId)-Edit house list

Party

MethodReturnsDescription
getParty()PartyPlayer’s party

Offline Training

MethodReturnsDescription
getOfflineTrainingTime()numberTraining time left
addOfflineTrainingTime(time)-Add training time
removeOfflineTrainingTime(time)-Remove training time
getOfflineTrainingSkill()numberSkill being trained
setOfflineTrainingSkill(skillId)-Set training skill
addOfflineTrainingTries(skillType, tries)-Add offline tries

Containers

MethodReturnsDescription
getContainerId(container)numberContainer ID for player
getContainerById(id)ContainerGet container by ID
getContainerIndex(id)numberContainer index

UI & Interface

MethodDescription
showTextDialog(item, text, canWrite, length)Show text dialog
openChannel(channelId)Open channel window
sendTutorial(tutorialId)Send tutorial hint
addMapMark(pos, type, description)Add map marker
sendCreatureSquare(creature, color)Show square on creature

Idle & Activity

MethodReturnsDescription
getIdleTime()numberIdle time in ms
resetIdleTime()-Reset idle timer

Ghost Mode

MethodDescription
setGhostMode(enabled)Enable/disable ghost mode
isInGhostMode()Check ghost mode

Equipment

MethodReturnsDescription
getEquipment()tableAll equipped items

Save

MethodReturnsDescription
save()booleanSave player to database

Augments

MethodReturnsDescription
addAugment(augment)-Add augment
removeAugment(augment)-Remove augment
isAugmented()booleanHas any augments
hasAugment(augment)booleanHas specific augment
getAugments()tableList of augments

Example: Complete Player Handler

local function onPlayerLogin(player)
-- Welcome message
player:sendTextMessage(MESSAGE_STATUS_DEFAULT,
"Welcome to the server, " .. player:getName() .. "!")
-- First login bonus
if player:getLastLoginSaved() == 0 then
player:addItem(2160, 100)
player:sendTextMessage(MESSAGE_INFO_DESCR,
"Welcome bonus: 100 crystal coins!")
end
-- Daily login reward
local lastDaily = player:getStorageValue(10000)
local today = os.date("%Y%m%d")
if lastDaily ~= tonumber(today) then
player:setStorageValue(10000, tonumber(today))
player:addExperience(1000, true)
end
-- Premium check
if player:getPremiumEndsAt() > os.time() then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE,
"Premium active!")
end
return true
end