- Joined
- Oct 24, 2012
- Messages
- 6,545
hello i was just looking to see if this is as optimal as possible. if it isnt plz give me some better ways to do things thanks.
JASS:
scope HeroAbilitySelection initializer Ability_Selection
globals
trigger trg_AbilitySelection
private integer array lumberCost
private integer array itemIDS
private integer array abilityIDS
private unit array abilitySellers
private integer array itemIntDataArray
private integer array itemGroups
endglobals
private function addItemsToStockLoop takes integer p, integer i, integer start, integer end returns nothing
loop
exitwhen start > end
call AddItemToStock( abilitySellers[((p*4)+i)], itemIDS[start], 1, 1)
set start = start + 1
endloop
endfunction
private function addItemsToStock takes integer p, integer Loop returns nothing
local integer i
local integer start
local integer end
set i = Loop/11
set start = i*11
if start > 32 then
set end = 39
else
set end = start + 10
endif
call addItemsToStockLoop( p, i, start, end)
endfunction
private function getAbilityGroup takes integer Loop returns integer
local integer L = 1
local integer e
loop
exitwhen L > 13
if Loop < itemGroups[L] then
return L
endif
set L = L + 1
endloop
return L
endfunction
private function addNewAbility takes integer p, integer Loop returns nothing
local integer i
local integer L
local integer e
set L = getAbilityGroup( Loop)
set e = (itemGroups[L]-1)
set i = itemGroups[(L-1)]
loop
exitwhen i > e
set itemIntDataArray[i] = 0
set i = i + 1
endloop
set itemIntDataArray[Loop] = 1
call addItemsToStock( p, Loop)
endfunction
private function Actions takes nothing returns nothing
local integer p = GetPlayerId( GetTriggerPlayer())
local integer start
local integer end
local item titem = GetManipulatedItem()
local integer Loop = 0
local integer abilvl
local integer id = GetItemTypeId( titem)
call text( "ability selection actions works", 0)
call RemoveItem( titem)
loop
exitwhen Loop > 39
if id == itemIDS[Loop] then
set abilvl = GetUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
if itemIntDataArray[Loop] == 1 then
if abilvl == 0 then
call UnitAddAbility( Selected_Hero_Player, abilityIDS[Loop])
call addNewAbility( p, Loop)
elseif abilvl == 100 then
call text( "Congradulations u Reached the Max Lvl for this Ability", p)
set itemIntDataArray[Loop] = 0
call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER)+lumberCost[Loop]))
call addItemsToStock( p, Loop)
else
call IncUnitAbilityLevel( Selected_Hero_Player, abilityIDS[Loop])
call addItemsToStock( p, Loop)
endif
elseif itemIntDataArray[Loop] == 0 then
call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_LUMBER)+lumberCost[Loop]))
call text( "Sry u can't buy this item", p)
call addItemsToStock( p, Loop)
endif
endif
set Loop = Loop + 1
endloop
set titem = null
endfunction
private function destroyItems takes nothing returns nothing
call RemoveItem( GetEnumItem())
endfunction
private function settingLumberCosts takes nothing returns nothing
local integer Loop = 0
local unit u = gg_unit_n01M_0127
local integer maxLumber = 1000000 // 1 mil
local integer itemLumber
local rect r = gg_rct_Delete_Items
loop
exitwhen Loop > 39
call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER, maxLumber)
call AddItemToStock( u, itemIDS[Loop], 1, 1)
call IssueNeutralImmediateOrderById( Player(11), u, itemIDS[Loop])
call RemoveItemFromStock( u, itemIDS[Loop])
set itemLumber = GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER)
set lumberCost[Loop] = maxLumber - itemLumber
set Loop = Loop + 1
endloop
call EnumItemsInRect( r, null, function destroyItems)
call ShowUnit( u, false )
call RemoveUnit( u)
set u = null
set r = null
endfunction
private function itemToStockSetup takes nothing returns nothing
local integer Loop = 0
local integer i = 0
local integer ids = 0
local integer loopE = ((40*2)-1) // number of abilities * number of players in map
loop
exitwhen Loop > loopE
call AddItemToStock( abilitySellers[i], itemIDS[ids], 1, 1)
set itemIntDataArray[Loop] = 1
if ids == 10 or ids == 21 or ids == 32 then
set i = i + 1
elseif ids == 39 then
set i = i + 1
set ids = -1
endif
set ids = ids + 1
set Loop = Loop + 1
endloop
endfunction
private function preloadAbilities takes nothing returns nothing
local unit u
local integer Loop = 0
set u = CreateUnit( Player(11), 'hfoo', 0, 0, 0)
call ShowUnit( u, false)
loop
exitwhen Loop > 39
call UnitAddAbility( u, abilityIDS[Loop])
call UnitRemoveAbility( u, abilityIDS[Loop])
set Loop = Loop + 1
endloop
call RemoveUnit( u)
set u = null
endfunction
private function hash takes nothing returns nothing
local integer Loop = 0
loop
exitwhen Loop > 39
call SaveBoolean( conditionHash, itemIDS[Loop], 0, true)
set Loop = Loop + 1
endloop
endfunction
private function startup takes nothing returns nothing //this whole thing just sets the data in arrays
set itemIDS[0] = 'I004' // Divine Shield ITEM ID
set itemIDS[1] = 'I005' // Mana Shield ITEM ID
set itemIDS[2] = 'I006' // Mirror Image ITEM ID
set itemIDS[3] = 'I007' // Wind Walk ITEM ID
set itemIDS[4] = 'I00E' // Volcano ITEM ID
set itemIDS[5] = 'I00F' // Earthquake ITEM ID
set itemIDS[6] = 'I00G' // Stampede ITEM ID
set itemIDS[7] = 'I00H' // Flame Strike ITEM ID
set itemIDS[8] = 'I00O' // Shadow Strike ITEM ID
set itemIDS[9] = 'I00P' // Storm Bolt ITEM ID
set itemIDS[10] = 'I00Q' // Soul Burn ITEM ID
set itemIDS[11] = 'I00R' // Bash ITEM ID
set itemIDS[12] = 'I00S' // Critical Strike ITEM ID
set itemIDS[13] = 'I00T' // Spiked Carapace ITEM ID
set itemIDS[14] = 'I00U' // Cleaving Attack ITEM ID
set itemIDS[15] = 'I00X' // Death Coil ITEM ID
set itemIDS[16] = 'I00Y' // Holy Light ITEM ID
set itemIDS[17] = 'I00Z' // Death Pact ITEM ID
set itemIDS[18] = 'I010' // Life Drain ITEM ID
set itemIDS[19] = 'I008' // Avatar ITEM ID
set itemIDS[20] = 'I009' // Metamorphosis ITEM ID
set itemIDS[21] = 'I00A' // Vengeance ITEM ID
set itemIDS[22] = 'I00I' // Tornado ITEM ID
set itemIDS[23] = 'I00J' // Bladestorm ITEM ID
set itemIDS[24] = 'I00K' // Incinerate ITEM ID
set itemIDS[25] = 'I00L' // Immolation ITEM ID
set itemIDS[26] = 'I00M' // Impale ITEM ID
set itemIDS[27] = 'I00N' // Carrion Swarm ITEM ID
set itemIDS[28] = 'I00V' // Sleep ITEM ID
set itemIDS[29] = 'I00W' // Charm ITEM ID
set itemIDS[30] = 'I011' // Fan of Knives ITEM ID
set itemIDS[31] = 'I012' // Thunder Clap ITEM ID
set itemIDS[32] = 'I013' // Howl of Terror ITEM ID
set itemIDS[33] = 'I001' // Chain Lightning ITEM ID
set itemIDS[34] = 'I000' // Forked Lightning ITEM ID
set itemIDS[35] = 'I002' // Blink ITEM ID
set itemIDS[36] = 'I003' // Mass Teleport ITEM ID
set itemIDS[37] = 'I00B' // Blizzard ITEM ID
set itemIDS[38] = 'I00C' // Rain of Fire ITEM ID
set itemIDS[39] = 'I00D' // Starfall ITEM ID
set abilityIDS[0] = 'A017' // Divine Shield ITEM ID
set abilityIDS[1] = 'A02D' // Mana Shield ITEM ID
set abilityIDS[2] = 'A006' // Mirror Image ITEM ID
set abilityIDS[3] = 'A00I' // Wind Walk ITEM ID
set abilityIDS[4] = 'A02F' // Volcano ITEM ID
set abilityIDS[5] = 'A003' // Earthquake ITEM ID
set abilityIDS[6] = 'A02I' // Stampede ITEM ID
set abilityIDS[7] = 'A018' // Flame Strike ITEM ID
set abilityIDS[8] = 'A02L' // Shadow Strike ITEM ID
set abilityIDS[9] = 'A01X' // Storm Bolt ITEM ID
set abilityIDS[10] = 'A02M' // Soul Burn ITEM ID
set abilityIDS[11] = 'A012' // Bash ITEM ID
set abilityIDS[12] = 'A002' // Critical Strike ITEM ID
set abilityIDS[13] = 'A023' // Spiked Carapace ITEM ID
set abilityIDS[14] = 'A02N' // Cleaving Attack ITEM ID
set abilityIDS[15] = 'A00Q' // Death Coil ITEM ID
set abilityIDS[16] = 'A01B' // Holy Light ITEM ID
set abilityIDS[17] = 'A00R' // Death Pact ITEM ID
set abilityIDS[18] = 'A02P' // Life Drain ITEM ID
set abilityIDS[19] = 'A010' // Avatar ITEM ID
set abilityIDS[20] = 'A029' // Metamorphosis ITEM ID
set abilityIDS[21] = 'A02B' // Vengeance ITEM ID
set abilityIDS[22] = 'A02J' // Tornado ITEM ID
set abilityIDS[23] = 'A020' // Bladestorm ITEM ID
set abilityIDS[24] = 'A02K' // Incinerate ITEM ID
set abilityIDS[25] = 'A028' // Immolation ITEM ID
set abilityIDS[26] = 'A021' // Impale ITEM ID
set abilityIDS[27] = 'A00P' // Carrion Swarm ITEM ID
set abilityIDS[28] = 'A022' // Sleep ITEM ID
set abilityIDS[29] = 'A02Q' // Charm ITEM ID
set abilityIDS[30] = 'A027' // Fan of Knives ITEM ID
set abilityIDS[31] = 'A01Z' // Thunder Clap ITEM ID
set abilityIDS[32] = 'A02Q' // Howl of Terror ITEM ID
set abilityIDS[33] = 'A000' // Chain Lightning ITEM ID
set abilityIDS[34] = 'A02C' // Forked Lightning ITEM ID
set abilityIDS[35] = 'A024' // Blink ITEM ID
set abilityIDS[36] = 'A01E' // Mass Teleport ITEM ID
set abilityIDS[37] = 'A014' // Blizzard ITEM ID
set abilityIDS[38] = 'A02E' // Rain of Fire ITEM ID
set abilityIDS[39] = 'A02A' // Starfall ITEM ID
set itemGroups[0] = 0 // 1st item in next group
set itemGroups[1] = 4 // 1st item in next group
set itemGroups[2] = 8 // 1st item in next group
set itemGroups[3] = 11 // 1st item in next group
set itemGroups[4] = 15 // 1st item in next group
set itemGroups[5] = 19 // 1st item in next group
set itemGroups[6] = 22 // 1st item in next group
set itemGroups[7] = 24 // 1st item in next group
set itemGroups[8] = 26 // 1st item in next group
set itemGroups[9] = 28 // 1st item in next group
set itemGroups[10] = 30 // 1st item in next group
set itemGroups[11] = 33 // 1st item in next group
set itemGroups[12] = 35 // 1st item in next group
set itemGroups[13] = 37 // 1st item in next group
set itemGroups[14] = 40 // 1st item in next group
set abilitySellers[0] = gg_unit_n01L_0119
set abilitySellers[1] = gg_unit_n01L_0120
set abilitySellers[2] = gg_unit_n01L_0121
set abilitySellers[3] = gg_unit_n01L_0122
set abilitySellers[4] = gg_unit_n01L_0123
set abilitySellers[5] = gg_unit_n01L_0124
set abilitySellers[6] = gg_unit_n01L_0125
set abilitySellers[7] = gg_unit_n01L_0126
call hash()
call preloadAbilities()
call itemToStockSetup()
call settingLumberCosts()
endfunction
private function conditions takes nothing returns boolean
return HaveSavedBoolean( conditionHash, GetItemTypeId( GetManipulatedItem()), 0)
endfunction
//===========================================================================
private function Ability_Selection takes nothing returns nothing
set trg_AbilitySelection = CreateTrigger()
call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(0), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(1), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(2), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
call TriggerRegisterPlayerUnitEvent( trg_AbilitySelection, Player(3), EVENT_PLAYER_UNIT_PICKUP_ITEM, null )
call startup()
call TriggerAddAction( trg_AbilitySelection, function Actions )
call TriggerAddCondition( trg_AbilitySelection, function conditions )
endfunction
endscope
Last edited: