# Player Management

Derive from Actor

Before using player API, please create player management object. The methods as follows:

local Player = class.Player.new()

The specific function name and description are as follows:

Serial number Function name Description
1 getAttr(...) Obtain Player attribute
2 setAttr(...) Player attribute setting
3 getHostUin(...) Obtain uin of host
4 isMainPlayer(...) Whether it is local player
5 getMainPlayerUin(...) Get the local player's uin
6 getGameResults(...) Get result of the game
7 setGameResults(...) Set result of the game
8 getGameScore(...) Get score of the game
9 setGameScore(...) Set score of the game
10 getGameRanking(...) Get the rank of player
11 setGameRanking(...) Set the rank of player
12 gainItems(...) Add items for players
13 teleportHome(...) Transfer to spawn point
14 getCurToolID(...) Get the item id currently held by the player
15 getNickname(...) Get the player's name
16 removeBackpackItem(...) Remove items in backpack
17 getDieTimes(...) Get the number of deaths
18 getLeftLifeNum(...) Get the number of remaining lives left
19 setTeam(...) Set player team
20 getTeam(...) Obtain player team
21 getFoodLevel(...) Get the current satiety
22 setFoodLevel(...) Set satiety of player
23 getCurShotcut(...) Get the current shortcut bar
24 onCurToolUsed(...) Set the consumption of item held by player
25 setSkillCD(...) Set CD
26 reviveToPos(...) Respawn player at designated point
27 setRevivePoint(...) Change the respawn point
28 mountActor(...) Player rides the mount 1.1+
29 playAct(...) Player play the cartoon
30 notifyGameInfo2Self(...) Display texts in popup window
31 useItem(...) Make player use current item
32 rotateCamera(...) Rotate player's lens
33 changeViewMode(...) Change angle mode of player
34 setActionAttrState(...) Set attribute status of player behavior
35 checkActionAttrState(...) Obtain status of player special attribute
36 setPosition(...) Set the location of player
37 getAimPos(...) Get the crosshair location of player
38 setItemAttAction(...) Set the setting attribute of player item 1.1+
39 playMusic(...) Play background music to players 1.3+
40 stopMusic(...) Stop background music to players 1.3+
41 setGameWin(...) Make player win 1.5+
42 openDevStore(...) Open Dev. Store 1.5+
43 playAdvertising(...) Play Advertising(Callback can be configured) 1.5+

# getAttr

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain Player attribute
  • The specific use cases are as follows:
--Get the homeowner's health
--The first parameter 0 is the game player id or player mini number,0 is the homeowner
--The second parameter 2 is the attribute:the current health value,which can be viewed in the "player attribute enumeration" of the "game data type"
local result,value=Player:getAttr(0,2)
--Show in chat box
Chat:sendSystemMsg("Homeowner's current health value:"..value)

# setAttr

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Player attribute setting
  • The specific use cases are as follows:
--Set the homeowner's life limit
--The first parameter 0 is the game player id or player mini number,0 is the homeowner
--The second parameter 1 is the attribute:the upper limit of life,which can be viewed in the "player attribute enumeration" of the "game data type"
--The third parameter 500 is the value of the property that needs to be set
Player:getAttr(0,1,500)
--Show in chat box
Chat:sendSystemMsg("The homeowner's life limit is set to 500")

# getHostUin

  • Parameters and types:nil
  • Return value and types:
  • The main role of this method: Obtain uin of host
  • The specific use cases are as follows:
--Get the owner's mini number
local result,uin=Player:getHostUin()
--Show in chat box
Chat:sendSystemMsg("The homeowner's mini number is:"..uin)

# isMainPlayer

  • Parameters and types:
  • Return value and types:
    • ErrorCode.OK is that local player is local player
  • The main role of this method: Whether it is local player
  • The specific use cases are as follows:
--Determine whether a mini number is a local player (homeowner)
--Parameter 1000 is the mini number to be judged
local result=Player:isMainPlayer(1000)
if result==0 then--if yes
	--Show in chat box
	Chat:sendSystemMsg("1000 is a local player(homeowner)")
else--if not
	--Show in chat box
	Chat:sendSystemMsg("1000 is not a local player(homeowner)")
end

# getMainPlayerUin

  • Parameters and types:nil
  • Return value and types:
  • The main role of this method: Get the local player's uin
  • The specific use cases are as follows:
--Get the local player (homeowner) mini number
local result,uin=Player:getMainPlayerUin()
--Show in chat box
Chat:sendSystemMsg("The local player(homeowner) mini number is:"..uin)

# getGameResults

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get result of the game
  • The specific use cases are as follows:
