Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calling the Bus

Considering that you got to this point, you have a good grasp on how the AnimBus works on itself. However, there is one thing remaining, and that is how to call an AnimBus, so we can play our scenes!

Currently there are two ways of utilizing the AnimBus through the API. One is calling an AnimBus on the Client with Buscaller.lua, and the other is directly creating one in the Server side by using the BusManager.lua. Let’s examine those methods.

Client Method

Since the AnimBus lives on the Server. We can’t directly create one for use. However we still can call for its creation utilizing the module BusCaller.lua. In this example, we can make a simple code that calls an AnimBus whenever a player tries to reload their weapon.

local BusCaller = require("DepravedSense/AnimGraph/BusCaller")

-- These are the necessary addresses to be able to find out Ticket in the Graph.
-- We still didn't explain the reason for these, but they will make sense when
-- we explain AnimKits. Just keep in mind that they are important.
local TICKET_ID      = "yourticket_id"
local ANIMKIT_MODULE = "youranimkitmodule"

---@param player IsoPlayer
---@param weapon HandWeapon
local function on_press_reload_button(player, weapon)
	-- To call a bus, we need a list of characters, so in here we wrap the player
	-- into a list.
	local character_list = { player }

	-- This will attempt to call a bus on the server side. And return a boolean
	-- value indicating whether it was able to send its command.
	local success = BusCaller.call_bus_with_characters(character_list, TICKET_ID, ANIMKIT_MODULE)

	if success then
		print("Called Bus!")
	else
		print("Failed to call the Bus...")
	end
end

Events.OnPressReloadButton.Add(on_press_reload_button)

If everything goes right, the player shall enter in an AnimBus at the exact specified Ticket, and execute the animation scene.

Server Method

Calling the bus on the Server is way more direct than on the Client since we are already on the same environment that the AnimBus lives on. So, instead of using BusCaller to handle commands for us, we can use the BusManager, and create a bus ourselves. PS. The BusManager.lua is a module that stores and updates all busses.

local Actor = require("DepravedSense/AnimGraph/Actor")
local BusManager = require("DepravedSense/AnimGraph/BusManager")

local TICKET_ID      = "yourticket_id"
local ANIMKIT_MODULE = "youranimkitmodule"

---In here, on multiplayer, a bus will be created as soon as a player processes an
---action.
---@param action string
---@param player IsoPlayer
---@param args table
local function on_player_process_action(action, player, args)
	-- In here, it's necessary that we create Actors based on the characters
	local player_actor = Actor:new(player)
	local actor_list = { player_actor }

	BusManager.create_bus(actor_list, TICKET_ID, ANIMKIT_MODULE)
end

Events.OnProcessAction.Add(on_player_process_action)