- Joined
- Aug 1, 2007
- Messages
- 535
Hey everybody, I am having a little trouble, I want to make an event if a player presses the spacebar. I have been looking up the code and have got somewhat lost...
First thing that happens is a trigger gets the even registered.
All looks fine here I just want to change the key_left to a spacebar... But that is not supported in the WC3 Framework so we need to add something for it.
When we look into what the TriggerRegisterPlayerKeyEventBJ is we get this...
Pretty much all the bj_KEYEVENTKEY_Whatever is just preset numbers corresponding to the keys that blizzard set, the key press\depress is the same, as seen here...
That is all pretty basic but that is a pretty closed system. I understand how making another function that allows for a fifth key could work, but lets look back at the register function, or a piece of it anyway.
What is this EVENT_PLAYER_ARROW_LEFT_DOWN? This is actually an event, and this is about where I get lost. How can I add a key if I do not understand what these "playerevent"s are?
What exactly is a ConvertPlayerEvent?
That is relatively useless...
As you can see it does seem very closed...
So does anyone know how to work around this?
Worst comes to worst I could have players use the escape key but that seems somewhat uncomfortable.
First thing that happens is a trigger gets the even registered.
JASS:
call TriggerRegisterPlayerKeyEventBJ( NameOfTrigger, SomePlayer, bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
All looks fine here I just want to change the key_left to a spacebar... But that is not supported in the WC3 Framework so we need to add something for it.
When we look into what the TriggerRegisterPlayerKeyEventBJ is we get this...
JASS:
function TriggerRegisterPlayerKeyEventBJ takes trigger trig, player whichPlayer, integer keType, integer keKey returns event
if (keType == bj_KEYEVENTTYPE_DEPRESS) then
// Depress event - find out what key
if (keKey == bj_KEYEVENTKEY_LEFT) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_LEFT_DOWN)
elseif (keKey == bj_KEYEVENTKEY_RIGHT) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_RIGHT_DOWN)
elseif (keKey == bj_KEYEVENTKEY_DOWN) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_DOWN_DOWN)
elseif (keKey == bj_KEYEVENTKEY_UP) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_UP_DOWN)
else
// Unrecognized key - ignore the request and return failure.
return null
endif
elseif (keType == bj_KEYEVENTTYPE_RELEASE) then
// Release event - find out what key
if (keKey == bj_KEYEVENTKEY_LEFT) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_LEFT_UP)
elseif (keKey == bj_KEYEVENTKEY_RIGHT) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_RIGHT_UP)
elseif (keKey == bj_KEYEVENTKEY_DOWN) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_DOWN_UP)
elseif (keKey == bj_KEYEVENTKEY_UP) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_UP_UP)
else
// Unrecognized key - ignore the request and return failure.
return null
endif
else
// Unrecognized type - ignore the request and return failure.
return null
endif
endfunction
Pretty much all the bj_KEYEVENTKEY_Whatever is just preset numbers corresponding to the keys that blizzard set, the key press\depress is the same, as seen here...
JASS:
constant integer bj_KEYEVENTKEY_DOWN = 2
constant integer bj_KEYEVENTKEY_LEFT = 0
constant integer bj_KEYEVENTKEY_RIGHT = 1
constant integer bj_KEYEVENTKEY_UP = 3
constant integer bj_KEYEVENTTYPE_DEPRESS = 0
constant integer bj_KEYEVENTTYPE_RELEASE = 1
That is all pretty basic but that is a pretty closed system. I understand how making another function that allows for a fifth key could work, but lets look back at the register function, or a piece of it anyway.
JASS:
if (keType == bj_KEYEVENTTYPE_DEPRESS) then
// Depress event - find out what key
if (keKey == bj_KEYEVENTKEY_LEFT) then
return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_LEFT_DOWN)
What is this EVENT_PLAYER_ARROW_LEFT_DOWN? This is actually an event, and this is about where I get lost. How can I add a key if I do not understand what these "playerevent"s are?
JASS:
constant playerevent EVENT_PLAYER_ARROW_LEFT_UP = ConvertPlayerEvent(262)
What exactly is a ConvertPlayerEvent?
JASS:
constant native ConvertPlayerEvent takes integer i returns playerevent
As you can see it does seem very closed...
So does anyone know how to work around this?
Worst comes to worst I could have players use the escape key but that seems somewhat uncomfortable.