ID:2195928
 
Code:
#define TAP_THRESHOLD 2.5

#define BIND_NORTH 1
#define BIND_WEST 2
#define BIND_SOUTH 3
#define BIND_EAST 4

client
var
list/bind_keys
list/key_binds
list/bind_taps
list/bind_time

last_key_press
last_key_release
last_key

list/default_keybinds = list("W"=BIND_NORTH, "North"=BIND_NORTH,"A"=BIND_WEST, "West"=BIND_WEST, "S"=BIND_SOUTH, "South"=BIND_SOUTH,"D"=BIND_EAST, "East"=BIND_EAST)
list/default_keybind_sz = 4

New()
InitKeybinds(default_keybinds,default_keybind_sz)
..()


verb
keyPress(key as text)
set instant = 1
set hidden = 1
var/bind = bind_keys[key]
if(bind&&!key_binds[bind]++)
var/time = world.time, taps = 1, tdelta = time-bind_time[bind]
if(last_key_press==key&&last_key_release==key&&tdelta<=TAP_THRESHOLD)
taps = ++bind_taps[bind]
else
bind_taps[bind] = 1
bind_time[bind] = world.time
. = BindPress(bind,taps,time,tdelta)
last_key_press = key
last_key = key

keyRelease(key as text)
set instant = 1
set hidden = 1
var/bind = bind_keys[key], num
if(bind&&!(num = --key_binds[bind]))
var/time = world.time
. = BindRelease(bind,bind_taps[bind],time,time-bind_time[bind])
else if(num<0)
key_binds[bind] = 0
last_key_release = key
last_key = 0

proc
BindPress(bind,taps,time,delta)
set waitfor = 0
mob.onBindPress(bind,taps,time,delta)

BindRelease(bind,taps,time,delta)
set waitfor = 0
mob.onBindRelease(bind,taps,time,delta)

InitKeybinds(list/default,number)
bind_keys = default
key_binds = new/list(number)
bind_taps = new/list(number)
bind_time = new/list(number)

for(var/count in 1 to number)
key_binds[count] = 0
bind_taps[count] = 1
bind_time[count] = -1#INF

ClearKeybinds()
var/num = key_binds.len
var/time = world.time

for(var/count in 1 to num)
if(key_binds[count])
key_binds[count] = 0
BindRelease(count,bind_taps[count],time,time-bind_time[count])
bind_taps[count] = 1
bind_time[count] = time
last_key = null
last_key_press = null
last_key_release = null

North()
South()
East()
West()
Southeast()
Northeast()
Southwest()
Northwest()
Center()

mob
var/tmp
move_keys = 0
move_dir = 0
move_delay = 0.25

last_move = -1#INF
next_move = 0
proc
onBindPress(bind,taps,time,delta)
switch(bind)
if(BIND_NORTH)
move_keys |= NORTH
if(move_dir&SOUTH) move_dir &= ~SOUTH
move_dir |= NORTH
if(BIND_SOUTH)
move_keys |= SOUTH
if(move_dir&NORTH) move_dir &= ~NORTH
move_dir |= SOUTH
if(BIND_EAST)
move_keys |= EAST
if(move_dir&WEST) move_dir &= ~WEST
move_dir |= EAST
if(BIND_WEST)
move_keys |= WEST
if(move_dir&EAST) move_dir &= ~EAST
move_dir |= WEST
if("z") switchTarget()

onBindRelease(bind,taps,time,delta)
switch(bind)
if(BIND_NORTH)
move_keys &= ~NORTH
if(move_keys&SOUTH) move_dir |= SOUTH
move_dir &= ~NORTH
if(BIND_SOUTH)
move_keys &= ~SOUTH
if(move_keys&NORTH) move_dir |= NORTH
move_dir &= ~SOUTH
if(BIND_EAST)
move_keys &= ~EAST
if(move_keys&WEST) move_dir |= EAST
move_dir &= ~EAST
if(BIND_WEST)
move_keys &= ~WEST
if(move_keys&EAST) move_dir |= WEST
move_dir &= ~WEST

ControlLoop()
set waitfor = 0
if(!client) return
var/client/c = client
while(client==c)
if(move_dir)
if(next_move<=world.time)
glide_size = TILE_SIZE/move_delay*world.tick_lag // changed from TILE_WIDTH to TILE_SIZE
if(step(src,move_dir))
last_move = world.time
next_move = last_move+move_delay
sleep(world.tick_lag)

Login()
ControlLoop()
..()


Problem description:

Ter13 provided me with this excellent bit of code for keyboard control. Problem is, upon testing it a bit on a server, one of the other players couldn't move. I'm having a bit of trouble debugging it, because I'm not sure where to start. I'm assuming the key's aren't getting setup properly.

This was resolved. The issue was they werent updated to the Beta.