| 08-23-2008, 12:51 AM | #1 |
To help along my learning of JASS/vJASS, I decided to make a small, simple king-of-the-hill-like arena. So far everything has been working fine (whether it's optimal will be figured out as I go along). Last thing on my list is working on the victory trigger (couldn't tell by the topic title, could you?). Just about everything for it is finished, too. But it's a king-of-the-hill like map. What happens is when the unit gains his "king of the hill" status, a countdown timer starts. If nobody else claims the title in the given time, the game ends. So far that's what I have. I'm not sure on how to factor in another unit throwing off the current "king of the hill." I don't need to be given exactly what to put down for the code, just a prod in the right direction. Victory:scope Victory globals private unit adventurer private timerdialog remaining endglobals //=========================================================================== function Conditions takes nothing returns boolean return GetUnitTypeId(GetTriggerUnit()) == 'n000' endfunction private function Finish takes nothing returns nothing call EndGame(true) endfunction private function Actions takes nothing returns nothing local timer t = NewTimer() local unit obelisk = GetDyingUnit() set remaining = CreateTimerDialog(t) set adventurer = GetKillingUnit() call CreateUnit( GetOwningPlayer(adventurer), 'n000', GetUnitX(obelisk), GetUnitY(obelisk), 0 ) call RemoveUnit(obelisk) call TimerDialogSetTitle(remaining, "Time until " +GetPlayerName(GetOwningPlayer(adventurer))+ " wins.") call TimerDialogDisplay(remaining, true) call TimerStart(t, 10.0, false, function Finish) set t = null set remaining = null endfunction //=========================================================================== public function InitTrig takes nothing returns nothing set gg_trg_Victory = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Victory, EVENT_PLAYER_UNIT_DEATH ) call TriggerAddCondition( gg_trg_Victory, Condition( function Conditions ) ) call TriggerAddAction( gg_trg_Victory, function Actions ) endfunction endscope |
| 08-23-2008, 01:29 AM | #2 |
Wait so do you mean the code on how one would replace another unit, or how to do it? If the latter and if I understood you right, couldn't you just remove the timer that is currently ticking away and basically repeat the trigger for the new unit (not sure though since can't tell how a unit replaces another on top of the hill)? |
| 08-23-2008, 01:37 AM | #3 |
What happens in that when the obelisk is killed, control in granted to the killing player. The player then has to defend the obelisk for a certain amount of time (it's been 10s for single player testing) in order to win. I just need to know how I'd modify the above code to factor in if the obelisk is destroyed during the countdown, restarting the timer for the new killer. Is really really as simple as removing the timer when the obelisk is destroyed again? Pardon me. My thoughts are jumbled, and I don't think I'm making any sense. I'm wondering if I'd need to use a timer to detect if the obelisk is destroyed during the time frame. For some reason that doesn't seem like the best option. Edited because: Added second paragraph. |
| 08-23-2008, 04:03 AM | #4 |
Timer shoud be pub global. JASS:private function Actions takes nothing returns nothing local timer t = ExtractTimerFromGlobal() local unit obelisk = GetDyingUnit() set remaining = ExtractDialogFromGlobal() set adventurer = GetKillingUnit() call CreateUnit( GetOwningPlayer(adventurer), 'n000', GetUnitX(obelisk), GetUnitY(obelisk), 0 ) call RemoveUnit(obelisk) call TimerDialogSetTitle(remaining, "Time until " +GetPlayerName(GetOwningPlayer(adventurer))+ " wins.") call TimerDialogDisplay(remaining, true) call TimerStart(t, 10.0, false, function Finish) set t = null set remaining = null endfunction If you call this function again it will overwrite settings and refresh countdown. Best way to do this - create struct of timer and dialog and attach it to unit. |
| 08-23-2008, 06:56 PM | #5 |
Ah I see now. As DioD said, you pretty much need to make a timer and make sure it's reachable (through a global or whatever) so you can destroy it and repeat it through the new killing unit. It's really simple concept wise, you should get it right away. |
| 08-23-2008, 08:20 PM | #6 |
I figured it out this morning. <3 Thanks for the help. Here's what the functional code looks like: Victory:scope Victory globals private unit adventurer private timerdialog remaining private timer victory_countdown private boolean victory_check = false //To check if the victory countdown has been initialized or not. endglobals //=========================================================================== function Conditions takes nothing returns boolean return GetUnitTypeId(GetTriggerUnit()) == 'n000' endfunction private function Finish takes nothing returns nothing call EndGame(true) endfunction private function Actions takes nothing returns nothing local unit obelisk = GetDyingUnit() if victory_check == false then set victory_countdown = NewTimer() set remaining = CreateTimerDialog(victory_countdown) set adventurer = GetKillingUnit() call CreateUnit( GetOwningPlayer(adventurer), 'n000', GetUnitX(obelisk), GetUnitY(obelisk), 0 ) call RemoveUnit(obelisk) call TimerDialogSetTitle(remaining, "Time until " +GetPlayerName(GetOwningPlayer(adventurer))+ " wins.") call TimerDialogDisplay(remaining, true) call TimerStart(victory_countdown, 10., false, function Finish) set remaining = null set adventurer = null set obelisk = null set victory_check = true elseif victory_check == true then call ReleaseTimer(victory_countdown) set victory_countdown = NewTimer() set adventurer = GetKillingUnit() call CreateUnit( GetOwningPlayer(adventurer), 'n000', GetUnitX(obelisk), GetUnitY(obelisk), 0 ) call RemoveUnit(obelisk) call TimerDialogSetTitle(remaining, GetPlayerName(GetOwningPlayer(adventurer))+ " wins in:") call TimerDialogDisplay(remaining, true) call TimerStart(victory_countdown, 60., false, function Finish) set remaining = null set adventurer = null set obelisk = null endif endfunction //=========================================================================== public function InitTrig takes nothing returns nothing set gg_trg_Victory = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Victory, EVENT_PLAYER_UNIT_DEATH ) call TriggerAddCondition( gg_trg_Victory, Condition( function Conditions ) ) call TriggerAddAction( gg_trg_Victory, function Actions ) endfunction endscope |