--Get the player's game status or game results
--Parameter 0 is the player id or player mini number,0 is the homeowner
--The return value may be:0 game 1 game victory 2 game end
local result,value=Player:getGameResults(0)
Chat:sendSystemMsg("The current homeowner's game state is(0 games,1 game wins,2 game ends):"..value)

# setGameResults

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set result of the game
  • The specific use cases are as follows:
--Set the player's game state or match result
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the game state or game result:0 game 1 game wins 2 game end
Player:setGameResults(0,1)
--Show in chat box
Chat:sendSystemMsg("Set Host Game Win")

# getGameScore

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get score of the game
  • The specific use cases are as follows:
--Display the homeowner's game score in the chat box when the player makes an animated expression
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Get game scores from homeowners
	--Parameter 0 is the player id or player mini number,0 is the homeowner
	local result,value=Player:getGameScore(0)
	--Show in chat box
	Chat:sendSystemMsg("The host's current game score is "..value)
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# setGameScore

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set score of the game
  • The specific use cases are as follows:
--Set the homeowner's score to 100 (the player's score is not the score of the player's team,pay attention to the difference. The team score can be found in Team)
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the game score to be set
Player:setGameScore(0,100)
--Show in chat box
Chat:sendSystemMsg("The homeowner's game score is set to 100(player score is not the score of the player's team)")

# getGameRanking

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the rank of player
  • The specific use cases are as follows:
--Get the player's game ranking
--Parameter 0 is the player id or player mini number,0 is the homeowner
local result,rank=Player:getGameRanking(0)
--Show in chat box
Chat:sendSystemMsg("Homeowner's Game Ranking Behavior"..rank)

# setGameRanking

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set the rank of player
  • The specific use cases are as follows:
--Set the homeowner's ranking first
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the player ranking
Player:setGameRanking(0,1)
--Show in chat box
Chat:sendSystemMsg("Homeowner Rank is set as No. 1")

# gainItems

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Add items for players
  • The specific use cases are as follows:
--Add a certain item or item to the player's backpack
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the id of the added item,1 is the bedrock
--The third parameter is the number of items added
--The last parameter is the priority shortcut bar or the backpack bar:1 priority shortcut bar 2 priority backpack bar
Player:gainItems(0,1,10,1)
--Show in chat box
Chat:sendSystemMsg("Add 10 bedrocks to the homeowner shortcut bar or backpack")

# teleportHome

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Transfer to spawn point
  • The specific use cases are as follows:
--Every time the player makes an animated expression,the homeowner will be sent back to the birth point
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Send the player to the birth point,the parameter is the player id or player mini number,0 is the homeowner
	Player:teleportHome(0)
	--Show in chat box
	Chat:sendSystemMsg("Homeowner was teleported to the point of birth")
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# getCurToolID

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the item id currently held by the player
  • The specific use cases are as follows:
--Get the id of the player's hand-held item,the parameter is the player id or player mini number,0 is the homeowner
local result,id=Player:getCurToolID(0)
--Show in chat box
Chat:sendSystemMsg("The id of the item currently held by the homeowner is "..id)

# getNickname

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the player's name
  • The specific use cases are as follows:
--Get the player's nickname,the parameter is the player id or player mini number,0 is the host
local result,name=Player:getNickname(0)
--Show in chat box
Chat:sendSystemMsg("Homeowner's nickname:"..name)

# removeBackpackItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove items in backpack
  • The specific use cases are as follows:
--Remove items from player's backpack
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the id of the item to be removed,101 is the soil block
--The third parameter is the number of items to be removed
Player:removeBackpackItem(0,101,10)
--Show in chat box
Chat:sendSystemMsg("Removed 10 soil blocks from the owner's backpack")

# getDieTimes

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the number of deaths
  • The specific use cases are as follows:
--Whenever the player makes an animated expression,the chat box displays the number of deaths of the homeowner
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Get the number of player deaths,the parameter is the player id or player mini number,0 is the homeowner
	local result,value=Player:getDieTimes(0)
	--Show in chat box
	Chat:sendSystemMsg("The homeowner's death count is "..value)
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# getLeftLifeNum

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the number of remaining lives left
  • The specific use cases are as follows:
--Whenever the player makes an animated expression,the chat box displays the remaining life of the homeowner
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Get the remaining life of the player,the parameter is the player id or player mini number,0 is the homeowner
	local result,value=Player:getLeftLifeNum(0)
	--Show in chat box
	Chat:sendSystemMsg("Homeowner's remaining life is "..value)
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# setTeam

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set player team
  • The specific use cases are as follows:
