Hello there fellow developers!
I need some framework help with making my abilities and characters for my battlegrounds game. I want the following things implemented correctly and efficiently:
Character Picker/Loader and the server handles the loading. There is a custom hotbar NOT USING ROBLOX TOOLS but instead using buttons and key binds. (Idk how to connect these and use them while not repeating code per Character)
Character can be executing using normal moves and the Meter fills up.
Once meter is full, the client is alerted and a seperate keybind to activate the ultimate is connected. (Button too for mobile)
If meter is activated, the hotbar swaps as usual. The bar decays down until hitting 0, before switching back to the normal moveset.
Now I don’t wanna repeat code, and I want everything organized single filed. I use a modular setup btw and the main Service handling this is called “CharacterService”. I don’t know exactly how to directly achieve the hotbar things and like not repeat the code for doing the keybinds and buttons, etc.
Right now I have a framework, but its SOOO tedious and like even someone else might get a bit confused trying to interpret what’s happening. I need the abilities to be executed parallel on Server and Client. If you also have an idea on how to properly execute an ability on client-to-server than also explain that for me please.
If you have any ideas on how to achieve this, please reply and help me
Thanks for stopping by!
There are various ways to do the things that you requested, but I can tell the most basic, simple and mostly reliable ways of doing it.
You can use RemoteEvents to fire events from LocalScripts to ServerScripts that are securely stored in ServerScriptsService to requests any action processed by the server, this can include the ability, character and the ultimate systems that you talked about.
For binding keys to actions for your player, you can use UserInputService or ContextActionService. Both of them should work perfectly if you use them correct. For the most part I think ContextActionService will work the best for you because you can bind actions to inputs that are only available under certain conditions, such as if your ultimate bar is full, your stamina bar is empty… etc. You can also make the system nearly full mobile supported by itself by using it’s own createTouchButton bool of the BindAction method, it can be customized too.
These are just the basics for a good and reliable combat/ability system Framework, you can improve it by browsing tutorials/educational contents on the DevForum or YouTube to improve it even more. The most important thing is to learn while doing these, don’t copy-paste codes except packages and try to create it yourself. This way, since you know what you are doing or have done, it will be much easier to edit and improve your system however you want.
This really helps!
I appreciate the links too and am learning more about inputting. CRAZY HOW CAS IS THIS ADVANCED LOL!
I’m going to mark this as a solution for now and if it works, ill inform you most likely
thanks for the help!
EDIT: Is there any way to use custom premade buttons for ContextAction instead of the default one. It’s a hotbar and it uses listlayouts, etc and all that to make it possible
Enabling createTouchButton simply just creates a ScreenGui with TextLabel and a ImageLabel in it if the player’s device is mobile and doesn’t have a key to the key that you binded with BindAction, like if you binded the key “G” from keyboard keys, because of mobile devices don’t have the G key a button will be created for them, it won’t be created if the binded key is a key that a mobile device has. So you can edit it’s properties just like how you would edit a normal ScreenGui’s.
It should appear like this under the PlayerGui section of the player if their device is mobile.
Nope, it’s completely fine to do so.
You can just straight up edit the position property of anything under the ContextActionGui, the button still would behave like a normal ImageButton.
But if you are going to use the auto-generated buttons for the hotbar I suggest you create a seperate gui for that since ContextAction buttons image property automatically get a circular image added by Roblox (It doesn’t break the Image that you set previously but it can be annoying if you are going to make the buttons square-ish.)
Also you can just use GetButton for getting the button instead of getting it from PlayerGui and other Methods like SetTitle, SetImage and SetPosition to easily change it’s specified properties.
Ok I see. Is there any way to customize a custom bind for a normal Button (I made, not roblox-made). I don’t want scripts to still listen to certain events when like a player is transitioning from a character to ultimate. yk what I’m trying to say?
Interestingly, this post says something weird about customizing buttons through scripting the properties:
Yes, you can do it with the second parameter of the BindAction method.
This is how it should look:
local function sayHello(actionName, inputState) --actionName: The name(string) that you binded the action with. | inputState: The state of the input (from Enum.UserInputState).
if actionName == "sayHello" and inputState == Enum.UserInputState.Begin then -- If the actionName that binded matches and the input state is begin (start activating the key) then
print("Hello!") --print hello lol
end
end
ContextActionService:BindAction("sayHello", sayHello, true, Enum.KeyCode.G) --1st param: Name of the action. | 2nd param: The function that will run. | 3rd param: Do you want to create a mobile button for it? | 4th param: Keybind, doesn't needs to be KeyCode, any input works.
It might’ve been a long description but parameters are confusing for this so I wanted to make it clear
For your system, you basically will just bind the action when the ultimate bar fills, and unbind it when player uses it (triggers the key).
Edit: The name of the action and the name of the function doesn’t necesserily needs to be same by the way, but make sure the names match if you are going to check them like I did:
That is a request that I’ve wanted too for some time but never came to life sadly, even till today the circular image still gets replaced by the Roblox’s own image when player clicks the button, the image is like 5 years old lol, and there is no way of changing it even with a loop because Roblox will change it every time player activates it.
No no mb I forgot to elaborate on my end, what a loser I am
I meant like how can you connect events to like normal buttons I made and not use Context Action?
I mean any way to connect/disconnect properly?
local Button = ... -- Path to your Image or TextButton.
local Event = ... -- Path to your RemoteEvent that you will send to server to safely process the action from server side.
Button.TouchTap:Connect(function() -- Function will trigger when your Image/TextButton is touch tapped with a touch screen enabled device (most likely a mobile device).
Event:FireServer() -- Event will be fired for any server script to catch it, you can send any arguement you would like inside the parenthesis to be used in the server script.
end)
UserInputService doesn’t have a problem to be cared actually, you can use it without any problem imo, if you meant ContextActionService they are different things
You anyways don’t need to use ContextActionService too, it was just a personal advice according to the system you wanted (and it’s easier because you don’t deal with mobile support : P ), you won’t lose anything but maybe even can gain if you use UserInputService because it has more functionality.
Yo yo yo I’m back lol
is there any way of making things organized on the server and client. Do you think I can use OOP and classes somehow and do you know an efficient method of keeping the client and server in sync?
Of course you can use both!
Both are really good and strong methods to organize your game, they might seem like hard on the first glance but it’s really not much in my opinion.