HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Creating a dialog array, resetting a trigger, then adding events to it

02-23-2007, 10:07 PM#1
Mythic Fr0st
this code I have, does a whole bunch of things, but function Alignment_Options, and the end part are really the things needed to show you,

The problem hasn't occured yet, as I only test single player, but my problem Im thinking I will have is because of these lines

Collapse JASS:
    call DialogSetMessageBJ(udg_Alignment_Dialog[pn], "|cffff0000Select your alignment|r")
    call DialogAddButtonBJ(udg_Alignment_Dialog[pn], "|cfffff000Become Righteous|r")
    set udg_Alignment_Dialog_Button[0] = GetLastCreatedButtonBJ()
    call DialogAddButtonBJ(udg_Alignment_Dialog[pn], "|cffff0000Become Unholy|r")
    set udg_Alignment_Dialog_Button[1] = GetLastCreatedButtonBJ()
    call DialogDisplayBJ(true, udg_Alignment_Dialog[pn], p)
    call BJDebugMsg("This trigger should work, and you should see an alignment dialog, however if it doesnt or you dont see the dialog, email me at [email][email protected][/email]")
    call ResetTrigger(gg_trg_SelectAlignmentDialog)
    call TriggerRegisterDialogEventBJ(gg_trg_SelectAlignmentDialog, udg_Alignment_Dialog[pn])
    call TriggerAddAction(gg_trg_SelectAlignmentDialog, function Alignment_Option)

its a dialog array, it adds the event that you click it to SelectAlignmentDialog (A trigger), now before it does that it resets that trigger, so im thinking, if soon as someone purchases a hero, this is going to run, and IF someone purchases a hero while someone else is, cause of ResetTrigger() its going to screw that up... Im wondering if theres an easy way to fix this

What the code does is, opens a dialog with 2 options, Become Righteous, and Become Unholy (Alignment), then sets a String to that, so you can view it, and a few other minor things, so im wondering what I should do

Is this going to be a problem?, will I have to make 11 triggers store it in a trigger variable, then add the events / and so on, to those triggers, should I not use an array dialog?

Any Idea's

(CODE BELOW)

Hidden information:
Collapse JASS:
globals
unit array udg_Hero
rect gg_rct_Rect_035
boolean array udg_Attack_Mastery
boolean array udg_Magic_Mastery
boolean array udg_Strength_Mastery
unit array udg_Backpack_Unit
unittype array udg_Backpack_Type
boolean array udg_Player_Has_Bought_Hero
dialog array udg_Alignment_Dialog
trigger gg_trg_SelectAlignmentDialog
button array udg_Alignment_Dialog_Button
integer array udg_Alignment_Level
boolean array udg_Alignment_Bool
string array udg_Alignment_String
trigger gg_trg_Move_To_Base
endglobals

function sell_c1 takes nothing returns boolean
 local boolean c1 = GetUnitTypeId(GetTriggerUnit()) == 'n00J'
    return c1
endfunction

function rem_hs takes nothing returns nothing
    call RemoveUnit(GetEnumUnit())
endfunction

function Alignment_Option takes nothing returns nothing
 local integer pn = GetPlayerId(GetTriggerPlayer())+1
 local string array al
 local integer i = 0
 local boolean array b
 local string array d
    set d[0] = GetPlayerName(Player(pn-1))+" has decided to become Righteous"
    set d[1] = GetPlayerName(Player(pn-1))+" has decided to become Unholy"
    set b[0] = true
    set b[1] = false
    set al[0] = "You are Righteous, [Level "+I2S(udg_Alignment_Level[pn])+"]"
    set al[1] = "You are Unholy, [Level "+I2S(udg_Alignment_Level[pn])+"]"
    loop
        exitwhen i > 1
            if udg_Alignment_Dialog_Button[i] == GetClickedButtonBJ() then
                set udg_Alignment_Bool[i] = b[i]
                set udg_Alignment_String[i] = al[i]
                call DisplayTextToForce(GetPlayersAll(), "|c00008B"+d[i]+"|r") 
            endif
            set i = i + 1
    endloop
endfunction

//            if udg_Alignment_Dialog_Button[i] == GetClickedButtonBJ() then
//    set udg_Alignment_Dialog_Button[1] = GetLastCreatedButtonBJ()
                  

function sell takes nothing returns nothing
 local unit u = GetTriggerUnit()
 local unit s = GetSoldUnit()
 local integer pn = GetPlayerId(GetOwningPlayer(s))+1
 local player p = Player(pn-1)
 local rect r = gg_rct_Rect_035
 local group g = GetUnitsOfPlayerAndTypeId(p, 'n000')
 local location loc = GetUnitLoc(s)
 local integer x = GetRandomInt(0,1)
    set udg_Hero[pn] = s
    call ForGroup(g, function rem_hs)
    call DisplayTextToForce(GetPlayersAll(), "|c9400D3"+GetPlayerName(p)+" has just bought the hero "+GetUnitName(s)+"|r")
    call DisplayTextToPlayer(p, 0, 0, "|c8B4513The default stat that has been set is \"attack\", you can change this by typing -strength, or -magic|r")
    set udg_Attack_Mastery[pn] = true
    set udg_Strength_Mastery[pn] = false
    set udg_Magic_Mastery[pn] = false
    call AdjustPlayerStateBJ(400, p, PLAYER_STATE_RESOURCE_GOLD)
    set udg_Backpack_Unit[pn] = CreateUnit(p, udg_Backpack_Type[x], GetRectCenterX(r), GetRectCenterY(r), 270.00)
    call UnitAddTypeBJ(UNIT_TYPE_MECHANICAL, GetSoldUnit())
    call SelectUnitForPlayerSingle(s, p)
    set udg_Player_Has_Bought_Hero[pn] = true
    if GetUnitTypeId(s) == 'N00U' then
        call UnitAddAbility(s, 'A01G')
    endif
    call DialogSetMessageBJ(udg_Alignment_Dialog[pn], "|cffff0000Select your alignment|r")
    call DialogAddButtonBJ(udg_Alignment_Dialog[pn], "|cfffff000Become Righteous|r")
    set udg_Alignment_Dialog_Button[0] = GetLastCreatedButtonBJ()
    call DialogAddButtonBJ(udg_Alignment_Dialog[pn], "|cffff0000Become Unholy|r")
    set udg_Alignment_Dialog_Button[1] = GetLastCreatedButtonBJ()
    call DialogDisplayBJ(true, udg_Alignment_Dialog[pn], p)
    call BJDebugMsg("This trigger should work, and you should see an alignment dialog, however if it doesnt or you dont see the dialog, email me at [email][email protected][/email]")
    call ResetTrigger(gg_trg_SelectAlignmentDialog)
    call TriggerRegisterDialogEventBJ(gg_trg_SelectAlignmentDialog, udg_Alignment_Dialog[pn])
    call TriggerAddAction(gg_trg_SelectAlignmentDialog, function Alignment_Option)
endfunction

//===========================================================================
function InitTrig_Move_To_Base takes nothing returns nothing
    set gg_trg_Move_To_Base = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Move_To_Base, EVENT_PLAYER_UNIT_SELL )
    call TriggerAddCondition(gg_trg_Move_To_Base, Condition(function sell_c1))
    call TriggerAddAction(gg_trg_Move_To_Base, function sell)
endfunction