| 04-14-2007, 05:33 AM | #1 |
This part doesn't work in my map, I am using dataangel's JASS code for combo keys. I don't have compile errors but nothing happens. This combokeyevent should add +1000 gold to player when he presses right+right+lleft+left. The addgold function is called from main before the InitBlizzard Function. JASS:globals gamecache udg_CONST_HandleCache = null real udg_CONST_KeyTimeout = 0 trigger gg_trg_gold = CreateTrigger( ) endglobals function H2I takes handle whichHandle returns integer return whichHandle return 0 endfunction function H2U takes handle whichHandle returns unit return whichHandle return null endfunction function Handle2Trigger takes handle whichHandle returns trigger return whichHandle return null endfunction function Handle2Timer takes handle whichHandle returns timer return whichHandle return null endfunction function Handle2Effect takes handle whichHandle returns effect return whichHandle return null endfunction function Handle2Loc takes handle whichHandle returns location return whichHandle return null endfunction function I2H takes integer whichInteger returns handle return whichInteger return null endfunction function Handle2Player takes handle whichHandle returns player return whichHandle return null endfunction function GetHandleReal takes handle whichHandle, string whichVariable returns real return GetStoredReal(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable) endfunction function SetHandleReal takes handle whichHandle, string whichVariable, real whichValue returns nothing call StoreReal(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable, whichValue) endfunction function GetHandleString takes handle whichHandle, string whichVariable returns string return GetStoredString(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable) endfunction function SetHandleString takes handle whichHandle, string whichVariable, string whichValue returns nothing call StoreString(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable, whichValue) endfunction function GetHandleInteger takes handle whichHandle, string whichVariable returns integer return GetStoredInteger(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable) endfunction function SetHandleInteger takes handle whichHandle, string whichVariable, integer whichValue returns nothing call StoreInteger(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable, whichValue) endfunction function GetHandleBoolean takes handle whichHandle, string whichVariable returns boolean return GetStoredBoolean(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable) endfunction function SetHandleBoolean takes handle whichHandle, string whichVariable, boolean whichValue returns nothing call StoreBoolean(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable, whichValue) endfunction function GetHandleHandle takes handle whichHandle, string whichVariable returns handle return I2H(GetStoredInteger(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable)) endfunction function SetHandleHandle takes handle whichHandle, string whichVariable, handle whichValue returns nothing call StoreInteger(udg_CONST_HandleCache, I2S(H2I(whichHandle)), whichVariable, H2I(whichValue)) endfunction function FlushHandleVars takes handle whichHandle returns nothing call FlushStoredMission(udg_CONST_HandleCache, I2S(H2I(whichHandle))) endfunction function ArrowKeyComboEventActions takes nothing returns nothing local eventid triggeringId = GetTriggerEventId() local trigger thisTrigger = GetTriggeringTrigger() local trigger comboTrigger = Handle2Trigger(GetHandleHandle(thisTrigger, "ComboTrigger")) local string Combo = GetHandleString(thisTrigger, "Combo") local integer comboLength = StringLength(Combo) local timer timeoutTimer = Handle2Timer(GetHandleHandle(thisTrigger, "timeoutTimer")) local real timeout = GetHandleReal(thisTrigger, "timeout") local integer keyIndex = GetHandleInteger(thisTrigger, "keyIndex") local string lastKey = null if(keyIndex == 0) then set keyIndex = 1 endif if(timeoutTimer != null and TimerGetRemaining(timeoutTimer) == 0) then set keyIndex = 1 endif if(timeoutTimer == null and comboLength > 0) then set timeoutTimer = CreateTimer() call SetHandleHandle(thisTrigger, "timeoutTimer", timeoutTimer) endif if(triggeringId == EVENT_PLAYER_ARROW_RIGHT_DOWN) then set lastKey = "R" elseif(triggeringId == EVENT_PLAYER_ARROW_LEFT_DOWN) then set lastKey = "L" elseif(triggeringId == EVENT_PLAYER_ARROW_UP_DOWN) then set lastKey = "U" elseif(triggeringId == EVENT_PLAYER_ARROW_DOWN_DOWN) then set lastKey = "D" elseif(triggeringId == EVENT_PLAYER_END_CINEMATIC) then set lastKey = "E" endif if(SubStringBJ(Combo, keyIndex, keyIndex) == lastKey) then if(keyIndex == comboLength) then set keyIndex = 1 call SetHandleHandle(thisTrigger, "timeoutTimer", null) call DestroyTimer(timeoutTimer) call TriggerExecuteBJ(comboTrigger, true) else set keyIndex = keyIndex + 1 call TimerStart(timeoutTimer, timeout, false, null) endif else set keyIndex = 1 call SetHandleHandle(thisTrigger, "timeoutTimer", null) call DestroyTimer(timeoutTimer) endif call SetHandleInteger(thisTrigger, "keyIndex", keyIndex) endfunction function TriggerRegisterArrowKeyComboEvent takes trigger whichTrigger, player whichPlayer, string Combo, real timeout returns nothing local trigger ArrowKeyTrigger = null if(Combo == null or whichPlayer == null or whichTrigger == null) then return endif set ArrowKeyTrigger = CreateTrigger() call TriggerRegisterPlayerEvent(ArrowKeyTrigger, whichPlayer, EVENT_PLAYER_ARROW_RIGHT_DOWN) call TriggerRegisterPlayerEvent(ArrowKeyTrigger, whichPlayer, EVENT_PLAYER_ARROW_LEFT_DOWN) call TriggerRegisterPlayerEvent(ArrowKeyTrigger, whichPlayer, EVENT_PLAYER_ARROW_UP_DOWN) call TriggerRegisterPlayerEvent(ArrowKeyTrigger, whichPlayer, EVENT_PLAYER_ARROW_DOWN_DOWN) call TriggerRegisterPlayerEvent(ArrowKeyTrigger, whichPlayer, EVENT_PLAYER_END_CINEMATIC) call SetHandleHandle(ArrowKeyTrigger, "ComboTrigger", whichTrigger) call SetHandleString(ArrowKeyTrigger, "Combo", Combo) call SetHandleReal(ArrowKeyTrigger, "timeout", timeout) call TriggerAddAction(ArrowKeyTrigger, function ArrowKeyComboEventActions) endfunction function Trig_gold_Actions takes nothing returns nothing call SetPlayerStateBJ(GetTriggerPlayer(),PLAYER_STATE_RESOURCE_GOLD,(GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)+1000)) endfunction function addgold takes nothing returns nothing set gg_trg_gold = CreateTrigger( ) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(0), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(1), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(2), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(3), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(4), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(5), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(6), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(7), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(8), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(9), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(10), "RRLL", udg_CONST_KeyTimeout) call TriggerRegisterArrowKeyComboEvent(gg_trg_gold, Player(11), "RRLL", udg_CONST_KeyTimeout) call TriggerAddAction(gg_trg_gold,function Trig_gold_Actions) endfunction |
