Create an AI state script||doc135568

September 20, 2022

Description


You must create a new custom_ai folder in the server script, and put the custom state script in the folder, otherwise the editor cannot read it.

Create the ai_state_dance script (dance state) and place it in the custom_ai directory.
For other states, the following script code can be used as a template by modifying the variable name of AIStateDance.


script code

local AIStateBase = require("entity.ai.ai_state_base")
---Make AIStateDance inherit from AIStateBase
local AIStateDance = L("AIStateDance", Lib.derive(AIStateBase))

---State name
AIStateDance.NAME = "DANCE"

---Called automatically when entering a state
function AIStateDance:enter()
    print("enter dance state")
end

---Called cyclically at the current state
function AIStateDance:update()
    local control = self.control
    local danceAction = control:aiData("danceAction")
    print("danceAction", danceAction)
    print("dance state update")
end

---Called automatically on exit status
function AIStateDance:exit()
    print("exit dance state")
end

RETURN(AIStateDance)