How would I go about interpreting player input in a valid manner? (AeroGameFramework)

I’m making a game where players have abilities that they can activate with their keyboard, aim with their mouse, etc. I get the input using an AGF controller (local modulescript that is loaded upon player joining game) and send it to the server. The set of abilities that players may have greatly varies, so I want to separate each set into it’s own controller.

I want players to only have the controller for the set of abilities that they own – for example, if a player has fire abilities, they will only have the controller that gets input for fire-related abilities and not the one that gets input for the water abilities.

However due to the nature of AGF, I don’t think I am able to add and remove controllers while a player is ingame. So how would I give the appropriate controller to a player upon loading their data?

1 Like

First of all, server side and client side connections are key, if you want to check if a player has something, check from the server side and send it back to the client side.

This might work for you:

-- Service
local Service = {Client = {}}

function Service.Client:HasItem(plr, name)
    -- Check if the player has the item
    return true -- Then return it back

return Service
-- Controller
local Controller = {}

function Controller:Start()
    local userInputService = game:GetService("UserInputService")
    local service = self.Services.Service -- Whatever the name is, replace Service with it.
    local controls = {}

    if(service:HasItem("Rocket Smash")) then -- For example
        controls["Rocket Smash"] = true
    userInputService.InputBegan:connect(input, gameProcessedEvent)
        if(input.UserInputType == Enum.UserInputType.Keyboard and
           controls["Rocket Smash"]) then
            print("Rocket.... SMASH!")

return Controller

Using this method, I would then have to give every player the controller for every set of abilities. Is this okay or might it be insecure/inefficient?

I don’t know of much insecurities, especially since it’s server side. I think you’re good to go, I made a post on the module: Datastore Caching Module

Sorry I got confused about what this was because I didn’t read it. I didn’t mean to send the link of a Datastore caching module. Still, there shouldn’t be much insecurities, but make sure to check if a player has an ability on the server side before you do anything, that way the client can’t interfere and get anything they want.

1 Like

I’d like to mention that AeroGameFramework has a premade UserInput controller that can make it cleaner and easier to work with user input

local Keyboard = self.Controllers.UserInput:Get("Keyboard")
    if keyCode == Enum.KeyCode.E then
        -- Yada yada yada

You can then:

  • Skip checking for GameProcessedEvent as that is handled by the UserInput controller
  • Skip checking for UserInputType since that is handled by the returned Keyboard module
  • Also use some premade functions that might come in handy: Keyboard:IsDown(keyCode), Keyboard:AreAllDown(keyCodes...),Keyboard:AreAnyDown(keyCodes...)

Oh, that’s pretty nice actually. I am not a big AeroGameFramework user, but I know the basics. Thanks for the reply! I learned something new today.