Remap Joypad Action Key

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
DWRL
Red Slime
Posts: 35
Joined: Wed Jan 15, 2020 2:26 am
Location: Germany
Contact:

Remap Joypad Action Key

Post by DWRL »

Pretty much as the title says.

Right now on a joypad with xbox layout the button 'A' is [use]. Is there any way to change this to 'B' ?

- It doesn't need to work everywhere, only for activating NPCs on the map. In fact, I don't care if it breaks menus or battles.
- I'm quite willing to mess with scancode.hsi if need be.

All the best,
Daniel
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Re: Remap Joypad Action Key

Post by TMC »

Builtin features to remap gamepad and keyboard keys are in the pipeline, and sorely needed. I wanted to finish that pretty soon, not sure when. But until then you need to script it.
Do you want A to stop acting as 'Use', or do you not care? It's possible to disable a builtin key by calling "suspend player" and waiting until the key is up:

Code: Select all

while (key is pressed(joy:A)) do(
  suspend player
  wait
  resume player
)
To make B act as Use you can use a script to watch for joy:B and if so use an NPC. I adapted https://rpg.hamsterrepublic.com/ohrrpgc ... _a_use_key

Code: Select all

plotscript, use npc on keypress, begin
  if (player is suspended || hero is walking(me)) then (exit script)
  if (keypress(joy:B)) then, begin
    variable (x, y, npc)
    x := hero x(me)
    y := hero y(me)
    # Find the tile in front of the hero
    switch (hero direction(me)) do, begin
      case (up)    y -= 1
      case (down)  y += 1
      case (left)  x -= 1
      case (right) x += 1
    end
    npc := npc at spot(x, y)
    if (npc) then (use npc(npc))
  end
end
User avatar
DWRL
Red Slime
Posts: 35
Joined: Wed Jan 15, 2020 2:26 am
Location: Germany
Contact:

Re: Remap Joypad Action Key

Post by DWRL »

Thank you TMC, that was fast :D
Post Reply