| 05-21-2006, 04:46 PM | #1 |
I built a trigger that works fine, but I want it improved. The triggers purpose is to allow any player in the map to repick a hero and remove the current hero. It's a multi-hero map, so the trigger I have will just find the last purchases hero and repick that one. What I would like to do is change it to Create a dialog for the triggering player only with buttons named as the heros. Then they can click on which one they want to pick. My problem is that I'm not good with adding events into a trigger and I'm not sure if there is a way to make local dialogs. Here is my current trigger with most of the useless stuff removed so that it doesn't take up too much space. I just left in what needs to be there. JASS:function RepickBool takes nothing returns boolean return IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO) endfunction function Repick_Actions takes nothing returns nothing local player p=GetTriggerPlayer() local group g=CreateGroup() local unit u local integer i local integer j=0 local location L local location heroSelectSpawn = GetUnitLoc(gg_unit_u000_0310) local integer playerIndex = GetConvertedPlayerId(p) local integer teamNumber = ( ( ( ( playerIndex - 1 ) - ModuloInteger(( playerIndex - 1 ), 3) ) / 3 ) + 1 ) local force F=GetPlayersAllies(ConvertedPlayer(9+teamNumber)) if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)>=600 then call GroupEnumUnitsOfPlayer(g,p,Condition(function RepickBool)) loop set u=FirstOfGroup(g) exitwhen u==null set i=GetUnitUserData(u) if i>j then set j=i endif call GroupRemoveUnit(g,u) endloop if j>0 then set u=udg_heroList[j] call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)-600) set udg_repick[playerIndex] = true set L = PolarProjectionBJ(heroSelectSpawn, 110.00, 30.00) call CreateUnitAtLocSaveLast( p, 'hC28', L, bj_UNIT_FACING ) call RemoveLocation(L) call SetUnitUserData( GetLastCreatedUnit(), j ) call PanCameraToTimedLocForPlayer( p, heroSelectSpawn, 0.50 ) call PingMinimapLocForForce( F, heroSelectSpawn, 4.00 ) call RemoveUnit( udg_heroList[j] ) else call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"You don't have a hero to repick.") endif else call DisplayTextToPlayer(p,0,0,"You need 600 gold to repick.") endif call DestroyGroup(g) call RemoveLocation(heroSelectSpawn) call DestroyForce(F) set F=null set p=null set g=null set u=null set L=null set heroSelectSpawn=null endfunction //=========================================================================== function InitTrig_Repick takes nothing returns nothing local integer i=0 set gg_trg_Repick = CreateTrigger( ) loop exitwhen i>8 call TriggerRegisterPlayerChatEvent( gg_trg_Repick, Player(i), "-repick", true ) set i=i+1 endloop call TriggerAddAction( gg_trg_Repick, function Repick_Actions ) endfunction Thanks for any suggestions. --edit I found local dialogs and I've gotten this much as to test it. JASS:local dialog repick if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)>=600 then call GroupEnumUnitsOfPlayer(g,p,Condition(function RepickBool)) if CountUnitsInGroup(g)>0 then set repick=DialogCreate() call DialogSetMessage(repick,"Which hero") call DialogAddButton(repick,"test1",1) call DialogAddButton(repick,"test2",2) call DialogAddButton(repick,"test3",3) call DialogDisplay(p,repick,true) endif |
| 05-22-2006, 06:03 AM | #2 |
Ok, so I did some work on it. I couldn't find a good way for it to work using locals because I couldn't pass the button array to the next function. So I went with globals. The dialogs show up just fine, but nothing happens when I click a button like its supposed to. It just takes me back to the game. Here is my code. JASS:function RepickBool takes nothing returns boolean return IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO) endfunction function Repick_Actions takes nothing returns nothing local player p=GetTriggerPlayer() local group g=CreateGroup() local unit u local integer i=1 local integer j local location L local location heroSelectSpawn = GetUnitLoc(gg_unit_u000_0310) local integer playerIndex = GetConvertedPlayerId(p) local integer teamNumber = ( ( ( ( playerIndex - 1 ) - ModuloInteger(( playerIndex - 1 ), 3) ) / 3 ) + 1 ) local force F=GetPlayersAllies(ConvertedPlayer(9+teamNumber)) local boolexpr b=Condition(function RepickBool) if SubStringBJ(GetEventPlayerChatString(),1,7)=="-repick" then if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)>=600 then call GroupEnumUnitsOfPlayer(g,p,b) if CountUnitsInGroup(g)>0 then set udg_heroRepick[playerIndex]=DialogCreate() call DialogClear(udg_heroRepick[playerIndex]) call DialogSetMessage(udg_heroRepick[playerIndex],"Which Hero") loop set u=FirstOfGroup(g) exitwhen u==null set udg_repickButton[i]=DialogAddButton(udg_heroRepick[playerIndex],GetUnitName(u),i) set i=i+1 call GroupRemoveUnit(g,u) endloop set udg_repickButton[i]=DialogAddButton(udg_heroRepick[playerIndex],"Cancel",i) call DialogDisplay(p,udg_heroRepick[playerIndex],true) else call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"You don't have a hero to repick.") endif else call DisplayTextToPlayer(p,0,0,"You need 600 gold to repick.") endif return else call BJDebugMsg("test1") call GroupEnumUnitsOfPlayer(g,p,b) loop set u=FirstOfGroup(g) set j=GetUnitUserData(u) exitwhen u==null or GetClickedButton()==udg_repickButton[i] call GroupRemoveUnit(g,u) set i=i+1 endloop if u!=null then call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)-600) set udg_repick[playerIndex] = true set L = PolarProjectionBJ(heroSelectSpawn, 110.00, 30.00) call CreateUnitAtLocSaveLast( p, 'hC28', L, bj_UNIT_FACING ) call RemoveLocation(L) call SetUnitUserData( GetLastCreatedUnit(), j ) call PanCameraToTimedLocForPlayer( p, heroSelectSpawn, 0.50 ) call PingMinimapLocForForce( F, heroSelectSpawn, 4.00 ) if udg_heroSpirit[j]!=null then call RemoveUnit( udg_heroSpirit[j] ) endif call RemoveUnit( udg_heroList[j] ) set udg_totalHeros[playerIndex] = udg_totalHeros[playerIndex] - 1 else call BJDebugMsg("test2") endif endif call DestroyGroup(g) call DestroyBoolExpr(b) call RemoveLocation(heroSelectSpawn) call DestroyForce(F) set F=null set b=null set p=null set g=null set u=null set L=null set heroSelectSpawn=null endfunction //=========================================================================== function InitTrig_Repick takes nothing returns nothing local integer i=0 set gg_trg_Repick = CreateTrigger( ) loop exitwhen i>8 call TriggerRegisterPlayerChatEvent( gg_trg_Repick, Player(i), "-repick", true ) call TriggerRegisterDialogEvent( gg_trg_Repick, udg_heroRepick[i+1] ) set i=i+1 endloop call TriggerAddAction( gg_trg_Repick, function Repick_Actions ) endfunction |
| 05-22-2006, 10:30 AM | #3 |
To pass locals into other functions, use a gamecache and H2I with I2Dialogue |
| 05-23-2006, 04:09 AM | #4 |
Well I already remade it using globals, and as far as I can tell, it should work fine like this. The dialog with buttons displays just fine, but the clicked buttons aren't triggering anything. I just need help finding why it doesn't fire. I even put the debugmsg at the first line and it never shows, so I'm guessing that maybe my event is wrong. |
