迷你世界api 系統事件
阿新 • • 發佈:2020-12-09
迷你世界api 系統事件
遊戲活動管理
只需新增需要監視的事件,而無需建立事件物件,如下所示:
--Game Event--- ScriptSupportEvent:registerEvent([=[Game.Start]=], Game_StartGame) ScriptSupportEvent:registerEvent([=[Game.Run]=], Game_Update) ScriptSupportEvent:registerEvent([=[Game.End]=], Game_GameOver) --Player Event--- ScriptSupportEvent:registerEvent([=[Player.Die]=], Player_Dead) ScriptSupportEvent:registerEvent([=[Player.Revive]=], Player_Revive) ScriptSupportEvent:registerEvent([=[Player.AddItem]=], BackPack_AddItem) --Block Event--- ScriptSupportEvent:registerEvent([=[Block.Add]=], Block_Add) ScriptSupportEvent:registerEvent([=[Block.DestroyBy]=], Block_Destroy) ScriptSupportEvent:registerEvent([=[Block.Trigger]=], Block_Trigger)
遊戲事件型別和說明
沒有。 事件型別 描述
1個 世界大賽 地圖中的相關事件
2 邏輯事件 遊戲邏輯相關事件
3 玩家事件 玩家相關事件
4 生物事件 生物相關事件
5 封鎖事件 阻止相關事件
6 專案事件 專案相關事件
7 粒子事件 粒子相關事件
世界大賽(世界)
名稱 描述 引數
天氣變化 天氣變化 沒有
Backpack.ItemTakeOut 容器有物品輸出 {blockid,x,y,z,itemid,itemnum}1.1+
Backpack.ItemPutIn 容器有物品輸入 {blockid,x,y,z,itemid,itemnum}1.1+
Backpack.ItemChange 揹包欄的變更 {blockid,x,y,z,itemid,itemnum}
--Write a function, just named when the Change of weather will perform this function local function Weather_Changed() Chat:sendSystemMsg("Incident: Change of weather") end --Registered listeners, Change the function of the Executive Weather_Changed when weather --The first parameter is listening event, the second parameter Weather_Changed function that is executed when the event occurs ScriptSupportEvent:registerEvent([=[Weather.Changed]=],Weather_Changed)
--Write a function, just named when the Change of backpack bar will perform this function
local function Backpack_ItemChange(event)
Chat:sendSystemMsg("Incident: Change of backpack bar")
Chat:sendSystemMsg("Parameter blockid as:" .. event.blockid)
Chat:sendSystemMsg("Parameter x is:" .. event.x)
Chat:sendSystemMsg("Parameter y is:" .. event.y)
Chat:sendSystemMsg("The parameter z as:" .. event.z)
Chat:sendSystemMsg("Parameter itemid as:" .. event.itemid)
Chat:sendSystemMsg("Parameter itemnum as:" .. event.itemnum)
end
--Registered listeners, Change of backpack bar when a function execution Backpack_ItemChange
--The first parameter is listening event, the second parameter Backpack_ItemChange function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Backpack.ItemChange]=],Backpack_ItemChange)
邏輯事件相關示例:
--Write a function, just named, when Any player is defeated will perform this function
local function Game_AnyPlayer_Defeat(event)
Chat:sendSystemMsg("Incident: Any player is defeated")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
end
--Registered listeners when the function execution Game_AnyPlayer_Defeat Any player is defeated
--The first parameter is listening event, the second parameter Game_AnyPlayer_Defeat function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.Defeat]=],Game_AnyPlayer_Defeat)
複製!
--Write a function, just named, when Any player enters game when this function is executed
local function Game_AnyPlayer_EnterGame(event)
Chat:sendSystemMsg("Incident: Any player enters game")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
end
--Registered listeners, do Game_AnyPlayer_EnterGame function Any player enters game when
--The first parameter is listening event, the second parameter Game_AnyPlayer_EnterGame function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.EnterGame]=],Game_AnyPlayer_EnterGame)
複製!
--Write a function, just named, when Any player leaves game will perform this function
local function Game_AnyPlayer_LeaveGame(event)
Chat:sendSystemMsg("Incident: Any player leaves game")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
end
--Registered listeners, do Game_AnyPlayer_LeaveGame function Any player leaves game time
--The first parameter is listening event, the second parameter Game_AnyPlayer_LeaveGame function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.LeaveGame]=],Game_AnyPlayer_LeaveGame)
複製!
--Write a function, just named, when Any player wins when this function is executed
local function Game_AnyPlayer_Victory(event)
Chat:sendSystemMsg("Incident: Any player wins")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
end
--Registered listeners when the function execution Game_AnyPlayer_Victory Any player wins
--The first parameter is listening event, the second parameter Game_AnyPlayer_Victory function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.Victory]=],Game_AnyPlayer_Victory)
複製!
--Write a function, just named, when Game over will perform this function
local function Game_End()
Chat:sendSystemMsg("Incident: Game over")
end
--Registered listeners, do Game_End function when Game over
--The first parameter is listening event, the second parameter Game_End function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.End]=],Game_End)
複製!
--Write a function, just named, when the World time is when will perform this function [n]
local function Game_Hour(event)
Chat:sendSystemMsg("Incident: World time is [n]")
Chat:sendSystemMsg("Parameter hour as:" .. event.hour)
end
--Registered listeners, World time is executed Game_Hour function when [n]
--The first parameter is listening event, the second parameter Game_Hour function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.Hour]=],Game_Hour)
複製!
--Write a function, just named, when Start game will perform this function
local function Game_Load()
Chat:sendSystemMsg("Incident: Start game")
end
--Registered listeners, do Game_Load function when Start game
--The first parameter is listening event, the second parameter Game_Load function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.Load]=],Game_Load)
複製!
--Write a function, just named, when the Game is running will perform this function
--This event will be triggered once every 50ms, the internal function call interface should not be sending messages, or chat box will be scraper
local function Game_Run()
--Chat:sendSystemMsg("Incident: Game is running")
--Every 50ms to homeowner output increased 1 until the blood is not less than 100
local result,hp=Player:getAttr(0,2) - Get current health Homeowners
if hp<100 then-- if the blood is less than 100
Player:setAttr(0,2, hp + 1) - adding to the blood a homeowner
end
end
--Registered listeners, do Game_Run function when Game is running
--The first parameter is listening event, the second parameter Game_Run function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.Run]=],Game_Run)
複製!
--Write a function, just named, when the World time is [n] will perform this function when the second
--This event will be triggered once per second, so the internal function call interface should not be sending messages, or chat box will be scraper
local function Game_RunTime(event)
--Chat:sendSystemMsg("Incident: World time is [n] second")
--Chat:sendSystemMsg("Second parameter as:" .. event.second)
--Per second to homeowners hungry increased by one, until the value of not less than 100 hunger
local result,hunger=Player:getAttr(0,6) - Get the current value of a homeowner hunger
if hunger<100 then-- If the value is less than 100 hunger
Player:setAttr(0,6, hunger + 1) - a plus value to a homeowner hunger
end
end
--Registered listeners, World time is [n] function when the second execution Game_RunTime
--The first parameter is listening event, the second parameter Game_RunTime function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.RunTime]=],Game_RunTime)
複製!
--Write a function, just named, when Game start will perform this function
local function Game_Start()
Chat:sendSystemMsg("Incident: Game start")
end
--Registered listeners, do Game_Start function when Game start
--The first parameter is listening event, the second parameter Game_Start function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.Start]=],Game_Start)
複製!
--Write a function, just named, when Game timeout will perform this function
local function Game_TimeOver()
Chat:sendSystemMsg("Incident: Game timeout")
end
--Registered listeners when Game timeout function execution Game_TimeOver
--The first parameter is listening event, the second parameter Game_TimeOver function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Game.TimeOver]=],Game_TimeOver)
複製!
--Write a function, just named, when Any change will do this time of Timer function
local function minitimer_change(event)
Chat:sendSystemMsg("Incident: Any change of Timer")
Chat:sendSystemMsg("Parameter timerid as:" .. event.timerid)
Chat:sendSystemMsg("Parameter timername as:" .. event.timername)
end
--Registered listeners, Any change execution minitimer_change time of Timer function
--The first parameter is listening event, the second parameter minitimer_change function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[minitimer.change]=],minitimer_change)
玩家事件相關示例:
--Write a function, just named when the Add new item will perform this function
local function Player_AddItem(event)
Chat:sendSystemMsg("Incident: Add new item")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
Chat:sendSystemMsg("Parameter itemid as:" .. event.itemid)
Chat:sendSystemMsg("Parameter itemnum as:" .. event.itemnum)
end
--Registered listeners when the function execution Player_AddItem Add new item
--The first parameter is listening event, the second parameter Player_AddItem function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Player.AddItem]=],Player_AddItem)
複製!
--Write a function, just named when the Player enters area will perform this function
local function Player_AreaIn(event)
Chat:sendSystemMsg("Incident: Player enters area")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter areaid as:" .. event.areaid)
end
--Registered listeners, do Player_AreaIn function when Player enters area
--The first parameter is listening event, the second parameter Player_AreaIn function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Player.AreaIn]=],Player_AreaIn)
複製!
--Write a function, just named when the Player leaves area will perform this function
local function Player_AreaOut(event)
Chat:sendSystemMsg("Incident: Player leaves area")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter areaid as:" .. event.areaid)
end
--Registered listeners, do Player_AreaOut function when Player leaves area
--The first parameter is listening event, the second parameter Player_AreaOut function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Player.AreaOut]=],Player_AreaOut)
生物事件相關示例:
--Write a function, just named, when the Creature enters area will perform this function
local function Actor_AreaIn(event)
Chat:sendSystemMsg("Incident: Creature enters area")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter areaid as:" .. event.areaid)
end
--Registered listeners, do Actor_AreaIn function when Creature enters area
--The first parameter is listening event, the second parameter Actor_AreaIn function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Actor.AreaIn]=],Actor_AreaIn)
複製!
---Actor.AreaOut---49
--Write a function, just named, when the Creature leaves area will perform this function
local function Actor_AreaOut(event)
Chat:sendSystemMsg("Incident: Creature leaves area")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter areaid as:" .. event.areaid)
end
--Registered listeners, do Actor_AreaOut function when Creature leaves area
--The first parameter is listening event, the second parameter Actor_AreaOut function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Actor.AreaOut]=],Actor_AreaOut)
複製!
---Actor.Attack---50
--Write a function, just named, when the Creature attacking will perform this function
local function Actor_Attack(event)
Chat:sendSystemMsg("Incident: Creature attacking")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
end
--Registered listeners, execute function when Creature attacking Actor_Attack
--The first parameter is listening event, the second parameter Actor_Attack function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Actor.Attack]=],Actor_Attack)
複製!
---Actor.AttackHit---51
--Write a function, just named, when the Creature attack hits will perform this function
local function Actor_AttackHit(event)
Chat:sendSystemMsg("Incident: Creature attack hits")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
end
--Registered listeners, Creature attack hits execution function when Actor_AttackHit
--The first parameter is listening event, the second parameter Actor_AttackHit function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Actor.AttackHit]=],Actor_AttackHit)
阻止事件相關示例:
--Write a function, just named, when Block is created will perform this function
local function Block_Add(event)
Chat:sendSystemMsg("Incident: Block is created")
Chat:sendSystemMsg("Parameter blockid as:" .. event.blockid)
Chat:sendSystemMsg("Parameter x is:" .. event.x)
Chat:sendSystemMsg("Parameter y is:" .. event.y)
Chat:sendSystemMsg("The parameter z as:" .. event.z)
end
--Registered listeners, do Block_Add function when Block is created
--The first parameter is listening event, function that executes when the second argument Block_Add That incident
ScriptSupportEvent:registerEvent([=[Block.Add]=],Block_Add)
複製!
--Write a function, just named, when Block is destoryed will perform this function
local function Block_DestroyBy(event)
Chat:sendSystemMsg("Incident: Block is destroyed")
Chat:sendSystemMsg("Parameter eventobjid (opt) as:" .. event.eventobjid (opt))
Chat:sendSystemMsg("Parameter blockid as:" .. event.blockid)
Chat:sendSystemMsg("Parameter x is:" .. event.x)
Chat:sendSystemMsg("Parameter y is:" .. event.y)
Chat:sendSystemMsg("The parameter z as:" .. event.z)
end
--Registered listeners, do Block_DestroyBy function when Block is destoryed
--The first parameter is listening event, the second parameter Block_DestroyBy function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Block.DestroyBy]=],Block_DestroyBy)
複製!
--Write a function, just named when the Start mining block will perform this function
local function Block_Dig_Begin(event)
Chat:sendSystemMsg("Incident: Start mining block")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter blockid as:" .. event.blockid)
Chat:sendSystemMsg("Parameter x is:" .. event.x)
Chat:sendSystemMsg("Parameter y is:" .. event.y)
Chat:sendSystemMsg("The parameter z as:" .. event.z)
end
--Registered listeners, do Block_Dig_Begin function when Start mining block
--The first parameter is listening event, the second parameter Block_Dig_Begin function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[Block.Dig.Begin]=],Block_Dig_Begin)
專案活動相關示例:
--Write a function, just named, when Drop item enters area will perform this function
local function DropItem_AreaIn(event)
Chat:sendSystemMsg("Incident: Drop item enters area")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter areaid as:" .. event.areaid)
Chat:sendSystemMsg("Parameter itemid (opt) as:" .. event.itemid (opt))
Chat:sendSystemMsg("Parameter itemnum (opt) as:" .. event.itemnum (opt))
end
--Registered listeners, do DropItem_AreaIn function when Drop item enters area
--The first parameter is listening event, the second parameter DropItem_AreaIn function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[DropItem.AreaIn]=],DropItem_AreaIn)
複製!
--Write a function, just named, when Drop item leaves area will perform this function
local function DropItem_AreaOut(event)
Chat:sendSystemMsg("Event: Drop item leaves area")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter areaid as:" .. event.areaid)
Chat:sendSystemMsg("Parameter itemid (opt) as:" .. event.itemid (opt))
Chat:sendSystemMsg("Parameter itemnum (opt) as:" .. event.itemnum (opt))
end
--Registered listeners, do DropItem_AreaOut function when Drop item leaves area
--The first parameter is listening event, the second parameter DropItem_AreaOut function that is executed when the event occurs
ScriptSupportEvent:registerEvent([=[DropItem.AreaOut]=],DropItem_AreaOut)
複製!
--Write a function, just named when the Item disappear will perform this function
local function Item_Disappear(event)
Chat:sendSystemMsg("Incident: Item disappear")
Chat:sendSystemMsg("Parameter eventobjid as:" .. event.eventobjid)
Chat:sendSystemMsg("Parameter toobjid as:" .. event.toobjid)
Chat:sendSystemMsg("Parameter itemid as:" .. event.itemid)
Chat:sendSystemMsg("Parameter itemnum as:" .. event.itemnum)
end
--Registered listeners, Item disappear when the function execution Item_Disappear --The first parameter is listening event, the second parameter Item_Disappear function that is executed when the event occurs ScriptSupportEvent:registerEvent([=[Item.Disappear]=],Item_Disappear)