FOnline Development > Questions and Answers
New Dude looking at expanding keybinds
(1/1)
RedStranger:
Hey guys,
I was looking at how I could keybind an activation for plastics from inventory, Throw said activated plastics from inventory, and then activate a detonator from inventory.
I subsequently fell down the Dev rabbithole. 4 hours in, I have downloaded a client, a mapper and server. And am trying to get it all operational to see what lies deeper down.
I have found 2/3 of what i needed for my original objective in the Itempid_h. But now I am looking for the Script?Command? that throws items from inventory based on PID. And is permissable to be keybinded clientside if that is a thing. I hope a version of the grenade/item hexthrowing might be adapted to a different pid reference but ive no idea where to look. Also how do i make .Fosb readable, notepad does not help very much.
For reference I'm playing on the Fonline : Reloaded server if that makes a difference.
Any info you would care to share would be greatly appriciated
-Stranger
Vice Dice:
Hello, do not try to read .fosb files, those are precompiled script files, basically binaries for angelscript, they are not there for human reading. Scripts you are supposed to work with are .fos files.
If you are using reloaded sdk, hotkey system should be already there before you, files are "client_keybinds_h.fos" and "client_keybinds.fos".
To use this system you would have to create own class that will represent your hotkey and define its "void Exec" function, its basically what happens when the hotkey is triggered.
Like this :
--- Code: ---class StopCritterBind : BaseBind
{
void Exec()
{
array<uint> actions;
uint cnt = GetChosenActions(actions);
if(actions.length() > 0)// && actions[0] == CHOSEN_MOVE)
{
uint[] action = { CHOSEN_NONE, 0, 0, 0, 0, 0, 0 };
SetChosenActions(action);
}
}
};
--- End code ---
The code above defines a hotkey that will stop player character when invoked, do this in "client_keybinds_h.fos"
After you're done with the class, go to "client_keybinds.fos" and find there a function like this :
--- Code: ---bool InitBinds()
--- End code ---
This function supposed to initialize hotkeys on game startup, it should be already linked in startup script to call, so all you would have to do is to create instance of your previously created hotkey class and put it into cached hotkeys. Since i've used critter stop hotkey, let's see how it gets initialized :
--- Code: ---bool InitStopCritterBind()
{
string@ s = GetConfigValue(CONFIG_FILE, "Bindings", "StopMove");
StopCritterBind bnd;
return TryAddBind(s, bnd);
}
--- End code ---
So, the GetConfigValue is another amazing tool that lets you easily read config values from files that are preloaded in "config_file.fos", but don't think about config management too much this time. Arguments of this function are in order of appearance - target config filename, section name, key name. The config file name is FOnline2238.cfg by default, but to be sure, check definition of CONFIG_FILE macro. Okay, so this is how an example hotkey entry in config would look like :
--- Code: ---[Bindings]
StopMove=Shift S
--- End code ---
Make sure your hotkey is located under the proper section of configuration, those are [] bracketed strings, key-value pair is considered to be a part of some section until next section is encountered in the file, from top to down. This example would make the hotkey to be triggerred when Shift + S are both pressed, which would lead the Exec function to be called, which stops the critter. So make sure your own hotkey will follow the same rules to be able to parse it properly from config file. After reading the config string, create your hotkey instance the same way as the stop critter bind is created in above example code and then call TryAddBind with your config string and the hotkey object itself, like this :
--- Code: ---bool InitSomeHotkey()
{
string@ s = GetConfigValue(CONFIG_FILE, "Your_Section", "Your_Hotkey");
YourHotkeyClass bnd;
return TryAddBind(s, bnd);
}
--- End code ---
Then just make a call to this function in InitBinds the same way as other binds initializers are called, this should do the trick.
The hotkey config string parser uses a text to keycode convertion table that maps human readable strings into decimal keyboard keys for system usage, for list of available strings to map, check the "void InitKeyMap()" in same "client_keybinds.fos" file. Just make sure you wont conflict with other hotkeys, or not, up to you.
As for the code, you probably would have to use SetChosenActions for activation and explode commands, as for throwing it... RunServerScriptUnsafe to call server side function as a client, which will handle the throw procedure, something like this :
--- Code: --- RunServerScriptUnsafe("unsafe_client@unsafe_DropOne", item.Id, 0, 0, "", null);
--- End code ---
params are
--- Code: ---scriptfile@unsafe_funcname, int, int, int, string, array<int>
--- End code ---
server will get the signal and call the function you specify here, with arguments you put there, this is where throw would happen, or you might just find the hexthrow code and re-use it for throwing it. For hex throw reference - check "hexthrow.fos" if there is any. Hope this helps, sorry if i forgot something.
RedStranger:
Thank you for the time and effort posing this reply Vice Dice.
I know have a better idea of what to look for, I did find a hexthrow.fos but i cant make heads or tails from it. I understand that it runs a script to determine if its a throwing weapon or not, and then use either throwingweaponmode or weapon.item.mode. I've tried guessing at the keybind (hexthrow=H | 209, itemthrow=H | 209, Throwing=H | 209) but so far no luck. Ill keep looking at it.
Navigation
[0] Message Index
Go to full version