ID:1907006
 
Hey guys I am trying to do two things. I want it so that when you learn spells, you press a button and it holds out your hands, for example "D" when you hold D then you can press "1-0" to cast a spell. Is that possible? If so how would I go about doing so.
Interface - macros.
So you want to detect if a key is being held.

There are many ways to do this and a few "key handling" libraries for it.

The basic concept goes something like this:
// in macros.dms; you could also do this in a .dmf macro editor
macro
yourkey return ".key-state yourkey 1"
yourkey+up return ".key-state yourkey 0"

// e.g. replace yourkey with d, 0, 1, 2, etc.
// (this method involves a lot of copy/paste)

// in key handling.dm
client
var
key_states[0]

verb
key_state(Key as text, State as num)
set name = ".key state", instant = TRUE
key_states[Key] = State
mob.KeyState(Key, State)

mob
proc
KeyState(Key, State)

// in spell casting system
mob
var tmp/spellcasting

KeyState(Key, State)
// handle spellcasting start
if(cmptext(Key, "d"))
spellcasting = State
if(spellcasting)
src << "Spellcasting start"
else
src << "Spellcasting end"

// if spellcasting and State is true (key down),
// handle number presses
else if(spellcasting && State)
var number = text2num(Key)
if(number != null)
src << "Spell cast: [number]"

// unhandled cases go elsewhere
else ..()