HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Hero Selection System

08-24-2008, 12:05 PM#1
Vestras
Well, here is a HSS I made for my Single Player RPG.
It isn't very funny on the screenshot, so I recommend you to check it out :)

MUI: Should it? :P
vJASS: Couldn't live without..
JASS/GUI: I think it's GUI... :)
Systems used: None! (Only a texttag library, not anything fancy)

Code:
Collapse JASS:
library HSS requires TextTag

// Configurable globals
globals
    private constant real Interval        = 0.01
    // The timer interval.
    private constant real Turn            = 5
    // The real the current hero is turned every Interval seconds.
    private constant rect ChooseRect      = gg_rct_Hero_Selection
    // The region where the hero selection takes place.
    private constant rect CreateRect      = gg_rct_Hero_Selection
    // The region where the hero is created.
    private constant integer Rows         = 10
    // The number of rows in the multiboard.
    // I'm sorry, but you can't edit the columns. :(
    private constant real HeroWidth       = 16
    // The width of the hero name spot.
    private constant real DescWidth       = 60
    // The width of the hero description spot.
    private constant string Title         = "Hero Selection"
    // The title of the multiboard.
    constant real Height                  = 10
    // The height of floating text.
    constant integer PlayerID             = 0
    // The player you want this to work for. (Remember, in JASS the players are minus one, eg.: Player 0 == Player 1, Player 2 == Player 3 etc.)
    private constant string CreateFX      = "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl"
    // The creation fx.
    private constant string Attach        = "origin"
    // Where CreateFX is attached to the unit.
endglobals

// Necessary globals
globals
     unit        current
     real           HSSX
     real           HSSY
     real          CHSSX
     real          CHSSY
     real         facing
     integer array    id
     string array   name
     string array   desc
     string array  fdesc
     integer        size
     integer          CS
     integer         max
     texttag        Text
     private trigger  T0
     private trigger  T1
     private trigger  T2
     private trigger  T3
     private trigger  T4
     
       // Multiboard stuff...
        private multiboard    Multiboard
        private multiboarditem  HeroText
        private multiboarditem  DescText
endglobals

private function TurnActs takes nothing returns nothing
    set facing=GetUnitFacing(current)+Turn
    call SetUnitFacing(current,facing)
    call PanCameraTo(HSSX,HSSY)
endfunction

private function Pick takes nothing returns nothing
    local integer id=GetUnitTypeId(current)
    local unit d
    call RemoveUnit(current)
        call PanCameraTo(CHSSX,CHSSY)
        set d=CreateUnit(Player(PlayerID),id,CHSSX,CHSSY,facing)
        call SelectUnit(d,true)
        call DestroyEffect(AddSpecialEffectTarget(CreateFX,d,Attach))
            // And now, leak cleaning;
            call DestroyTrigger(T0)
            call DestroyTrigger(T1)
            call DestroyTrigger(T2)
            call DestroyTrigger(T3)
            call DestroyTrigger(T4)
            call DestroyTextTag(Text)
            call DestroyMultiboard(Multiboard)
            set T0=null
            set T1=null
            set T2=null
            set T3=null
            set T4=null
            set Text=null
            set Multiboard=null
            set HeroText=null
            set DescText=null
            // And last, but not least, our love;
            set current=null
    set d=null
endfunction

private function Down takes nothing returns nothing
   if CS!=0 then
    set CS=CS-1
    call MultiboardSetItemValue(HeroText,name[CS])
    call MultiboardSetItemValue(DescText,desc[CS])
        call RemoveUnit(current)
        call DestroyTextTag(Text)
          set Text=FadingTextSingle(Player(PlayerID),fdesc[CS],255,255,255,HSSX,HSSY,0,9999999,9999999)
            set current=CreateUnit(Player(PlayerID),id[CS],HSSX,HSSY,facing)
                call SetCameraTargetController(current,0,0,true)
            call PanCameraTo(HSSX,HSSY)
        call UnitAddAbility(current,'Aloc')
        call PauseUnit(current,true)
   endif
endfunction

private function Up takes nothing returns nothing
   if CS!=(max-1) then
    set CS=CS+1
    call MultiboardSetItemValue(HeroText,name[CS])
    call MultiboardSetItemValue(DescText,desc[CS])
        call RemoveUnit(current)
        call DestroyTextTag(Text)
          set Text=FadingTextSingle(Player(PlayerID),fdesc[CS],255,255,255,HSSX,HSSY,0,9999999,9999999)
            set current=CreateUnit(Player(PlayerID),id[CS],HSSX,HSSY,facing)
                call SetCameraTargetController(current,0,0,true)
            call PanCameraTo(HSSX,HSSY)
        call UnitAddAbility(current,'Aloc')
        call PauseUnit(current,true)
   endif
endfunction

private function Setup takes nothing returns nothing
    local integer i=0
    set Multiboard=CreateMultiboard()
    call MultiboardSetColumnCount(Multiboard,5)
    call MultiboardSetRowCount(Multiboard,Rows)
    call MultiboardSetTitleText(Multiboard,Title)
    set HeroText=MultiboardGetItem(Multiboard,1,0)
    set DescText=MultiboardGetItem(Multiboard,4,0)
            call MultiboardSetItemWidth(HeroText,HeroWidth)
            call MultiboardSetItemWidth(DescText,DescWidth)
            loop
                exitwhen i>Rows
                    call MultiboardSetItemStyle(MultiboardGetItem(Multiboard,i,0),true,false)
                    call MultiboardSetItemStyle(MultiboardGetItem(Multiboard,i,1),true,false)
                    call MultiboardSetItemStyle(MultiboardGetItem(Multiboard,i,2),true,false)
                    call MultiboardSetItemStyle(MultiboardGetItem(Multiboard,i,3),true,false)
                    call MultiboardSetItemStyle(MultiboardGetItem(Multiboard,i,4),true,false)
                    call MultiboardSetItemStyle(MultiboardGetItem(Multiboard,i,5),true,false)
                set i=i+1
            endloop
            set i=0
        call MultiboardSetItemValue(HeroText,name[0])
        call MultiboardSetItemValue(DescText,desc[0])
        call MultiboardDisplay(Multiboard,true)
