Skip to content

Instantly share code, notes, and snippets.

@Nimblz
Last active May 16, 2019 01:20
Show Gist options
  • Save Nimblz/b56faf856d03a9d714511588fd728638 to your computer and use it in GitHub Desktop.
Save Nimblz/b56faf856d03a9d714511588fd728638 to your computer and use it in GitHub Desktop.

the behavior asset could look something like this maybe

-- AssetBehaviors/BaseballBat.lua
local BatBehavior = {}

function BatBehavior:equippedClient(player, otherArgs...) -- would be called locally whenever you or someone else equips the baseball bat
function BatBehavior:equippedServer(player, otherArgs...) -- called on the server when anyone equips the baseball bat

function BatBehavior:unequippedClient(player)
function BatBehavior:unequippedServer(player)

function BatBehavior:processActionClient(player,payload) -- called on client when an action is dispatched for this asset by player, effects, animations, and other local things should go here
function BatBehavior:processActionServer(player,payload) -- called on server when an action is dispatched for this asset by player, business logic for tool should go here (decreasing health, interacting with server side puzzle element, knocking players back)

These would be called by Equipment modules on the client and server.

Would it be a good idea to separate client and server behaviors into their own modules clientBehavior and serverBehavior properties of the asset?

Finally my api spec has these endpoints to do networking of attempted actions, validation would be done on the server before replicating to other clients or running server behaviors

fromClient = {
    equippedAction = {
        arguments = t.tuple(
            t.string, -- assetid that is being used and should recieve the action (if its equipped)
            t.any -- action payload (action type, any arguments (target, options))
        )
    }
}
fromServer = {
    equippedAction = {
        arguments = t.tuple(
            t.Instance, -- player performing this action
            t.string, -- assetid that is being used and should recieve the action (if its equipped)
            t.any -- action payload (action type, any arguments (target, options))
        )
    }
}

They should prolly have different names.. maybe actionBroadcast as the fromServer event..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment