| 12-22-2007, 02:47 PM | #1 |
I'm making the map that can rematch when end and starting a new game again but sometime triggers will run 2 times at once (like create 2 units at a time). I think it must be something wrong about trigger but I don't know so I tried to destroy trigger everytime when it finishes but seem that's not a point.... JASS:function DelayBeforeStartGame takes nothing returns nothing local timer t=GetExpiredTimer() local group g=CreateGroup() local unit tmpu local integer i=GetInteger("GameData","Delay") if i > 0 then call PlaySoundBJ(gg_snd_BattleNetTick) call DebugMsg("|cffFF0000"+I2S(i)+"|r") call SetInteger("GameData","Delay",i-1) else call PauseTimer(t) call DestroyTimer(t) call SetTimeOfDayScalePercentBJ( 300.00 ) call PlaySoundBJ(gg_snd_ArrangedTeamInvitation) call ClearTextMessages() call DebugMsg("|cffFFFF00GAME START!") call GroupEnumUnitsInRect(g,GetPlayableMapRect(),Condition(function PausedUnitsFilter)) loop set tmpu=FirstOfGroup(g) exitwhen tmpu == null call PauseUnit(tmpu,false) call GroupRemoveUnit(g,tmpu) endloop call FlushKey("GameData","Delay") endif call DestroyGroup(g) set t=null set g=null set tmpu=null endfunction function NoSubMode takes nothing returns nothing local timer t=CreateTimer() call DisplayTimedTextToForce(GetPlayersAll(),10.,"|cffFF80C0No sub mode|r |cff00FF40has been selected.|r") call SetInteger("GameData","Delay",5) call TimerStart(t,1.,true,function DelayBeforeStartGame) set t=null call DestroyTrigger(GetTriggeringTrigger()) endfunction function SelectSubMode takes nothing returns nothing if GetEventPlayerChatString() == "-no" then call DestroyTrigger(GetTriggeringTrigger()) call NoSubMode() endif call SetBoolean("GameData","SubModeSelected",true) endfunction function DeBugTimerB takes nothing returns nothing local string s=I2S(H2I(GetExpiredTimer())) call DestroyTimer(GetExpiredTimer()) if GetBoolean("GameData","SubModeSelected") == false then call DestroyTrigger(GetTrigger(s,"DebugB")) call DestroyTrigger(GetTrigger(s,"DebugB.2")) call NoSubMode() endif call FlushTable(s) endfunction function StartSelectingSubMode takes nothing returns nothing local trigger t=CreateTrigger() local timer tm=CreateTimer() call DisplayTimedTextToForce(GetPlayersAll(),10.,"|cff00FFFFPlease wait for|r " + udg_PlayerName[1] + " |cff00FFFFselecting the sub mode.|r") call SetBoolean("GameData","SubModeSelected",false) call TriggerRegisterPlayerChatEvent(t,Player(0),"-no",true) call TriggerAddAction(t,function SelectSubMode) call SetHandle(I2S(H2I(tm)),"DebugB",t) call SetHandle(I2S(H2I(tm)),"DebugB.2",GetTriggeringTrigger()) call TimerStart(tm,10.,false,function DeBugTimerB) set t=null set tm=null endfunction function NewbieMode takes nothing returns nothing local unit tmpu local integer i=0 call DisplayTimedTextToForce(GetPlayersAll(),10.,"|cff8080FFNewbie Mode|r |cff00FF40has been selected.|r") set udg_West_Main_Hall=CreateUnitAtLoc(Player(4),'h000',GetRectCenter(gg_rct_West_Castle_Newbie),270.) set udg_East_Main_Hall=CreateUnitAtLoc(Player(10),'h000',GetRectCenter(gg_rct_East_Castle_Newbie),270.) call SetCameraBoundsToRect(gg_rct_RectNewbiePlayableMap) loop exitwhen i > 10 if i == 1 or i == 2 or i == 3 or i == 4 or i == 7 or i == 8 or i == 9 or i == 10 then if GetPlayerController(ConvertedPlayer(i)) == MAP_CONTROL_USER and GetPlayerSlotState(ConvertedPlayer(i)) == PLAYER_SLOT_STATE_PLAYING then call SetPlayerState(ConvertedPlayer(i),PLAYER_STATE_RESOURCE_FOOD_CAP,0) if i == 1 or i == 2 or i ==3 or i == 4 then set tmpu=CreateUnitAtLoc(ConvertedPlayer(i),'e003',GetRectCenter(gg_rct_SpawnWorkerWestNewbie),0.) call PauseUnit(tmpu,true) call SetPlayerTechMaxAllowed(GetOwningPlayer(tmpu),'n000',3) elseif i == 7 or i == 8 or i == 9 or i == 10 then set tmpu=CreateUnitAtLoc(ConvertedPlayer(i),'e003',GetRectCenter(gg_rct_SpawnWorkerEastNewbie),180.) call PauseUnit(tmpu,true) endif call SelectUnitForPlayerSingle(tmpu,ConvertedPlayer(i)) call PanCameraToTimedForPlayer(ConvertedPlayer(i),GetUnitX(tmpu),GetUnitY(tmpu),0.) endif endif set i=i+1 endloop call FogEnable(false) call FogMaskEnable(false) call DestroyTrigger(GetTriggeringTrigger()) set tmpu=null endfunction function AdvancedMode takes nothing returns nothing local unit tmpu local integer i=0 call DisplayTimedTextToForce(GetPlayersAll(),10.,"|cff8080FFAdvanced Mode|r |cff00FF40has been selected.|r") set udg_West_Main_Hall=CreateUnitAtLoc(Player(4),'h000',GetRectCenter(gg_rct_West_Castle_Region),270.) set udg_East_Main_Hall=CreateUnitAtLoc(Player(10),'h000',GetRectCenter(gg_rct_East_Castle_Region),270.) call SetCameraBoundsToRect(gg_rct_RectPlayableMap) loop exitwhen i > 10 if i == 1 or i == 2 or i == 3 or i == 4 or i == 7 or i == 8 or i == 9 or i == 10 then if GetPlayerController(ConvertedPlayer(i)) == MAP_CONTROL_USER and GetPlayerSlotState(ConvertedPlayer(i)) == PLAYER_SLOT_STATE_PLAYING then call SetPlayerState(ConvertedPlayer(i),PLAYER_STATE_RESOURCE_FOOD_CAP,15) if i == 1 or i == 2 or i ==3 or i == 4 then set tmpu=CreateUnitAtLoc(ConvertedPlayer(i),'opeo',GetRectCenter(gg_rct_SpawnWorkerWest),0.) call PauseUnit(tmpu,true) call SetPlayerTechMaxAllowed(GetOwningPlayer(tmpu),'n000',3) elseif i == 7 or i == 8 or i == 9 or i == 10 then set tmpu=CreateUnitAtLoc(ConvertedPlayer(i),'opeo',GetRectCenter(gg_rct_SpawnWorkerEast),180.) call PauseUnit(tmpu,true) endif call SelectUnitForPlayerSingle(tmpu,ConvertedPlayer(i)) call PanCameraToTimedForPlayer(ConvertedPlayer(i),GetUnitX(tmpu),GetUnitY(tmpu),0.) endif endif set i=i+1 endloop set tmpu=null call DestroyTrigger(GetTriggeringTrigger()) endfunction function SelectMode takes nothing returns nothing call ClearTextMessages() if GetEventPlayerChatString() == "-am" then call AdvancedMode() elseif GetEventPlayerChatString() == "-nm" then call NewbieMode() endif call SetBoolean("GameData","MainModeSelected",true) call StartSelectingSubMode() call DestroyTrigger(GetTriggeringTrigger()) endfunction function DeBugTimerA takes nothing returns nothing local string s=I2S(H2I(GetExpiredTimer())) call DestroyTimer(GetExpiredTimer()) if GetBoolean("GameData","MainModeSelected") == false then call DestroyTrigger(GetTrigger(s,"DebugA")) call DestroyTrigger(GetTrigger(s,"DebugA.2")) call NewbieMode() call StartSelectingSubMode() endif call FlushTable(s) endfunction function StartSelectingMode takes nothing returns nothing local trigger t=CreateTrigger() local timer tm=CreateTimer() call DisplayTimedTextToForce(GetPlayersAll(),15.,"|cff00FF00Please wait for|r " + udg_PlayerName[1] + " |cff00FF00selecting the mode.|r") call SetBoolean("GameData","MainModeSelected",false) call TriggerRegisterPlayerChatEvent(t,Player(0),"-am",true) call TriggerRegisterPlayerChatEvent(t,Player(0),"-nm",true) call TriggerAddAction(t,function SelectMode) call SetHandle(I2S(H2I(tm)),"DebugA",t) call SetHandle(I2S(H2I(tm)),"DebugA.2",GetTriggeringTrigger()) call TimerStart(tm,15.,false,function DeBugTimerA) set t=null set tm=null endfunction and When I want to rematch just type -rematch and the trigger will run JASS:call StartSelectingMode() I have tired about this......... What I did wrong ? For someone who helps me I will give you a rep and adding you in my map credit too. |
| 12-23-2007, 12:47 AM | #2 |
well, dynamic triggers sometimes sucks, so we should try to avoid them as much as possible. I don't know.... I would do this system in other way like... one permanent trigger that detects the input and a global boolean which is set to true if the -rematch command is started. Something like this: JASS:function SelectMode takes nothing returns nothing if udg_ActivateRematch then // here you play with the entered string and do your stuff. endif endfunction function StopMode takes nothing return nothing set udg_ActivateRematch = false call DestroyTimer(GetExpiredTimer()) endfunction function Trig_Rematch_Actions takes nothing returns nothing set udg_ActivateRematch = true call TimerStart(CreateTimer(), 15., false, function StopMode) endfunction //=========================================================================== function InitTrig_Rematch takes nothing returns nothing local trigger t = CreateTrigger( ) call TriggerRegisterPlayerChatEvent(t,Player(0),"-am",true) call TriggerRegisterPlayerChatEvent(t,Player(0),"-nm",true) call TriggerAddAction(t, function SelectMode) set gg_trg_Rematch = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_Rematch, Player(0), "-rematch", true ) call TriggerAddAction( gg_trg_Rematch, function Trig_Rematch_Actions ) set t = null endfunction |
| 12-23-2007, 06:12 AM | #3 |
Thanks moyack, last night I was thinking about making triggers to permanent too, seem it's the better way. even though I really want to know issue why sometime it runs 2 times at once. thanks for helping me +rep. EDIT : OK I got it because I quickly rematch before the timer detroyed so sometime triggers will call function 2 or 3 times at once. |