endfunction

function AddHero takes integer ID, string NAME, string DESCRIPTION, string FLOATDESC, boolean SETCURR returns unit
    set id[size]=ID
    set name[size]=NAME
    set desc[size]=DESCRIPTION
    set fdesc[size]=FLOATDESC
        if SETCURR==true then
            if current!=null then
                call RemoveUnit(current)
            endif
            set current=CreateUnit(Player(PlayerID),id[size],HSSX,HSSY,0)
            call SetCameraTargetController(current,0,0,true)
            call PanCameraTo(HSSX,HSSY)
            call UnitAddAbility(current,'Aloc')
            call PauseUnit(current,true)
              set Text=FadingTextSingle(Player(PlayerID),FLOATDESC,255,255,255,HSSX,HSSY,0,9999999,9999999)
        endif
        set size=size+1
        set max=max+1
        return current
endfunction

//===========================================================================
function InitTrig_HeroSelectionSystem takes nothing returns nothing
    set T0=CreateTrigger()
    set T1=CreateTrigger()
    set T2=CreateTrigger()
    set T3=CreateTrigger()
    set T4=CreateTrigger()
    call TriggerRegisterTimerEvent(T1,Interval,true)
    call TriggerAddAction(T1,function TurnActs)
    set HSSX=GetRectCenterX(ChooseRect)
    set HSSY=GetRectCenterY(ChooseRect)
    set CHSSX=GetRectCenterX(CreateRect)
    set CHSSY=GetRectCenterY(CreateRect)
    call CreateFogModifierRect(Player(0),FOG_OF_WAR_VISIBLE,ChooseRect,false,false)
    set size=0
    set CS=0
    set max=0
    set current=null

        call TriggerRegisterTimerEvent(T0,0,false)
        call TriggerAddAction(T0,function Setup)
        call TriggerRegisterPlayerKeyEventBJ(T2,Player(0),bj_KEYEVENTTYPE_DEPRESS,bj_KEYEVENTKEY_DOWN)
        call TriggerAddAction(T2,function Down)
        call TriggerRegisterPlayerKeyEventBJ(T3,Player(0),bj_KEYEVENTTYPE_DEPRESS,bj_KEYEVENTKEY_UP)
        call TriggerAddAction(T3,function Up)
        call TriggerRegisterPlayerEventEndCinematic(T4,Player(0))
        call TriggerAddAction(T4,function Pick)
endfunction

endlibrary

Documentation:
Collapse JASS:
    1) Copy the trigger "TextTag" into your map.
    2) Copy the trigger "HeroSelectionSystem" into your map.
    3) Done!
    
        Note: requires vJASS.
        
            ~Vestras.

        Pros:
            - A new type of hero selection system.
            - Simple, yet effective.
            
        Cons:
            - Can only work for one player. (Not necessarily player red, just only one player.)
            - No leaks or bugs detected so far, if you find some, please report.
    
    Notes:
    
        - This system can only work for one player.
        - This system is ideal for any single player RPG which wants to add a characteristic feeling.
        - This system is used in my single player RPG.
        
            ~Vestras.

    1) To switch between Heroes, press the up and down arrow keys.
    2) To select a Hero, press the ESC/Escape key.
    3) Info, name and a short description is found at the Hero's position and in the Multiboard.
    
            ~Vestras.

Screenshot:
Click image for larger version

Name:	wc3scrnshot082408135351xs9.jpg
Views:	245
Size:	81.7 KB
ID:	46042

Enjoy, and credit me if you use it :)
Oh yeah, it isn't really "ultimate", it's just a name :)
EDIT: You can now check it out!
Attached Images
File type: jpgwc3scrnshot082408135351xs9.jpg (81.7 KB)
Attached Files
File type: w3xUltimate Hero Selection System.w3x (22.6 KB)
08-24-2008, 10:12 PM#2
Vexorian
You need to upload that screenshot as attachment.
10-15-2008, 12:12 AM#3
moyack
I don't like the fact that this only works for singleplayer maps... therefore it's not a system due to that limitation.
10-15-2008, 01:15 PM#4
emjlr3
where I don't agree with you assessment that its not a system (it clearly is) - having this only work for 1 player reduces its usage to basically zero
11-14-2008, 10:17 PM#5
Kwah
Single Player selection systems are so easy to brute code that creating a system seems rather extravagant.
11-19-2008, 01:10 AM#6
Pyrogasm
As this works only in SP, this is definitely not a system. If you update it to make it work for all players, then this could be acceptable, but until then no. This could be a sample if you don't want to make it for all players.

Following the new rules, if you don't update or respond to this thread within 7 days, this will be graveyarded.
11-19-2008, 05:33 AM#7
Vestras
Quote:
Originally Posted by Pyrogasm
As this works only in SP, this is definitely not a system. If you update it to make it work for all players, then this could be acceptable, but until then no. This could be a sample if you don't want to make it for all players.

Following the new rules, if you don't update or respond to this thread within 7 days, this will be graveyarded.

Then go sample.