- Joined
- Sep 26, 2009
- Messages
- 9,534
I have no idea why but the guy I'm programming this for can't get this to function (can't save the map even in NewGen, and his JassHelper is updated and his settings are configured), it's giving really bizarre errors that don't add up with anything I can think of.
JASS:
scope AllIn1 initializer Init
// globals are variables from the variable editor, but inserting them like this allows full control; no need for the "udg_" prefix,
// and this way allows you to select variables/types that you can't even choose from the editor.
globals
private multiboard Stats // This is what you're working with
private multiboarditem MBItem // This is for me to help the multiboard update more quickly
private constant trigger Refresher = CreateTrigger()
endglobals
// These functions are used to apply the changes you request; no real need to modify...
private function Icon takes integer col, integer row, string s returns nothing
set MBItem = MultiboardGetItem(Stats, col - 1, row - 1)
call MultiboardSetItemIcon(MBItem, s)
call MultiboardReleaseItem(MBItem)
endfunction
private function HideIcon takes integer col, integer row returns nothing
set MBItem = MultiboardGetItem(Stats, col - 1, row - 1)
call MultiboardSetItemStyle(MBItem, true, false)
call MultiboardReleaseItem(MBItem)
endfunction
private function SetColor takes integer col, integer row, integer red, integer gre, integer blu returns nothing
set MBItem = MultiboardGetItem(Stats, col - 1, row - 1)
call MultiboardSetItemValueColor(MBItem, red, gre, blu, 255)
call MultiboardReleaseItem(MBItem)
endfunction
private function Value takes integer col, integer row, string s returns nothing
set MBItem = MultiboardGetItem(Stats, col - 1, row - 1)
call MultiboardSetItemValue(MBItem, s)
call MultiboardReleaseItem(MBItem)
endfunction
// * * * * * * * * * * * * * * * * * * Initialize the multiboard * * * * * * * * * * * * * * * * * *
private function MultiboardInit takes nothing returns nothing
local integer i = 1
set Stats = CreateMultiboard()
call MultiboardSetRowCount(Stats, 15)
call MultiboardSetColumnCount(Stats, 3)
call MultiboardSetTitleText(Stats, "Class: - ")
call MultiboardSetItemWidth( Stats, 5 ) // Set width of everything to 5
call MultiboardSetItemWidthBJ( Stats, 1, 0, 10 ) // Set width of Column 1 to 10.
// column --------v v--------- row
call SetColor(1, 1,255,204,204) // Colors are red,green,blue and can only be integers - no decimals.
call SetColor(1, 9,255,204,204)
call SetColor(2,10, 0,255, 0)
call SetColor(3, 1,255,204,204)
call HideIcon(1, 1)
call HideIcon(1, 9)
call HideIcon(1,13)
loop
call HideIcon(2, i) // Hide all icons in column 2
if i != 11 then // Hide all icons in column 3 except row 11
call HideIcon(3, i)
endif
set i = i + 1
exitwhen i > 15
endloop
set i = 2
loop // Set value of everything in column 2 to zero
if i != 9 and i != 13 then // except for rows 1,9 and 13
call Value(2,i,"0")
endif
set i = i + 1
exitwhen i > 15
endloop
// Materials
call Value(1,1,"|cffFFFF00--[Materials]--|r")
call Value(3,1,"Max")
call Value(1,2,"Metal Scrap")
call Value(1,3,"Wood")
call Value(1,4,"Resin")
call Value(1,5,"Wine")
call Value(1,6,"Stone")
call Value(1,7,"Sulfer")
call Value(1,8,"Gunpowder")
call Icon(1,2,"war3mapImported\\BTNUpgradedPlateBar.blp")
call Icon(1,3,"ReplaceableTextures\\CommandButtons\\BTNBundleOfLumber.blp")
call Icon(1,4,"ReplaceableTextures\\CommandButtons\\BTNPhilosophersStone.blp")
call Icon(1,5,"ReplaceableTextures\\CommandButtons\\BTNShimmerWeed.blp")
call Icon(1,6,"war3mapImported\\BTNINV_Stone_13.blp")
call Icon(1,7,"ReplaceableTextures\\CommandButtons\\BTNManaFlareOff.blp")
call Icon(1,8,"ReplaceableTextures\\CommandButtons\\BTNBarrel.blp")
// Weapons
call Value(1, 9,"|cffFFFF00--[Weapons]--|r")
call Value(1,10,"Weapon")
call Value(1,11,"Ammo")
call Value(3,11,"Coming Soon")
call Value(1,12,"Magazine")
call Icon(1,10,"ReplaceableTextures\\CommandButtons\\BTNDwarvenLongRifle.blp")
call Icon(1,11,"war3mapImported\\BTNammo.blp")
call Icon(3,11,"war3mapImported\\BTNbullet.blp")
call Icon(1,12,"war3mapImported\\BTNreload.blp")
// Survival
call Value(1,13,"|cffFFFF00--[Survival]--|r")
call Value(3,13,"|cffFFFF00-[Need]-|r")
call Value(1,14,"Food")
call Value(1,15,"Water")
call Icon(1,14,"ReplaceableTextures\\CommandButtons\\BTNAcorn.blp")
call Icon(1,15,"war3mapImported\\BTNWaterOrb.blp")
call MultiboardDisplay(Stats, true) // Display multiboard
// The refresh trigger won't run until it has this event:
call TriggerRegisterTimerEvent( Refresher,0.20, true )
endfunction
// Here's the "MULTI BOARD REFRESH" trigger:
private function Refresh takes nothing returns nothing
local integer i = 0
loop
set i = i + 1
exitwhen i > 8
if GetLocalPlayer() == Player(i-1) then // * * * * * * * * * The following is local code - careful with this
// Materials
call Value( 2, 2, I2S(udg_MetalScrap[i]) )
call Value( 2, 3, I2S(udg_Wood[i]) )
call Value( 2, 4, I2S(udg_Resin[i]) )
call Value( 2, 5, I2S(udg_Wine[i]) )
call Value( 2, 6, I2S(udg_Stone[i]) )
call Value( 2, 7, I2S(udg_Sulfur[i]) )
call Value( 2, 8, I2S(udg_Gunpowder[i]) )
// Weapons
call Value( 2, 10, udg_Weapon[i] )
call Value( 2, 11, I2S(udg_Ammo[i]) )
call Value( 3, 11, udg_AmmoType[i] )
call Value( 2, 12, I2S(udg_Magazine[i]) )
call Value( 3, 12, I2S(udg_MaxMag[i]) )
// Survival
call Value( 2, 14, I2S(udg_Food[i]) )
call Value( 2, 15, I2S(udg_Water[i]) )
call Value( 3, 14, I2S(udg_Hunger[i]) )
call Value( 3, 15, I2S(udg_Thirst[i]) )
if udg_Hunger[i] >= 80 then // Too much hunger
call SetColor( 3, 14, 255, 0, 0 )
else
call SetColor( 3, 14, 255, 255, 255 )
endif
if udg_Thirst[i] >= 80 then // Too much thirst
call SetColor( 3, 15, 255, 0, 0 )
else
call SetColor( 3, 15, 255, 255, 255 )
endif
endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * Above this line is the local code
endloop
endfunction
// Initialize multiboard
private function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterTimerEvent( t, 1.00, false )
call TriggerAddAction( t, function MultiboardInit )
call TriggerAddAction( Refresher, function Refresh )
set t = null
endfunction
// * * * * * * * * * * * * * * * The following code is for the actual map initialization * * * * * * * * * * * * * * *
public function SetTo2 takes nothing returns nothing
call SetUnitUserData(GetEnumUnit(), 2)
endfunction
public function PlaceItem takes integer id, rect r, integer howManyItems returns nothing
local real x1 = GetRectMinX(r)
local real x2 = GetRectMaxX(r)
local real y1 = GetRectMinY(r)
local real y2 = GetRectMaxY(r)
local integer i = 1
loop
call CreateItem(id, GetRandomReal(x1, x2), GetRandomReal(y1, y2))
set i = i + 1
exitwhen i > howManyItems
endloop
endfunction
endscope
function InitTrig_Map_Initialization takes nothing returns nothing
local group g = CreateGroup()
call GroupEnumUnitsInRect(g, bj_PLAYABLE_MAP_RECT , null)
call ForGroup(g, function Set2)
call GroupClear(g)
call DestroyGroup(g)
set g = null
call CreateFogModifierRectBJ( true, Player(10), FOG_OF_WAR_VISIBLE, bj_PLAYABLE_MAP_RECT )
call SetTimeOfDay(10.00)
call UseTimeOfDayBJ( false )
// * * * * * * * * * * Place items in random locations * * * * * * * * * * * *
// Raw code of item ----------v v--------- Region you want it in, prefixed with gg_rct_
call PlaceItem( 'I001', gg_rct_Junk_Metal_Spawn, 50)
call PlaceItem( 'I002', gg_rct_Wood_Spawn, 150)
call PlaceItem( 'I003', gg_rct_Wood_Spawn, 150)
call PlaceItem( 'I004', gg_rct_Wood_Spawn, 150)
call PlaceItem( 'I005', gg_rct_Stone_Spawn, 50)
call PlaceItem( 'I006', gg_rct_Stone_Spawn, 50)
// call PlaceItem( 'XXXX', gg_rct_XXXXX_Spawn, #) < -------- Example of how you can make a new one
endfunction
JASS:
scope ZControl initializer Init
globals
private unit z // z == each zombie as it is picked
private unit v // v == target victim of the zombies
private timer sub60 = CreateTimer() // sub60 == Tracks the amount of time between subwaves
private integer ZOMBIES // ZOMBIES == the actual number of zombies created per region
private constant integer ATTACK = OrderId("attack") // ATTACK == conversion of string to integer
private constant group g = CreateGroup() // g == temporary placeholder for zombies
private constant string Zombify = "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdx"
// Zombify == The effect that appears each time a zombie is made
endglobals
private constant function Living takes unit u returns boolean
return GetUnitState(u, UNIT_STATE_LIFE) > 0 and not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
private function AcquireTarget takes nothing returns nothing
local integer j = 0
loop
set v = udg_Survivor[GetRandomInt(1,8)] // This picks a random survivor to attack.
if Living(v) then // If that survivor is alive, then...
call IssueTargetOrderById(z, ATTACK, v) // have the zombie attack him
exitwhen true
endif
set j = j + 1
exitwhen j > 10 // Failsafe exitpoint - zombie will ignore order after so many failed tries to find a suitable target;
endloop // without this, there is a chance the game will crash sometimes. Actually, this isn't so bad to have, because
endfunction // the zombies will sometimes stay still for a short period of time if there are fewer players.
private function SendZombies takes nothing returns nothing
set z = GetEnumUnit()
// Check if zombie (z) is attacking & if zombie is alive
if GetUnitCurrentOrder(z) != ATTACK and Living(z) then
call AcquireTarget()
endif
endfunction
private function ZombieMove takes nothing returns nothing
call GroupEnumUnitsOfType(g,'n004',null)
call ForGroup(g,function SendZombies)
call GroupClear(g)
endfunction
private function CountPlayingPlayers takes nothing returns integer
local integer j = 0
local integer PlayersInGame = 0
loop
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
set PlayersInGame = PlayersInGame + 1
endif
set j = j + 1
exitwhen j > 7
endloop
if PlayersInGame < 4 then // if fewer than 4 players then multiply by zero
return 0
endif
return PlayersInGame - 3 // otherwise set multiplier to #players - 3
endfunction
// "AddZombiesToRegion" creates the calculated number of zombies at random points in each region (rect)
private function AddZombiesToRegion takes rect r returns nothing
local real x1 = GetRectMinX(r)
local real x2 = GetRectMaxX(r)
local real y1 = GetRectMinY(r)
local real y2 = GetRectMaxY(r)
local integer i = 1
loop
set z = CreateUnit(Player(10), 'n004', GetRandomReal(x1,x2),GetRandomReal(y1,y2),0)
call DestroyEffect(AddSpecialEffectTarget(Zombify,z,"origin"))
call AcquireTarget()
set i = i + 1
exitwhen i > ZOMBIES
endloop
endfunction
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function AddZombies takes integer count returns nothing // "AddZombies" - you assign it a number, it spawns them in all regions.
set ZOMBIES = (CountPlayingPlayers() * 10) + count // If you want to add a region (rect) where zombies are spawned, do it here.
call AddZombiesToRegion(gg_rct_Zombie_Spawn_Main) // * Whenever you want zombies, if in JASS, type:
call AddZombiesToRegion(gg_rct_Forest_Zombie_Spawn) // call AddZombies(# of Zombies you want)
call AddZombiesToRegion(gg_rct_Stone_Spawn) // * or, if in GUI, use:
endfunction // Custom script: call AddZombies(number you want)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
private function Subwave01 takes nothing returns nothing
if GetTimeOfDay() < 10 and GetTimeOfDay() > 16.00 then
call AddZombies(20) // Here I set it to add 20 zombies. Note that this is the number before the math bonuses,
else // So with more players this number will be higher.
call PauseTimer(sub60)
endif
endfunction
private function FirstWaveActions takes nothing returns nothing
local integer i = 1
loop
exitwhen i > 8
set udg_Skip[i] = 0
set i = i + 1
endloop
call AddZombies(30) // Here I set it to add 30 zombies.
call TimerStart(sub60, 60., true, function Subwave01)
endfunction
// Kill all zombies at 10:00am
private function EndWave takes nothing returns nothing
call GroupEnumUnitsOfType(g,'n004')
loop
set z = FirstOfGroup(g)
exitwhen z == null
call GroupRemoveUnit( g , z )
call KillUnit( z )
endloop
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterGameStateEventTimeOfDay( t , EQUAL , 10.00 )
call TriggerAddAction( t , function EndWave )
set t = CreateTrigger()
call TriggerRegisterTimerEvent( t, 2.00, true )
call TriggerAddAction( t, function ZombieMove )
set t = CreateTrigger()
call TriggerRegisterGameStateEventTimeOfDay( t, 16.00 )
call TriggerAddAction( t, function FirstWaveActions )
set t = null
endfunction
endscope
function InitTrig_Zombies takes nothing returns nothing
// This is kind of a wasted function, but your editor won't let you save without it...
endfunction