--Set up the player team
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the team to be set
Player:setTeam(0,2)
--Show in chat box
Chat:sendSystemMsg("Homeowner is set as the second team")

# getTeam

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain player team
  • The specific use cases are as follows:
--Get the player's team,the parameter is the player id or player mini number,0 is the host
local result,value=Player:getTeam(0)
--Show in chat box
Chat:sendSystemMsg("The host team is:"..value)

# getFoodLevel

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the current satiety
  • The specific use cases are as follows:
--Get the player's satiety,the parameter is the player id or player mini number,0 is the homeowner
local result,value=Player:getFoodLevel(0)
--Show in chat box
Chat:sendSystemMsg("Homeowner's current satiety is "..value)

# setFoodLevel

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set satiety of player
  • The specific use cases are as follows:
--Set the player's satiety
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the degree of satiety to be set
Player:setFoodLevel(0,100)
--Show in chat box
Chat:sendSystemMsg("Set the homeowner's satiety to 100")

# getCurShotcut

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the current shortcut bar
  • The specific use cases are as follows:
--Get the location of the shortcut bar currently selected by the player,the parameter is the player id or player mini number,0 is the homeowner
local result,scutIdx=Player:getCurShotcut(0)
--Show in chat box
Chat:sendSystemMsg("The shortcut bar currently selected by the homeowner is:"..scutIdx)

# onCurToolUsed

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set the consumption of item held by player
  • The specific use cases are as follows:
--Set the consumption of items held by players
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the number of props consumed (seems to have no effect)
Player:onCurToolUsed(0,1)
--Show in chat box
Chat:sendSystemMsg("The owner's currently selected item has been removed 1")

# setSkillCD

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set CD
  • The specific use cases are as follows:
--Every time the player makes an animated expression,the diamond sword CD of the homeowner will become 100 seconds
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Set the player's props CD
	--The first parameter is the player id or player mini number,0 is the homeowner
	--The second parameter is the prop id,12005 is the energy sword (diamond sword)
	--The third parameter is the set skill cooling time
	Player:setSkillCD(0,12005,100)
	--Show in chat box
	Chat:sendSystemMsg("The homeowner's diamond sword skill cooldown is set to 100 seconds")
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# reviveToPos

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Respawn player at designated point
  • The specific use cases are as follows:
--Resurrect the player to the specified location (seems to have no effect,maybe only effective for the dead player)
--The first parameter is the player id or player mini number,0 is the homeowner
--The last three parameters are resurrected to coordinates
Player:reviveToPos(0,50,7,50)
--Show in chat box
Chat:sendSystemMsg("Resurrection of homeowner to(50,50) height 7 position")

# setRevivePoint

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Change the respawn point
  • The specific use cases are as follows:
--Set the player's resurrection point coordinates
--The first parameter is the player id or player mini number,0 is the homeowner
--The last three parameters are the set resurrection point coordinates
Player:setRevivePoint(0,50,7,50)
--Show in chat box
Chat:sendSystemMsg("Homeowner's resurrection point is set at(50,50) height 7")

# mountActor 1.1+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Player rides the mount
  • The specific use cases are as follows:
local result = Player:mountActor(playerid, objid, posindex)

# playAct

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Player play the cartoon
  • The specific use cases are as follows:
--Let players play animated emojis
--The first parameter is the player mini number
--The second parameter is the action expression id,which can be queried in "Action Table Data" of "Mini World ID Query"
Player:playAct(1000,1)
--Show in chat box
Chat:sendSystemMsg("Let the player with the mini number 1000 play the greeting action")

# notifyGameInfo2Self

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Display texts in popup window
  • The specific use cases are as follows:
--Display a prompt box for the player
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the displayed text content
Player:notifyGameInfo2Self(0,"Here is the text content of the floating window")

# useItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Make player use current item
  • The specific use cases are as follows:
local result = Player:useItem(objid, itemid, status, onshift)

# rotateCamera

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Rotate player's lens
  • The specific use cases are as follows:
--Set the direction of the player's perspective
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the horizontal rotation angle,true north is 0,from north to east is the positive direction
--The third parameter is the pitch angle,90 is the top view,-90 is the upward view,the angle between can be set arbitrarily
Player:rotateCamera(0,90,90)
--Show in chat box
Chat:sendSystemMsg("The homeowner's perspective is set to face the east and look down")

# changeViewMode

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Change angle mode of player
  • The specific use cases are as follows:
--Set player perspective mode
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the viewing angle mode:0 main viewing angle 1 back viewing angle 2 positive viewing angle 3 overhead viewing angle 4 custom viewing angle
--The third parameter is whether to lock the perspective:true lock false not lock
Player:changeViewMode(0,0,true)
--Show in chat box
Chat:sendSystemMsg("Lock the homeowner's perspective as the first-person main perspective")

