| 01-11-2007, 12:52 AM | #1 |
So i made a trigger so that when you type "-Battle", a timer starts. When the timer expires, 2 heros are randomly chosen to fight at the arena box. I havent made the "what happens after death" thing, but how is this? I tried using the "Wrap" for the timers, but idk if ive done it right. JASS:function Move_BattleHeros takes nothing returns nothing call SetUnitPosition( GetEnumUnit(), GetRectCenterX(gg_rct_Battle_Arena), GetRectCenterY(gg_rct_Battle_Arena) ) call DisplayTextToForce( udg_All_Users, "3...2...1..." ) call TriggerSleepAction( 2 ) call PauseUnit( GetEnumUnit(), false) call DisplayTextToForce( udg_All_Users, "Go!" ) endfunction function Move_BattleHeros_Cond takes nothing returns boolean return IsUnitType( GetFilterUnit(), UNIT_TYPE_HERO ) == true endfunction function Start_Move takes nothing returns nothing local group g = CreateGroup() call ForGroup( GetUnitsOfPlayerMatching( GetEnumPlayer(), Condition(function Move_BattleHeros_Cond) ), function Move_BattleHeros ) endfunction function Battle_After_60 takes timer t returns nothing local force for = udg_All_Users //////////////////////////////////////////////// //Heres what All_Users is: //GetPlayersMatching(Condition(function Trig_SetUp_AllUsers)) //function Trig_SetUp_AllUsers takes nothing returns boolean // return GetPlayerSlotState(GetFilterPlayer()) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(GetFilterPlayer()) == MAP_CONTROL_USER //endfunction ///////////////////////////////////////////////// local player ran1 = ForcePickRandomPlayer(for) local player ran2 = ForcePickRandomPlayer(for) call PauseGame(true) call DisplayTextToForce( udg_All_Users, "The battle has begun!" ) call DisableTrigger( gg_trg_Score ) call DisableTrigger( gg_trg_Hero_Kills_Slayer ) call DisableTrigger( gg_trg_Kill_Self_Slayer ) call DisableTrigger( gg_trg_Hero_Deaths_Slayer ) if ran1 != ran2 then call ForForce( for, function Start_Move ) else call DisplayTextToForce( udg_All_Users, "Only 1 player was chosen. He will automatically recieve 400 gold." ) call SetPlayerState( ran1, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( ran1, PLAYER_STATE_RESOURCE_GOLD ) + 400 ) call PauseGame(false) endif call PauseTimer(t) call DestroyTimer(t) set for = null set ran1 = null set ran2 = null endfunction function Battle_After_60_Timer takes nothing returns nothing call Battle_After_60(GetExpiredTimer()) endfunction function Trig_Battle_Time_Actions_Timer takes timer t returns nothing local timerdialog td = CreateTimerDialog(t) call TimerDialogSetTitle( td, "Battle Countdown" ) call TimerDialogDisplay( td, true ) call DisplayTextToForce( udg_All_Users, udg_PlayerNames[GetConvertedPlayerId(GetTriggerPlayer())] " has requested a battle. 2 players will be randomly chosen after 60 seconds for the battle." ) call TimerStart( t, 60, false, function Battle_After_60_Timer ) set td = null endfunction function Trig_Battle_Time_Actions takes nothing returns nothing call Trig_Battle_Time_Actions_Timer(CreateTimer()) endfunction //=========================================================================== function InitTrig_Battle_Time takes nothing returns nothing local integer a = 0 set gg_trg_Battle_Time = CreateTrigger( ) call DisableTrigger( gg_trg_Battle_Time ) loop call TriggerRegisterPlayerChatEvent( gg_trg_Battle_Time, Player(a), "-battle", true ) set a = a + 1 exitwhen a == 11 endloop call TriggerAddAction( gg_trg_Battle_Time, function Trig_Battle_Time_Actions ) endfunction I also tried something new with the event, dunno if its good or not. |
| 01-11-2007, 07:00 AM | #2 |
What exactly is the problem? |
| 01-11-2007, 08:36 PM | #3 |
He says "...how is this?" so I think he's just seeing if it's good so far. EDIT: Your last function I think that exitwhen's are suppose to be right after the "loop" in a bottom line, like: loop exitwhen |
| 01-11-2007, 09:05 PM | #4 |
It doesn't matter where the exitwhen is, it's usually for the convenience of the coder to put them exactly WHEN you want the loop to end. The code has a few flaws --
|
| 01-11-2007, 09:46 PM | #5 | |
Ty Dusk :) +rep, but a question on the Quote:
|
| 01-11-2007, 10:56 PM | #6 |
> In function "Start_Move" you leak a group and its pointer. Two groups actually (the one he created and the one he used). The right code would be JASS:function Start_Move takes nothing returns nothing local group g = GetUnitsOfPlayerMatching( GetEnumPlayer(), Condition(function Move_BattleHeros_Cond) ) call ForGroup( g, function Move_BattleHeros ) call DestroyGroup(g) set g = null endfunction JASS:function Start_Move takes nothing returns nothing local boolexpr b = Condition(function Move_BattleHeros_Cond) local group g = CreateGroup() call GroupEnumUnitsOfPlayer(g, GetEnumPlayer(), b) call DestroyBoolExpr(b) call ForGroup(g, function Move_BattleHeros) call DestroyGroup(g) set g = null endfunction > In function "Battle_After_60" you leak a force. If you are talking about local force for = udg_All_Users then that's not a leak, he doesn't create a new force, he only makes "for" point to the same thing udg_All_Users points to. And Battle_After_60_Timer can probably be merged with Battle_After_60... |
| 01-11-2007, 11:05 PM | #7 | |
Quote:
You wouldn't have to destroy it if you would use it again later. Although, why create your own force when you can just use the BJ var, bj_FORCE_ALL_PLAYERS? Just a thought. :P |
| 01-11-2007, 11:18 PM | #8 |
Dunno, my friend started the map, im just trying to fix it up |
| 01-12-2007, 11:40 PM | #9 |
Ok, tested this today, and it bugs horribly....someone help JASS:function Move_BattleHeros takes nothing returns nothing local unit a = GetEnumUnit() call SetUnitPosition( a, GetRectCenterX(gg_rct_Battle_Arena), GetRectCenterY(gg_rct_Battle_Arena) ) call EnableTrigger( gg_trg_End_Of_Battle ) call DisplayTextToPlayer( GetEnumPlayer(),0,0, "3...2...1..." ) call TriggerSleepAction( 2 ) call PauseUnit( a, false) call DisplayTextToPlayer( GetEnumPlayer(),0,0, "Go!" ) set a = null endfunction function Move_BattleHeros_Cond takes nothing returns boolean return IsUnitType( GetFilterUnit(), UNIT_TYPE_HERO ) == true endfunction function Start_Move takes nothing returns nothing local boolexpr b = Condition(function Move_BattleHeros_Cond) local group g = CreateGroup() call GroupEnumUnitsOfPlayer(g, GetEnumPlayer(), b) call DestroyBoolExpr(b) call ForGroup(g, function Move_BattleHeros) call DestroyGroup(g) set g = null endfunction function Battle_After_60 takes timer t returns nothing local force for = udg_All_Users local player ran1 = ForcePickRandomPlayer(for) local player ran2 = ForcePickRandomPlayer(for) call PauseGame(true) call DisplayTextToForce( udg_All_Users, "The battle has begun!" ) call DisableTrigger( gg_trg_Score ) call DisableTrigger( gg_trg_Hero_Kills_Slayer ) if ran1 != ran2 then call ForForce( for, function Start_Move ) else call DisplayTextToForce( udg_All_Users, "Only " + GetPlayerName(ran1) + " has been chosen for the battle. He will automatically recieve 400 gold." ) call SetPlayerState( ran1, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( ran1, PLAYER_STATE_RESOURCE_GOLD ) + 400 ) call PauseGame(false) endif call PauseTimer(t) call DestroyTimer(t) set for = null endfunction function Battle_After_60_Timer takes nothing returns nothing call Battle_After_60(GetExpiredTimer()) endfunction function Trig_Battle_Time_Actions_Timer takes timer t returns nothing local timerdialog td = CreateTimerDialog(t) call TimerDialogSetTitle( td, "Battle Countdown" ) call TimerDialogDisplay( td, true ) call DisplayTextToForce( udg_All_Users, udg_PlayerNames[GetConvertedPlayerId(GetTriggerPlayer())] + " has requested a battle. 2 players will be randomly chosen after 60 seconds for the battle." ) call TimerStart( t, 60, false, function Battle_After_60_Timer ) call PolledWait( 60 ) call DestroyTimerDialog(td) set td = null endfunction function Trig_Battle_Time_Actions takes nothing returns nothing call Trig_Battle_Time_Actions_Timer(CreateTimer()) endfunction //=========================================================================== function InitTrig_Battle_Time takes nothing returns nothing local integer a = 0 set gg_trg_Battle_Time = CreateTrigger( ) call DisableTrigger( gg_trg_Battle_Time ) loop call TriggerRegisterPlayerChatEvent( gg_trg_Battle_Time, Player(a), "-battle", true ) set a = a + 1 exitwhen a == 11 endloop call TriggerAddAction( gg_trg_Battle_Time, function Trig_Battle_Time_Actions ) endfunction Part 2 JASS:function Trig_End_Of_Battle_Conditions takes nothing returns boolean return IsUnitType(GetKillingUnit(), UNIT_TYPE_HERO) == true and IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true endfunction function Trig_End_Of_Battle_Actions takes nothing returns nothing local unit a = GetKillingUnit() local player pa = GetOwningPlayer(a) call DisplayTextToForce( udg_All_Users, "The Battle is over! " + udg_PlayerNames[GetConvertedPlayerId(GetOwningPlayer(GetKillingUnitBJ()))] + " has slain " + udg_PlayerNames[GetConvertedPlayerId(GetOwningPlayer(GetDyingUnit()))] + " for 400 gold!" ) call StartSound( gg_snd_monster_kill ) call KillSoundWhenDone( gg_snd_monster_kill ) call SetUnitPosition( a, GetStartLocationX(GetPlayerStartLocation(pa)), GetStartLocationY(GetPlayerStartLocation(pa)) ) call PauseGame( false ) call EnableTrigger( gg_trg_Keep_People_Out_Of_Arena ) call EnableTrigger( gg_trg_Remove_Heroes ) call EnableTrigger( gg_trg_Hero_Kills_Slayer ) call DisableTrigger( gg_trg_Heroes_Cant_Leave ) call DisableTrigger( GetTriggeringTrigger() ) call TriggerSleepAction( 5.00 ) call DisplayTextToForce( udg_All_Users, "You must wait 3 minutes before typing ''Battle'' again." ) call StartSound(bj_questSecretSound) call KillSoundWhenDone( gg_snd_monster_kill ) call PolledWait( 180.00 ) call EnableTrigger( gg_trg_Battle_Time ) set a = null set pa = null endfunction //=========================================================================== function InitTrig_End_Of_Battle takes nothing returns nothing set gg_trg_End_Of_Battle = CreateTrigger( ) call DisableTrigger( gg_trg_End_Of_Battle ) call TriggerRegisterAnyUnitEventBJ( gg_trg_End_Of_Battle, EVENT_PLAYER_UNIT_DEATH ) call TriggerAddCondition( gg_trg_End_Of_Battle, Condition( function Trig_End_Of_Battle_Conditions ) ) call TriggerAddAction( gg_trg_End_Of_Battle, function Trig_End_Of_Battle_Actions ) endfunction |
| 01-13-2007, 12:10 AM | #10 |
> and it bugs horribly Could you be more specific? What bugs, what happens and what's supposed to happen? |
| 01-13-2007, 12:49 AM | #11 |
Sry, Well, it doesnt move the 2 heros to the arena rect, and it moves everyone's hero to the center of the map and the game never unpauses |
| 01-13-2007, 03:40 PM | #12 |
Your problem is likely here -- JASS:function Battle_After_60 takes timer t returns nothing local force for = udg_All_Users local player ran1 = ForcePickRandomPlayer(for) local player ran2 = ForcePickRandomPlayer(for) call PauseGame(true) call DisplayTextToForce( udg_All_Users, "The battle has begun!" ) call DisableTrigger( gg_trg_Score ) call DisableTrigger( gg_trg_Hero_Kills_Slayer ) if ran1 != ran2 then call ForForce( for, function Start_Move ) else call DisplayTextToForce( udg_All_Users, "Only " + GetPlayerName(ran1) + " has been chosen for the battle. He will automatically recieve 400 gold." ) call SetPlayerState( ran1, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( ran1, PLAYER_STATE_RESOURCE_GOLD ) + 400 ) call PauseGame(false) endif call PauseTimer(t) call DestroyTimer(t) set for = null endfunction This is why I recommend using the BJ var. Also, what IF in your testing ran1 == ran2? Then NOTHING happens. You should add an else BJDebugMsg() to tell you if that happens, otherwise you don't know if its working or not. |
| 01-13-2007, 04:14 PM | #13 |
> Make sure that your global force is properly initialized. What do you mean by that? |
| 01-13-2007, 04:44 PM | #14 |
Like, make sure the correct players are in the force, etc. If you didn't initialize the force properly, then noone's hero would be moved. |
