-
Notifications
You must be signed in to change notification settings - Fork 0
Lua Remap Profiles Getting Started
Knowing the structure of the lua remap profiles, we can start programming the simplest one and the first.
To do this, we will use the built-in functions of the input state structure. This doesn't give you much freedom, and may not be enough to convert from a regular gamepad to an Xbox 360 gamepad, but it will be the easiest way.
All the built-in functions will be listed below, but we will only use some of them:
[state].SetAxis([axis array])Where:
- [state]: Is the name of the input state structure of the emulated controller.
- [axis array]: Is an array with the physical device axis.
[state].SetButtons([buttons array])Where:
- [state]: Is the name of the input state structure of the emulated controller.
- [buttons array]: Is an array with the physical device buttons.
[state].SetPovs([povs array])Where:
- [state]: Is the name of the input state structure of the emulated controller.
- [povs array]: Is an array with the physical device PoVs (PoVs stands for Point of Views, in other words, a D-pad).
[state].SetSliders([sliders array])Where:
- [state]: Is the name of the input state structure of the emulated controller.
- [sliders array]: Is an array with the physical device sliders (similar to axis, more details in Basic actions section).
I don't know why I put this. A feature for the future, I guess
[state].SetTouchs([touchs array])Where:
- [state]: Is the name of the input state structure of the emulated controller.
- [touchs array]: Is an array with the physical device touchpads (this are the touchpads found on a DualShock4 gamepad, more details in Advanced behavior section).
This is the most difficult part of this guide, so we won't go into too much detail, as this depends on the installed output plugins. For the moment is enough with knowing how to create one.
To create the controller we will use the Emulated global variable.
The sentence is:
[controller name] = Emulated.CreateController([controller path])Where:
- [controller name]: Is the id name you want to give to access the controller
- [controller path]: Is the id of the emulated controller (I call it path, since its structure may resemble that of a computer file system)
The next step is to connect the controller with the following sentence:
[controller name].Connect()This step is for practicality. Finally, we create a shortcut to the state of the controller, to write less and make it easier.
[state name] = [controller name].stateEntonces en ves de escribir [controller name].state, simplemente escribimos [state name]
Full statement will be something like this:
ctrl1 = Emulated.CreateController("ViGEm/Xbox")
ctrl1.Connect()
state1 = ctrl1.stateFor this case we will use the Xbox controller provided by the ViGEm output plugin (it is required to be installed for this statement to run correctly).
For this, we will use three of the above functions (SetAxis, SetButtons and SetPovs) and make the following code inside a .lua file on the Profile folder.
--Emulated controller creation
ctrl1 = Emulated.CreateController("ViGEm/Xbox")
ctrl1.Connect()
state1 = ctrl1.state
--Remap function
function Remap(input)
state1.SetAxis(input.Axis) --Emulated axis set
state1.SetPovs(input.Povs) --Emulated Povs set
state1.SetButtons(input.Buttons) --Emulated Buttons set
ctrl1.Update() --Call to update emulated controller state
endThe ctrl1.Update() sentence is required to make the emulated controller to change it's state with the values setted previously.
With this code, you can remap a controller to an emulated one without much trouble, however this will work fine for a DualShock 4. Other controllers may not remap correctly, for that reason I recommend you to see the next page of the wiki.