# setActionAttrState

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set attribute status of player behavior
  • The specific use cases are as follows:
--Set player behavior attribute status
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the behavior attribute value,1 is "moving",you can check it in "Player Attribute Setting" of "Game Data Type"
--The third parameter is "whether it is possible",true can be false not
Player:setActionAttrState(0,1,false)
--Show in chat box
Chat:sendSystemMsg("Set homeowner immovable")

# checkActionAttrState

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain status of player special attribute
  • The specific use cases are as follows:
--Get the player's behavior attribute status
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the behavior attribute value,1 is "moving",you can check it in "Player Attribute Setting" of "Game Data Type"
local result=Player:checkActionAttrState(0,1)
if result==0 then--if you can
	--Show in chat box
	Chat:sendSystemMsg("Homeowner can move")
else--if not
	--Show in chat box
	Chat:sendSystemMsg("Homeowner is not mobile")
end

# setPosition

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set the location of player
  • The specific use cases are as follows:
--Set the player to a certain coordinate
--The first parameter is the player id or player mini number,0 is the homeowner
--The last three parameters are the set coordinates
Player:setPosition(0,100,7,100)
--Show in chat box
Chat:sendSystemMsg("Homeowner is set to(100,100) height 7 position")

# getAimPos

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get the crosshair location of player
  • The specific use cases are as follows:
--Get the player's cross center coordinates,the parameter is the player id or player mini number,0 is the homeowner
local result,x,y,z=Player:getAimPos(0)
--Show in chat box
Chat:sendSystemMsg("The homeowner's current center of gravity coordinates are("..x..","..y..","..z..")")
--Output to the console
print("The homeowner’s current cross-centre coordinates are("..x..","..y..","..z..")")

# setItemAttAction 1.1+

--Set the operation attributes of the player's props
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the id of the prop to be set,101 is the soil block
--The third parameter is the attribute value:1 cannot be discarded 2 cannot be dropped
--The last parameter is whether to open the property:true open false close
Player:setItemAttAction(0,101,1,true)
--Show in chat box
Chat:sendSystemMsg("Homeowner is set to a non-disposable clod")

# playMusic 1.3+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Play background music to players
  • The specific use cases are as follows:
--Play music to players
--The first parameter is the player id or player mini number,0 is the homeowner
--The second parameter is the music id,which can be viewed in the "Sound Effect Table Data" of the "Mini World ID Table Query"
--The third parameter is the playback volume
--The fourth parameter is the playback pitch
--The last parameter is whether to loop playback
Player:playMusic(0,10713,100,1,false)
--Show in chat box
Chat:sendSystemMsg("Start playing music to the host 10713")

# stopMusic 1.3+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Stop background music to players
  • The specific use cases are as follows:
--Play music to the host 10713
Player:playMusic(0,10713,100,1,false)
--Show in chat box
Chat:sendSystemMsg("Start playing music 10713 to the host,stop the playback with animated expressions")
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Stop playing music to the player,the parameter is player id or player mini number,0 is the host
	Player:stopMusic(0)
	--Show in chat box
	Chat:sendSystemMsg("Stop playing music to the host")
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# setGameWin 1.5+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Make player win
  • The specific use cases are as follows:
--Whenever the player makes an animated expression,let the player with the designated mini number win
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--The designated mini player wins,the parameter is the player mini number
	local result=Player:setGameWin(1000)
	if result==0 then--If there is a player with a mini number of 1000 in the room
		--Show in chat box
		Chat:sendSystemMsg("Set Player 1000 to Win")
	else--If there is no player with a mini number of 1000 in the room
		--Show in chat box
		Chat:sendSystemMsg("No player in the room has a mini number of 1000")
	end
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# openDevStore 1.5+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Open Dev. Store
  • The specific use cases are as follows:
--Whenever the player makes an animated expression,open the developer store for the designated player
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Open the developer store for the specified player,the parameter is the player id or player mini number,0 is the host
	Player:openDevStore(0)
	--Show in chat box
	Chat:sendSystemMsg("Open the developer store for the homeowner")
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# playAdvertising 1.5+

  • Parameters and types:
    • objid:number
    • adname:stringName of the advertising
    • eventname:stringCallback event name
    • eventparams:tableCallback event parameters
  • Return value and types:
  • The main role of this method: Play Advertising(Callback can be configured)
  • The specific use cases are as follows:
local result = Player:playAdvertising(objid, adname, eventname, eventparams)
Last Update: 6/11/2020, 9:30:46 PM