Tom Jones
N/A
- Reaction score
- 437
A snippet that'll return a random unit id. I ported it from a tower defence I've long given up on. I admit that it may be a little big for a snippet, but one can hardly call it a system.
Code:
vJass.
Usage:
Also have a look at the example that comes with the map.
Code:
vJass.
JASS:
library GetRandomId initializer Init
//##############################################################################
//#GetRandomId by Tom Jones.
//##############################################################################
//#Requirements:
//#1) NewGen Editor.
//#
//#Implementation:
//#1) Copy this GUI trigger from this map to your map.
//#
//#Usage:
//#¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# call GetRandomId(A_UNIT_TYPE,ONCE)
//#¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//# Returns a random unit id.
//#
//# A_UNIT_TYPE must be one of the following:
//# a) UNIT_TYPE_GROUND
//# b) UNIT_TYPE_FLYING
//# c) UNIT_TYPE_HERO
//# d) UNIT_TYPE_RANDOM
//#
//# ONCE is a boolean and determines if a unit id can be randomized more then
//# once. If ONCE is true a unit id can only be randomized once.
//#
//#Notes:
//#1) Enabling Debug mode will display errors, warnings, and possible fixes.
//#2) Typing -getlastindex will return the index of the last randomized
//# id. This is usefull if for some reason the id doesn't work, etc. units
//# without movement. If you find unit id that doesn't work, please PM me on
//# <a href="http://www.TheHelper.net" target="_blank" class="link link--external" rel="nofollow ugc noopener">www.TheHelper.net</a>.
//##############################################################################
//##############################################################################
//#Options.
//##############################################################################
globals
//If you randomize an entire array, the below will reset the array so it can be
//randomized again.
private constant boolean RESET_ARRAYS = true
//Enabling the below boolean will check randomized ids for invisiblity,
//invulnerbility, and locust, if Debug mode is enabled.
private constant boolean CHECK_ABILITIES = true
endglobals
//##############################################################################
//#GetRandomId Code - Do not modify below here unless you know what your doing.
//##############################################################################
globals
constant unittype UNIT_TYPE_RANDOM = ConvertUnitType(26) //No idea if this messes with anthing, so far I haven't been able to produce an error.
private constant integer NO_ID = 0
private integer LAST_INDEX
private integer array GROUND
private integer GROUND_INDEX
private integer array AIR
private integer AIR_INDEX
private integer array HERO
private integer HERO_INDEX
private constant string ERROR = "|cffff0000GetRandomId() Error:|r "
private constant string WARNING = "|cffff0000GetRandomId() Warning:|r "
private constant string FIX = "|cff00ff00GetRandomId() Fix:|r "
endglobals
private function Init_Heroes takes nothing returns nothing
set HERO[0] = 039;Hamg039;
set HERO[1] = 039;Hblm039;
set HERO[2] = 039;Hmkg039;
set HERO[3] = 039;Hpal039;
set HERO[4] = 039;Obla039;
set HERO[5] = 039;Ofar039;
set HERO[6] = 039;Oshd039;
set HERO[7] = 039;Otch039;
set HERO[8] = 039;Edem039;
set HERO[9] = 039;Edmm039;
set HERO[10] = 039;Ekee039;
set HERO[11] = 039;Emoo039;
set HERO[12] = 039;Ewar039;
set HERO[13] = 039;Ucrl039;
set HERO[14] = 039;Udea039;
set HERO[15] = 039;Udre039;
set HERO[16] = 039;Ulic039;
set HERO[17] = 039;Nal2039;
set HERO[18] = 039;Nal3039;
set HERO[19] = 039;Nalc039;
set HERO[20] = 039;Nalm039;
set HERO[21] = 039;Nbrn039;
set HERO[22] = 039;Nbst039;
set HERO[23] = 039;Nfir039;
set HERO[24] = 039;Nngs039;
set HERO[25] = 039;Npbm039;
set HERO[26] = 039;Nplh039;
set HERO[27] = 039;Nrob039;
set HERO[28] = 039;Ntin039;
set HERO[29] = 039;Ecen039;
set HERO[30] = 039;Eevi039;
set HERO[31] = 039;Eevm039;
set HERO[32] = 039;Efur039;
set HERO[33] = 039;Eidm039;
set HERO[34] = 039;Eill039;
set HERO[35] = 039;Eilm039;
set HERO[36] = 039;Ekgg039;
set HERO[37] = 039;Emfr039;
set HERO[38] = 039;Emns039;
set HERO[39] = 039;Etyr039;
set HERO[40] = 039;Ewrd039;
set HERO[41] = 039;Hant039;
set HERO[42] = 039;Hapm039;
set HERO[43] = 039;Harf039;
set HERO[44] = 039;Hart039;
set HERO[45] = 039;Hdgo039;
set HERO[46] = 039;Hgam039;
set HERO[47] = 039;Hhkl039;
set HERO[48] = 039;Hjai039;
set HERO[49] = 039;Hkal039;
set HERO[50] = 039;Hlgr039;
set HERO[51] = 039;Hmbr039;
set HERO[52] = 039;Hmgd039;
set HERO[53] = 039;Hpb1039;
set HERO[54] = 039;Hpb2039;
set HERO[55] = 039;Huth039;
set HERO[56] = 039;Hvsh039;
set HERO[57] = 039;Hvwd039;
set HERO[58] = 039;Naka039;
set HERO[59] = 039;Nbbc039;
set HERO[60] = 039;Nkjx039;
set HERO[61] = 039;Nklj039;
set HERO[62] = 039;Nmag039;
set HERO[63] = 039;Nman039;
set HERO[64] = 039;Npld039;
set HERO[65] = 039;Nsjs039;
set HERO[66] = 039;Ocb2039;
set HERO[67] = 039;Ocbh039;
set HERO[68] = 039;Odrt039;
set HERO[69] = 039;Ogld039;
set HERO[70] = 039;Ogrh039;
set HERO[71] = 039;Opgh039;
set HERO[72] = 039;Orex039;
set HERO[73] = 039;Orkn039;
set HERO[74] = 039;Osam039;
set HERO[75] = 039;Otcc039;
set HERO[76] = 039;Othr039;
set HERO[77] = 039;Uanb039;
set HERO[78] = 039;Ubal039;
set HERO[79] = 039;Uclc039;
set HERO[80] = 039;Udth039;
set HERO[81] = 039;Uear039;
set HERO[82] = 039;Uktl039;
set HERO[83] = 039;Umal039;
set HERO[84] = 039;Usyl039;
set HERO[85] = 039;Utic039;
set HERO[86] = 039;Uvar039;
set HERO[87] = 039;Uvng039;
set HERO[88] = 039;Uwar039;
set HERO_INDEX = 88
endfunction
private function Init_Ground takes nothing returns nothing
set GROUND[0] = 039;hfoo039;
set GROUND[1] = 039;hmil039;
set GROUND[2] = 039;hmpr039;
set GROUND[3] = 039;hmtm039;
set GROUND[4] = 039;hmtt039;
set GROUND[5] = 039;hpea039;
set GROUND[6] = 039;hpxe039;
set GROUND[7] = 039;hrif039;
set GROUND[8] = 039;hrtt039;
set GROUND[9] = 039;hspt039;
set GROUND[10] = 039;hwat039;
set GROUND[11] = 039;hwt2039;
set GROUND[12] = 039;hwt3039;
set GROUND[13] = 039;nlv1039;
set GROUND[14] = 039;nlv2039;
set GROUND[15] = 039;nlv3039;
set GROUND[16] = 039;hkni039;
set GROUND[17] = 039;hsor039;
set GROUND[18] = 039;ncat039;
set GROUND[19] = 039;nsw1039;
set GROUND[20] = 039;nsw2039;
set GROUND[21] = 039;nsw3039;
set GROUND[22] = 039;nwad039;
set GROUND[23] = 039;ocat039;
set GROUND[24] = 039;odoc039;
set GROUND[25] = 039;oeye039;
set GROUND[26] = 039;ogru039;
set GROUND[27] = 039;ohun039;
set GROUND[28] = 039;ohwd039;
set GROUND[29] = 039;opeo039;
set GROUND[30] = 039;oshm039;
set GROUND[31] = 039;osp1039;
set GROUND[32] = 039;osp2039;
set GROUND[33] = 039;osp3039;
set GROUND[34] = 039;osp4039;
set GROUND[35] = 039;ospm039;
set GROUND[36] = 039;ospw039;
set GROUND[37] = 039;osw1039;
set GROUND[38] = 039;osw2039;
set GROUND[39] = 039;osw3039;
set GROUND[40] = 039;otau039;
set GROUND[41] = 039;otbk039;
set GROUND[42] = 039;otot039;
set GROUND[43] = 039;okod039;
set GROUND[44] = 039;orai039;
set GROUND[45] = 039;earc039;
set GROUND[46] = 039;ebal039;
set GROUND[47] = 039;edcm039;
set GROUND[48] = 039;edoc039;
set GROUND[49] = 039;edot039;
set GROUND[50] = 039;edry039;
set GROUND[51] = 039;efon039;
set GROUND[52] = 039;emtg039;
set GROUND[53] = 039;esen039;
set GROUND[54] = 039;espv039;
set GROUND[55] = 039;even039;
set GROUND[56] = 039;ewsp039;
set GROUND[57] = 039;uabo039;
set GROUND[58] = 039;uaco039;
set GROUND[59] = 039;ucrm039;
set GROUND[60] = 039;ucry039;
set GROUND[61] = 039;ucs1039;
set GROUND[62] = 039;ucs2039;
set GROUND[63] = 039;ucs3039;
set GROUND[64] = 039;ucsB039;
set GROUND[65] = 039;ucsC039;
set GROUND[66] = 039;ugho039;
set GROUND[67] = 039;ugrm039;
set GROUND[68] = 039;umtw039;
set GROUND[69] = 039;unec039;
set GROUND[70] = 039;uobs039;
set GROUND[71] = 039;uske039;
set GROUND[72] = 039;uskm039;
set GROUND[73] = 039;uban039;
set GROUND[74] = 039;ushd039;
set GROUND[75] = 039;nanb039;
set GROUND[76] = 039;nanc039;
set GROUND[77] = 039;nane039;
set GROUND[78] = 039;nanm039;
set GROUND[79] = 039;nano039;
set GROUND[80] = 039;nanw039;
set GROUND[81] = 039;narg039;
set GROUND[82] = 039;nass039;
set GROUND[83] = 039;nba2039;
set GROUND[84] = 039;nbal039;
set GROUND[85] = 039;nban039;
set GROUND[86] = 039;nbda039;
set GROUND[87] = 039;nbdm039;
set GROUND[88] = 039;nbdo039;
set GROUND[89] = 039;nbds039;
set GROUND[90] = 039;nbdw039;
set GROUND[91] = 039;nbnb039;
set GROUND[92] = 039;nbrg039;
set GROUND[93] = 039;ncea039;
set GROUND[94] = 039;ncen039;
set GROUND[95] = 039;ncer039;
set GROUND[96] = 039;nchp039;
set GROUND[97] = 039;ncim039;
set GROUND[98] = 039;ncks039;
set GROUND[99] = 039;ncnk039;
set GROUND[100] = 039;ndqn039;
set GROUND[101] = 039;ndqp039;
set GROUND[102] = 039;ndqs039;
set GROUND[103] = 039;ndqt039;
set GROUND[104] = 039;ndqv039;
set GROUND[105] = 039;ndtb039;
set GROUND[106] = 039;ndth039;
set GROUND[107] = 039;ndtp039;
set GROUND[108] = 039;ndtr039;
set GROUND[109] = 039;ndtt039;
set GROUND[110] = 039;ndtw039;
set GROUND[111] = 039;nelb039;
set GROUND[112] = 039;nele039;
set GROUND[113] = 039;nenc039;
set GROUND[114] = 039;nenf039;
set GROUND[115] = 039;nenp039;
set GROUND[116] = 039;nepl039;
set GROUND[117] = 039;nerd039;
set GROUND[118] = 039;ners039;
set GROUND[119] = 039;nerw039;
set GROUND[120] = 039;nfel039;
set GROUND[121] = 039;nfgb039;
set GROUND[122] = 039;nfgt039;
set GROUND[123] = 039;nfgu039;
set GROUND[124] = 039;nfod039;
set GROUND[125] = 039;nfor039;
set GROUND[126] = 039;nfot039;
set GROUND[127] = 039;nfov039;
set GROUND[128] = 039;nfpc039;
set GROUND[129] = 039;nfpe039;
set GROUND[130] = 039;nfpl039;
set GROUND[131] = 039;nfps039;
set GROUND[132] = 039;nfpt039;
set GROUND[133] = 039;nfpu039;
set GROUND[134] = 039;nfra039;
set GROUND[135] = 039;nfrb039;
set GROUND[136] = 039;nfre039;
set GROUND[137] = 039;nfrg039;
set GROUND[138] = 039;nfrl039;
set GROUND[139] = 039;nfrp039;
set GROUND[140] = 039;nfrs039;
set GROUND[141] = 039;nfsh039;
set GROUND[142] = 039;nfsp039;
set GROUND[143] = 039;nftb039;
set GROUND[144] = 039;nftk039;
set GROUND[145] = 039;nftr039;
set GROUND[146] = 039;nftt039;
set GROUND[147] = 039;nggr039;
set GROUND[148] = 039;ngir039;
set GROUND[149] = 039;nglm039;
set GROUND[150] = 039;ngna039;
set GROUND[151] = 039;ngnb039;
set GROUND[152] = 039;ngno039;
set GROUND[153] = 039;ngns039;
set GROUND[154] = 039;ngnv039;
set GROUND[155] = 039;ngnw039;
set GROUND[156] = 039;ngrk039;
set GROUND[157] = 039;ngsp039;
set GROUND[158] = 039;ngst039;
set GROUND[159] = 039;ngza039;
set GROUND[160] = 039;nhdc039;
set GROUND[161] = 039;nhfp039;
set GROUND[162] = 039;nhhr039;
set GROUND[163] = 039;nhym039;
set GROUND[164] = 039;nina039;
set GROUND[165] = 039;ninc039;
set GROUND[166] = 039;ninf039;
set GROUND[167] = 039;ninm039;
set GROUND[168] = 039;nith039;
set GROUND[169] = 039;nitp039;
set GROUND[170] = 039;nitr039;
set GROUND[171] = 039;nits039;
set GROUND[172] = 039;nitt039;
set GROUND[173] = 039;nitw039;
set GROUND[174] = 039;njg1039;
set GROUND[175] = 039;njga039;
set GROUND[176] = 039;njgb039;
set GROUND[177] = 039;nkob039;
set GROUND[178] = 039;nkog039;
set GROUND[179] = 039;nkol039;
set GROUND[180] = 039;nkot039;
set GROUND[181] = 039;nlds039;
set GROUND[182] = 039;nlkl039;
set GROUND[183] = 039;nlpd039;
set GROUND[184] = 039;nlpr039;
set GROUND[185] = 039;nlps039;
set GROUND[186] = 039;nlsn039;
set GROUND[187] = 039;nltc039;
set GROUND[188] = 039;nltl039;
set GROUND[189] = 039;nlur039;
set GROUND[190] = 039;nmam039;
set GROUND[191] = 039;nmdr039;
set GROUND[192] = 039;nmfs039;
set GROUND[193] = 039;nmgd039;
set GROUND[194] = 039;nmgr039;
set GROUND[195] = 039;nmgw039;
set GROUND[196] = 039;nmit039;
set GROUND[197] = 039;nmmu039;
set GROUND[198] = 039;nmpg039;
set GROUND[199] = 039;nmrl039;
set GROUND[200] = 039;nmrm039;
set GROUND[201] = 039;nmrr039;
set GROUND[202] = 039;nnwa039;
set GROUND[203] = 039;nnwl039;
set GROUND[204] = 039;nnwq039;
set GROUND[205] = 039;nnwr039;
set GROUND[206] = 039;nnws039;
set GROUND[207] = 039;noga039;
set GROUND[208] = 039;nogl039;
set GROUND[209] = 039;nogm039;
set GROUND[210] = 039;nogn039;
set GROUND[211] = 039;nogo039;
set GROUND[212] = 039;nogr039;
set GROUND[213] = 039;nomg039;
set GROUND[214] = 039;nowb039;
set GROUND[215] = 039;nowe039;
set GROUND[216] = 039;nowk039;
set GROUND[217] = 039;npfl039;
set GROUND[218] = 039;npfm039;
set GROUND[219] = 039;nqbh039;
set GROUND[220] = 039;nrog039;
set GROUND[221] = 039;nrzb039;
set GROUND[222] = 039;nrzg039;
set GROUND[223] = 039;nrzm039;
set GROUND[224] = 039;nrzs039;
set GROUND[225] = 039;nrzt039;
set GROUND[226] = 039;nsat039;
set GROUND[227] = 039;nsbm039;
set GROUND[228] = 039;nsc2039;
set GROUND[229] = 039;nsc3039;
set GROUND[230] = 039;nsca039;
set GROUND[231] = 039;nscb039;
set GROUND[232] = 039;nsce039;
set GROUND[233] = 039;nsgg039;
set GROUND[234] = 039;nsgt039;
set GROUND[235] = 039;nska039;
set GROUND[236] = 039;nske039;
set GROUND[237] = 039;nskf039;
set GROUND[238] = 039;nskg039;
set GROUND[239] = 039;nskm039;
set GROUND[240] = 039;nsko039;
set GROUND[241] = 039;nslf039;
set GROUND[242] = 039;nslh039;
set GROUND[243] = 039;nsll039;
set GROUND[244] = 039;nslm039;
set GROUND[245] = 039;nsln039;
set GROUND[246] = 039;nslr039;
set GROUND[247] = 039;nslv039;
set GROUND[248] = 039;nsoc039;
set GROUND[249] = 039;nsog039;
set GROUND[250] = 039;nspb039;
set GROUND[251] = 039;nspd039;
set GROUND[252] = 039;nspg039;
set GROUND[253] = 039;nspp039;
set GROUND[254] = 039;nspr039;
set GROUND[255] = 039;nsqa039;
set GROUND[256] = 039;nsqe039;
set GROUND[257] = 039;nsqo039;
set GROUND[258] = 039;nsqt039;
set GROUND[259] = 039;nsra039;
set GROUND[260] = 039;nsrh039;
set GROUND[261] = 039;nsrn039;
set GROUND[262] = 039;nsrw039;
set GROUND[263] = 039;nssp039;
set GROUND[264] = 039;nsth039;
set GROUND[265] = 039;nstl039;
set GROUND[266] = 039;nsts039;
set GROUND[267] = 039;nstw039;
set GROUND[268] = 039;nsty039;
set GROUND[269] = 039;nthl039;
set GROUND[270] = 039;ntka039;
set GROUND[271] = 039;ntkc039;
set GROUND[272] = 039;ntkf039;
set GROUND[273] = 039;ntkh039;
set GROUND[274] = 039;ntks039;
set GROUND[275] = 039;ntkt039;
set GROUND[276] = 039;ntkw039;
set GROUND[277] = 039;ntor039;
set GROUND[278] = 039;nubk039;
set GROUND[279] = 039;nubr039;
set GROUND[280] = 039;nubw039;
set GROUND[281] = 039;nwen039;
set GROUND[282] = 039;nwiz039;
set GROUND[283] = 039;nwld039;
set GROUND[284] = 039;nwlg039;
set GROUND[285] = 039;nwlt039;
set GROUND[286] = 039;nwna039;
set GROUND[287] = 039;nwnr039;
set GROUND[288] = 039;nwns039;
set GROUND[289] = 039;nwrg039;
set GROUND[290] = 039;nwwd039;
set GROUND[291] = 039;nwwf039;
set GROUND[292] = 039;nwwg039;
set GROUND[293] = 039;nwzd039;
set GROUND[294] = 039;nwzg039;
set GROUND[295] = 039;nwzr039;
set GROUND[296] = 039;nzom039;
set GROUND[297] = 039;nbld039;
set GROUND[298] = 039;nahy039;
set GROUND[299] = 039;ncfs039;
set GROUND[300] = 039;nehy039;
set GROUND[301] = 039;nhyc039;
set GROUND[302] = 039;nhyd039;
set GROUND[303] = 039;nhyh039;
set GROUND[304] = 039;nmbg039;
set GROUND[305] = 039;nmcf039;
set GROUND[306] = 039;nmrv039;
set GROUND[307] = 039;nmsc039;
set GROUND[308] = 039;nmsn039;
set GROUND[309] = 039;nmtw039;
set GROUND[310] = 039;nmyr039;
set GROUND[311] = 039;nmys039;
set GROUND[312] = 039;nnmg039;
set GROUND[313] = 039;nnrg039;
set GROUND[314] = 039;nnrs039;
set GROUND[315] = 039;nnsu039;
set GROUND[316] = 039;nnsw039;
set GROUND[317] = 039;nplb039;
set GROUND[318] = 039;nplg039;
set GROUND[319] = 039;nrel039;
set GROUND[320] = 039;nsbs039;
set GROUND[321] = 039;nsel039;
set GROUND[322] = 039;nsgb039;
set GROUND[323] = 039;nsgh039;
set GROUND[324] = 039;nsgn039;
set GROUND[325] = 039;nsnp039;
set GROUND[326] = 039;nsns039;
set GROUND[327] = 039;ntrd039;
set GROUND[328] = 039;ntrg039;
set GROUND[329] = 039;ntrh039;
set GROUND[330] = 039;ntrs039;
set GROUND[331] = 039;ntrt039;
set GROUND[332] = 039;ntws039;
set GROUND[333] = 039;ndrv039;
set GROUND[334] = 039;ngh1039;
set GROUND[335] = 039;ngh2039;
set GROUND[336] = 039;nlrv039;
set GROUND[337] = 039;nrvd039;
set GROUND[338] = 039;nrvf039;
set GROUND[339] = 039;nrvi039;
set GROUND[340] = 039;nrvl039;
set GROUND[341] = 039;nrvs039;
set GROUND[342] = 039;nsrv039;
set GROUND[343] = 039;ntrv039;
set GROUND[344] = 039;nvde039;
set GROUND[345] = 039;nvdg039;
set GROUND[346] = 039;nvdl039;
set GROUND[347] = 039;nvdw039;
set GROUND[348] = 039;ncrb039;
set GROUND[349] = 039;nder039;
set GROUND[350] = 039;ndog039;
set GROUND[351] = 039;ndwm039;
set GROUND[352] = 039;nech039;
set GROUND[353] = 039;necr039;
set GROUND[354] = 039;nfbr039;
set GROUND[355] = 039;nfro039;
set GROUND[356] = 039;nhmc039;
set GROUND[357] = 039;npig039;
set GROUND[358] = 039;nrac039;
set GROUND[359] = 039;nrat039;
set GROUND[360] = 039;nsea039;
set GROUND[361] = 039;nshe039;
set GROUND[362] = 039;nskk039;
set GROUND[363] = 039;nvil039;
set GROUND[364] = 039;nvk2039;
set GROUND[365] = 039;nvl2039;
set GROUND[366] = 039;nvlk039;
set GROUND[367] = 039;nvlw039;
set GROUND[368] = 039;npng039;
set GROUND[369] = 039;nsha039;
set GROUND[370] = 039;eilw039;
set GROUND[371] = 039;enec039;
set GROUND[372] = 039;ensh039;
set GROUND[373] = 039;eshd039;
set GROUND[374] = 039;hbew039;
set GROUND[375] = 039;hcth039;
set GROUND[376] = 039;hhes039;
set GROUND[377] = 039;hprt039;
set GROUND[378] = 039;nbee039;
set GROUND[379] = 039;nbel039;
set GROUND[380] = 039;nbsp039;
set GROUND[381] = 039;nchg039;
set GROUND[382] = 039;nchw039;
set GROUND[383] = 039;ncpn039;
set GROUND[384] = 039;ndmu039;
set GROUND[385] = 039;ndrd039;
set GROUND[386] = 039;ndrf039;
set GROUND[387] = 039;ndrh039;
set GROUND[388] = 039;ndrj039;
set GROUND[389] = 039;ndrl039;
set GROUND[390] = 039;ndrm039;
set GROUND[391] = 039;ndrn039;
set GROUND[392] = 039;ndrp039;
set GROUND[393] = 039;ndrs039;
set GROUND[394] = 039;ndrt039;
set GROUND[395] = 039;ndrw039;
set GROUND[396] = 039;ndsa039;
set GROUND[397] = 039;negz039;
set GROUND[398] = 039;nemi039;
set GROUND[399] = 039;nfgl039;
set GROUND[400] = 039;ngbl039;
set GROUND[401] = 039;nhea039;
set GROUND[402] = 039;nhef039;
set GROUND[403] = 039;nhem039;
set GROUND[404] = 039;nhew039;
set GROUND[405] = 039;njks039;
set GROUND[406] = 039;nmed039;
set GROUND[407] = 039;nmsh039;
set GROUND[408] = 039;nspc039;
set GROUND[409] = 039;nssn039;
set GROUND[410] = 039;nw2w039;
set GROUND[411] = 039;nwat039;
set GROUND[412] = 039;nzlc039;
set GROUND[413] = 039;odkt039;
set GROUND[414] = 039;ogrk039;
set GROUND[415] = 039;omtg039;
set GROUND[416] = 039;oosc039;
set GROUND[417] = 039;ovlj039;
set GROUND[418] = 039;owar039;
set GROUND[419] = 039;uabc039;
set GROUND[420] = 039;uktg039;
set GROUND[421] = 039;uktn039;
set GROUND[422] = 039;hhdl039;
set GROUND[423] = 039;hrdh039;
set GROUND[424] = 039;nchr039;
set GROUND[425] = 039;nckb039;
set GROUND[426] = 039;onzg039;
set GROUND[427] = 039;nmpe039;
set GROUND[428] = 039;uswb039;
set GROUND_INDEX = 428
endfunction
private function Init_Air takes nothing returns nothing
set AIR[0] = 039;hdhw039;
set AIR[1] = 039;hgry039;
set AIR[2] = 039;hgyr039;
set AIR[3] = 039;hphx039;
set AIR[4] = 039;otbr039;
set AIR[5] = 039;owyv039;
set AIR[6] = 039;echm039;
set AIR[7] = 039;edtm039;
set AIR[8] = 039;efdr039;
set AIR[9] = 039;ehip039;
set AIR[10] = 039;ehpr039;
set AIR[11] = 039;ubsp039;
set AIR[12] = 039;ufro039;
set AIR[13] = 039;ugar039;
set AIR[14] = 039;uloc039;
set AIR[15] = 039;nadk039;
set AIR[16] = 039;nadr039;
set AIR[17] = 039;nadw039;
set AIR[18] = 039;nbdk039;
set AIR[19] = 039;nbdr039;
set AIR[20] = 039;nbwm039;
set AIR[21] = 039;nbzd039;
set AIR[22] = 039;nbzk039;
set AIR[23] = 039;nbzw039;
set AIR[24] = 039;ngdk039;
set AIR[25] = 039;ngrd039;
set AIR[26] = 039;ngrw039;
set AIR[27] = 039;nhar039;
set AIR[28] = 039;nhrh039;
set AIR[29] = 039;nhrq039;
set AIR[30] = 039;nhrr039;
set AIR[31] = 039;nhrw039;
set AIR[32] = 039;nndk039;
set AIR[33] = 039;nndr039;
set AIR[34] = 039;nnht039;
set AIR[35] = 039;nrdk039;
set AIR[36] = 039;nrdr039;
set AIR[37] = 039;nrwm039;
set AIR[38] = 039;nwgs039;
set AIR[39] = 039;nws1039;
set AIR[40] = 039;nzep039;
set AIR[41] = 039;nalb039;
set AIR[42] = 039;now2039;
set AIR[43] = 039;now3039;
set AIR[44] = 039;nowl039;
set AIR[45] = 039;nshf039;
set AIR[46] = 039;nsno039;
set AIR[47] = 039;nvul039;
set AIR[48] = 039;nmdm039;
set AIR[49] = 039;nser039;
set AIR[50] = 039;nthr039;
set AIR[51] = 039;oswy039;
set AIR[52] = 039;ownr039;
set AIR[53] = 039;uarb039;
set AIR[54] = 039;ubdd039;
set AIR[55] = 039;ubdr039;
set AIR[56] = 039;nwe1039;
set AIR[57] = 039;nwe2039;
set AIR[58] = 039;nwe3039;
set AIR[59] = 039;zjug039;
set AIR_INDEX = 59
endfunction
private function Display_Index takes nothing returns nothing
call BJDebugMsg("|cffffd700GetRandomId() Index:|r "+I2S(LAST_INDEX))
endfunction
private function Reset_Array takes nothing returns nothing
if HERO_INDEX < 0 then
call Init_Heroes()
elseif GROUND_INDEX < 0 then
call Init_Ground()
elseif AIR_INDEX < 0 then
call Init_Air()
endif
endfunction
private function Init takes nothing returns nothing
local trigger trig
call Init_Heroes()
call Init_Ground()
call Init_Air()
if bj_isSinglePlayer then
set trig = CreateTrigger()
call TriggerRegisterPlayerChatEvent(trig,Player(0),"-getlastindex",true)
call TriggerAddAction(trig,function Display_Index)
endif
if RESET_ARRAYS then
set trig = CreateTrigger()
call TriggerRegisterVariableEvent(trig,SCOPE_PRIVATE+"HERO_INDEX",LESS_THAN,0)
call TriggerRegisterVariableEvent(trig,SCOPE_PRIVATE+"GROUND_INDEX",LESS_THAN,0)
call TriggerRegisterVariableEvent(trig,SCOPE_PRIVATE+"AIR_INDEX",LESS_THAN,0)
call TriggerAddAction(trig,function Reset_Array)
endif
endfunction
private function CheckAbilities takes integer id returns nothing
local unit u = CreateUnit(Player(15),id,0,0,0)
local boolean b = false
if IsUnitInvisible(u,Player(0)) == true then
set b = true
call BJDebugMsg(WARNING+"Unit type "+UnitId2String(id)+" is invisible.")
if GetUnitAbilityLevel(u,039;Agho039;) > 0 then
call BJDebugMsg(FIX+"Remove ability 039;Agho039; from created units.")
elseif GetUnitAbilityLevel(u,039;Ashm039;) > 0 then
call BJDebugMsg(FIX+"Remove ability 039;Ashm039; from created units.")
elseif GetUnitAbilityLevel(u,039;Ahid039;) > 0 then
call BJDebugMsg(FIX+"Remove ability 039;Ahid039; from created units.")
elseif GetUnitAbilityLevel(u,039;Sshm039;) > 0 then
call BJDebugMsg(FIX+"Remove ability 039;Sshm039; from created units.")
endif
endif
if GetUnitAbilityLevel(u,039;Avul039;) > 0 then
set b = true
call BJDebugMsg(WARNING+"Unit type "+UnitId2String(id)+" is invulnerable.")
call BJDebugMsg(FIX+"Remove ability 039;Avul039; from created units.")
endif
if GetUnitAbilityLevel(u,039;Aloc039;) > 0 then
set b = true
call BJDebugMsg(WARNING+"Unit type "+UnitId2String(id)+" is locusted.")
call BJDebugMsg(FIX+"Remove ability 039;Aloc039; from created units.")
endif
if IssuePointOrder(u,"move",0,0) == false then
set b = true
call BJDebugMsg(WARNING+"Unit type "+UnitId2String(id)+" has no movement.")
endif
if b then
if IsUnitType(u,UNIT_TYPE_HERO) == true then
call BJDebugMsg(FIX+"Alternatively set HERO["+I2S(LAST_INDEX)+"] = NO_ID.")
elseif IsUnitType(u,UNIT_TYPE_FLYING) == true then
call BJDebugMsg(FIX+"Alternatively set AIR["+I2S(LAST_INDEX)+"] = NO_ID.")
elseif IsUnitType(u,UNIT_TYPE_GROUND) == true then
call BJDebugMsg(FIX+"Alternatively set GROUND["+I2S(LAST_INDEX)+"] = NO_ID.")
endif
endif
call RemoveUnit(u)
set u = null
endfunction
function GetRandomId takes unittype whichtype, boolean remove returns integer
local integer id = NO_ID
loop
exitwhen id != NO_ID
if GROUND_INDEX >= 0 and (whichtype == UNIT_TYPE_GROUND or (whichtype == UNIT_TYPE_RANDOM and GetRandomInt(1,3) == 1)) then
set LAST_INDEX = GetRandomInt(0,GROUND_INDEX)
set id = GROUND[LAST_INDEX]
if remove or id == NO_ID then
set GROUND[LAST_INDEX] = GROUND[GROUND_INDEX]
set GROUND_INDEX = GROUND_INDEX-1
endif
elseif AIR_INDEX >= 0 and (whichtype == UNIT_TYPE_FLYING or (whichtype == UNIT_TYPE_RANDOM and GetRandomInt(1,2) == 1)) then
set LAST_INDEX = GetRandomInt(0,AIR_INDEX)
set id = AIR[LAST_INDEX]
if remove or id == NO_ID then
set AIR[LAST_INDEX] = AIR[AIR_INDEX]
set AIR_INDEX = AIR_INDEX-1
endif
elseif HERO_INDEX >= 0 and (whichtype == UNIT_TYPE_HERO or whichtype == UNIT_TYPE_RANDOM) then
set LAST_INDEX = GetRandomInt(0,HERO_INDEX)
set id = HERO[LAST_INDEX]
if remove or id == NO_ID then
set HERO[LAST_INDEX] = HERO[HERO_INDEX]
set HERO_INDEX = HERO_INDEX-1
endif
else
debug if HERO_INDEX < 0 then
debug call BJDebugMsg(ERROR+"UNIT_TYPE_HERO array is empty.")
debug call BJDebugMsg(FIX+"Set RESET_ARRAYS = true.")
debug elseif AIR_INDEX < 0 then
debug call BJDebugMsg(ERROR+"UNIT_TYPE_FLYING array is empty.")
debug call BJDebugMsg(FIX+"Set RESET_ARRAYS = true.")
debug elseif GROUND_INDEX < 0 then
debug call BJDebugMsg(ERROR+"UNIT_TYPE_GROUND array is empty.")
debug call BJDebugMsg(FIX+"Set RESET_ARRAYS = true.")
debug else
debug call BJDebugMsg(ERROR+"Unrecognized unit type passed to function.")
debug call BJDebugMsg(FIX+"Use UNIT_TYPE_GROUND, UNIT_TYPE_FLYING, UNIT_TYPE_HERO, or UNIT_TYPE_RANDOM.")
debug endif
return NO_ID
endif
endloop
debug if CHECK_ABILITIES then
debug call CheckAbilities(id)
debug endif
return id
endfunction
endlibrary
Usage:
JASS:
function ...
local unit u_flying = CreateUnit(Player(0),GetRandomId(UNIT_TYPE_FLYING,true),0,0,0)
local unit u_ground = CreateUnit(Player(0),GetRandomId(UNIT_TYPE_GROUND,true),0,0,0)
local unit u_hero = CreateUnit(Player(0),GetRandomId(UNIT_TYPE_HERO,true),0,0,0)
local unit u_random = CreateUnit(Player(0),GetRandomId(UNIT_TYPE_RANDOM,true),0,0,0)
...
endfunction