function LoadToc takes string s returns nothing
if BlzLoadTOCFile(s) then
call PlayMusicBJ("sound\\Music\\mp3music\\HumanX1.mp3")
else
call PlayMusicBJ("sound\\Music\\mp3music\\HumanX1.mp3")
endif
endfunction
function UpdateCam takes nothing returns nothing
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, BlzFrameGetValue(BlzGetFrameByName("EscMenuSliderTemplate", 0)), 0)
call BlzFrameSetText(BlzGetFrameByName("EscMenuLabelTextTemplate", 0), "Distance: " + R2SW(BlzFrameGetValue(BlzGetFrameByName("EscMenuSliderTemplate", 0)), 1, 1))
endfunction
function CreateSliderDistance takes nothing returns nothing
local framehandle fh = BlzCreateFrame("EscMenuSliderTemplate", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 0, 0)
local framehandle label = BlzCreateFrame("EscMenuLabelTextTemplate", fh, 0, 0)
call BlzFrameSetPoint(label, FRAMEPOINT_LEFT, fh, FRAMEPOINT_RIGHT, 0, 0)
call BlzFrameSetAbsPoint(fh, FRAMEPOINT_LEFT, 0.01, 0.56) //below the menu, quest buttons
//call BlzFrameSetSize(fh, 0.139, 0.012) //default size in the fdf.
call BlzFrameSetMinMaxValue(fh, 600, 5000) //limits user can choose
call BlzFrameSetValue(fh, 1650) //starting value, should be used after one changed min max
call BlzFrameSetStepSize(fh, 50) //
endfunction
function CreateCamControl takes nothing returns nothing
call LoadToc("war3mapimported\\templates.toc") //use the custom function to load the Toc, the custom function prints success/fail loading the toc.
call CreateSliderDistance()
call TimerStart(CreateTimer(), 0.4, true, function UpdateCam)
endfunction
function ChangeLumberTextBox takes nothing returns nothing
local framehandle fh = BlzGetFrameByName("ResourceBarUpkeepText" , 0) //Load "ResourceBarLumberText" with creationcontext 0
call BlzFrameSetText(fh , "|Cffffff00Prehistory") //Change the text to Lumber
set fh = null
endfunction
Name | Type | is_array | initial_value |
____Armure | itemtype | No | |
AleoLivre | integer | No | |
armeselect | integer | Yes | |
AuDessus | force | No | |
bag_integer | integervar | No | |
bag_items_stored | integer | No | |
bag_not_compatible | itemcode | Yes | |
bag_number_of_not_compatible | integer | No | |
bag_slot | integer | No | |
bag_store_point | location | No | |
bag_table | hashtable | No | |
bag_tempPoint | location | No | |
blabla | integer | No | |
Bois | integer | Yes | |
boom | integer | Yes | 1 |
Caisse | unit | Yes | |
Caisson | item | Yes | |
Caissonage | unit | Yes | |
CamoJag | boolean | Yes | |
CamoJeep | boolean | Yes | |
CamoM1 | boolean | Yes | |
CamoM7 | boolean | Yes | |
CamoP2 | boolean | Yes | |
CamoSherman | boolean | Yes | |
CamoSU76 | boolean | Yes | |
CamoSU85 | boolean | Yes | |
CamoT26 | boolean | Yes | |
CamoTiger | boolean | Yes | |
champion | unit | No | |
chimique | force | No | |
CL_AbilityLevel | integer | Yes | |
CL_AOE | real | Yes | |
CL_Caster | unit | Yes | |
CL_Count | integer | Yes | |
CL_Damage | integer | Yes | |
CL_FirstTarget | boolean | Yes | |
CL_Group | group | Yes | |
CL_Loc | location | Yes | |
CL_Player | player | Yes | |
CL_Slashes | integer | Yes | |
CL_Special | effect | Yes | |
CL_Target | unit | Yes | |
CL_Victim | unit | Yes | |
compteur | integer | No | |
Computer | force | No | |
Deaths | integer | Yes | |
Delivero | boolean | Yes | |
Dialogue | button | Yes | |
Dialogue2 | dialog | No | |
Dif | integer | No | |
difficulte | integer | Yes | |
doctor | unit | No | |
DS_BallCreationInterval | integer | Yes | |
DS_BallDamages | real | Yes | |
DS_BallDamagesAoe | real | Yes | |
DS_BallDamagesType | attacktype | No | |
DS_BallDamagesTypes2 | damagetype | No | |
DS_BallDirectionAndSpeed | real | Yes | |
DS_BallHeightIncrease | real | Yes | |
DS_BallLifeSteal | real | Yes | |
DS_BallLiveTime | real | Yes | |
DS_BallLocation | location | No | |
DS_BallLocationNew | location | No | |
DS_BallsGroup | group | No | |
DS_CasterLocation | location | No | |
DS_CastersGroup | group | No | |
DS_CircleAoe | real | Yes | |
DS_CircleDirectionAndSpeed | real | Yes | |
DS_CircleStartAngle | real | Yes | |
DS_Duration | real | Yes | |
DS_Effect | string | No | |
DS_Hashtable | hashtable | No | |
DS_NumberOfCircle | integer | Yes | |
DS_TempInteger | integer | No | |
DS_TempInteger2 | integer | No | |
DS_TempReal | real | No | |
DS_TempUnit | unit | No | |
DS_TempUnit2 | unit | No | |
emplacement | location | No | |
EngineJag | boolean | Yes | |
EngineJeep | boolean | Yes | |
EngineM1 | boolean | Yes | |
EngineM7 | boolean | Yes | |
EngineP2 | boolean | Yes | |
EngineSherman | boolean | Yes | |
EngineSU76 | boolean | Yes | |
EngineSU85 | boolean | Yes | |
EngineT26 | boolean | Yes | |
EngineTiger | boolean | Yes | |
Entier | integer | No | |
EntierTemporaire | integer | No | |
Etage | player | No | |
feraille | integer | Yes | |
fighter | player | No | |
fighting | boolean | Yes | |
Fireball | unit | Yes | |
fusil | item | Yes | |
Gain | real | Yes | |
Gold1 | group | No | |
Gold2 | group | No | |
Gold3 | group | No | |
GripAK | boolean | Yes | |
GripColt | boolean | Yes | |
GripEagle | boolean | Yes | |
GripFlamethrower | boolean | Yes | |
GripGlock | boolean | Yes | |
GripLahti | boolean | Yes | |
GripM249 | boolean | Yes | |
GripMinigun | boolean | Yes | |
GripMossberg | boolean | Yes | |
GripP90 | boolean | Yes | |
GripSniper | boolean | Yes | |
GripStinger | boolean | Yes | |
GripTaurus | boolean | Yes | |
GripWebley | boolean | Yes | |
GripWinchester | boolean | Yes | |
group | group | No | |
h_Bolean | boolean | No | |
h_Bolean2 | boolean | No | |
h_Caster | unit | No | |
h_hook | unit | Yes | |
h_Number | integer | No | |
Hero | unit | Yes | |
HeroXPConstant | integer | No | |
HeroXPLevelFactor | integer | No | |
HeroXPPrevLevelFactor | integer | No | |
HeroXPRequired | integer | No | |
i | integer | No | |
integer | integer | No | |
item | item | No | |
JD_Angle | real | Yes | |
JD_Animations | string | Yes | |
JD_Distances | real | Yes | |
JD_Effect | string | Yes | |
JD_Group | group | No | |
JD_HighSettings | real | Yes | |
JD_Integers | integer | Yes | |
JD_JumpHigh | real | Yes | |
JD_ReachedDistance | real | Yes | |
JD_RealTimer | real | Yes | |
JD_SpeedUnits | real | Yes | |
JD_TempPoint | location | Yes | |
JD_TreesDestroy | boolean | Yes | |
JD_Unit | unit | Yes | |
JDA_Animation | string | No | |
JDA_AnimationSpeed | real | No | |
JDA_Collusion | boolean | No | |
JDA_DestroyTrees_Dash | boolean | No | |
JDA_JumpHigh_Distance | real | No | |
JDA_SpecialEffect | string | No | |
JDA_Speed | real | No | |
JDA_TargetPoint | location | No | |
JDA_Unit | unit | No | |
Joue | force | No | |
Joueur | integer | No | |
Joueur2 | integer | No | |
JoueurDansMultitable | integer | Yes | |
JumpAngle | real | No | |
JumpAnimation | effect | No | |
JumpDa | integer | No | |
JumpDummy | unit | No | |
JumpEnd | integer | No | |
Jumper | unit | Yes | |
JumpHeight | real | No | |
JumpMaxHeight | real | No | |
JumpPoint | location | No | |
JumpTime | real | No | |
kb | integervar | No | |
KB_Angle | real | Yes | |
KB_Dist | real | Yes | |
KB_Max | integer | No | |
KB_MaxDist | real | Yes | |
KB_n | integer | No | |
KB_Speed | real | Yes | |
KB_Unit | unit | Yes | |
KB_Used | boolean | Yes | |
Kills | integer | Yes | |
KitJag | boolean | Yes | |
KitJeep | boolean | Yes | |
KitM1 | boolean | Yes | |
KitM7 | boolean | Yes | |
KitP2 | boolean | Yes | |
KitSherman | boolean | Yes | |
KitSU76 | boolean | Yes | |
KitSU85 | boolean | Yes | |
KitT26 | boolean | Yes | |
KitTiger | boolean | Yes | |
LightMaterialDagger | boolean | Yes | |
LightMaterialDeath | boolean | Yes | |
LightMaterialFlail | boolean | Yes | |
LightMaterialHalberd | boolean | Yes | |
LightMaterialJousting | boolean | Yes | |
LightMaterialLight | boolean | Yes | |
LightMaterialLongsword | boolean | Yes | |
LightMaterialMace | boolean | Yes | |
LightMaterialMine | boolean | Yes | |
LightMaterialStaff | boolean | Yes | |
LightMaterialWarhammer | boolean | Yes | |
LimiteDecoupeur | integer | Yes | 5 |
LimitePanneau | integer | Yes | 5 |
LocalFiles_WarningMessage | string | No | |
MagazineAK | boolean | Yes | |
MagazineColt | boolean | Yes | |
MagazineEagle | boolean | Yes | |
MagazineFlamethrower | boolean | Yes | |
MagazineGlock | boolean | Yes | |
MagazineLahti | boolean | Yes | |
MagazineM249 | boolean | Yes | |
MagazineMinigun | boolean | Yes | |
MagazineMossberg | boolean | Yes | |
MagazineP90 | boolean | Yes | |
MagazineSniper | boolean | Yes | |
MagazineStinger | boolean | Yes | |
MagazineTaurus | boolean | Yes | |
MagazineWebley | boolean | Yes | |
MagazineWinchester | boolean | Yes | |
Mana | real | No | |
MapName | string | No | |
Max_Index | integer | No | |
Meca | unit | No | |
MOB | group | No | |
Mobiage | unitcode | No | |
momo | integer | No | |
MUI_1 | integer | No | |
MUI_2 | integer | Yes | |
MUI_3 | integervar | No | |
MyResourceBarCount | integer | No | |
MyResourceFieldCount | integer | No | |
MyResourceFieldCreateFree | trigger | No | |
MyResourceFieldFreeX | real | No | |
MyResourceFieldFreeY | real | No | |
MyResourceFieldHideData | boolean | Yes | |
MyResourceFieldHideTrigger | trigger | No | |
MyResourceFieldIcons | imagefile | Yes | |
MyResourceFieldLastLineStart | integer | No | |
MyResourceFieldTooltipText | string | Yes | |
MyResourceFieldTooltipTitle | string | Yes | |
MyResourceFieldValue | string | Yes | |
night | boolean | Yes | |
night2 | integer | No | |
Nitro | item | No | |
nu | boolean | Yes | |
Nuit | boolean | No | |
number | integer | No | |
objet | item | Yes | |
Or | integer | Yes | |
p | player | No | |
ParingExtensionDagger | boolean | Yes | |
ParingExtensionDeath | boolean | Yes | |
ParingExtensionFlail | boolean | Yes | |
ParingExtensionHalberd | boolean | Yes | |
ParingExtensionJoust | boolean | Yes | |
ParingExtensionLight | boolean | Yes | |
ParingExtensionLongsword | boolean | Yes | |
ParingExtensionMace | boolean | Yes | |
ParingExtensionMine | boolean | Yes | |
ParingExtensionStaff | boolean | Yes | |
ParingExtensionWarhammer | boolean | Yes | |
patient | unit | No | |
Philosophe | force | No | |
pla | player | No | |
Player | player | No | |
PlayerIndex | integer | No | |
PlayerIndex_Copy | integer | No | |
po | location | Yes | |
point | location | No | |
POINT | location | No | |
point1 | location | No | |
point2 | location | No | |
POINT2 | location | No | |
PointTourelle | location | Yes | |
PorteArmure | boolean | Yes | |
PorteSortie | unit | Yes | |
PrixPanel | integer | Yes | 100 |
PrixWood | integer | Yes | 100 |
Question | StringExt | Yes | |
Questionetat | integer | No | |
questionsdejaposees | integer | Yes | |
RangeNumber | integer | No | |
ravitaillement | integer | Yes | |
RedDotAK | boolean | Yes | |
RedDotColt | boolean | Yes | |
RedDotEagle | boolean | Yes | |
RedDotFlamethrower | boolean | Yes | |
RedDotGlock | boolean | Yes | |
RedDotLahti | boolean | Yes | |
RedDotM249 | boolean | Yes | |
RedDotMinigun | boolean | Yes | |
RedDotMossberg | boolean | Yes | |
RedDotP90 | boolean | Yes | |
RedDotSniper | boolean | Yes | |
RedDotStinger | boolean | Yes | |
RedDotTaurus | boolean | Yes | |
RedDotWebley | boolean | Yes | |
RedDotWinchester | boolean | Yes | |
Reponse | force | No | |
Reponse1 | StringExt | Yes | |
Reponse2 | StringExt | Yes | |
Reponse3 | StringExt | Yes | |
Reponse4 | StringExt | Yes | |
ResourceBois1 | integer | Yes | |
ResourceBois2 | integer | Yes | |
ResourceBois3 | integer | Yes | |
ResourceOr1 | integer | Yes | |
ResourceOr2 | integer | Yes | |
ResourceOr3 | integer | Yes | |
SaveAbilityType | abilcode | Yes | |
SaveAbilityTypeMax | integer | No | |
SaveCodeColored | string | No | |
SaveCount | integer | No | |
SaveCurrentSlot | integer | Yes | |
SaveHeroName | boolean | No | |
SaveItemType | itemcode | Yes | |
SaveItemTypeMax | integer | No | |
SaveLoad_Slot | integer | No | |
SaveLoadEvent | real | No | |
SaveLoadEvent_Code | string | No | |
SaveLoadEvent_Player | player | No | |
SaveLoadMaxLength | integer | No | |
SaveMaxValue | integer | Yes | |
SaveNameList | string | Yes | |
SaveNameMax | integer | No | |
SavePlayerHero | unit | Yes | |
SavePlayerLoading | boolean | Yes | |
SaveShowCode | boolean | No | |
SaveTempInt | integer | No | |
SaveTempReal | real | No | |
SaveTempString | string | No | |
SaveTempUnit | unit | No | |
SaveUnitMaxStat | integer | No | |
SaveUnitType | unitcode | Yes | |
SaveUnitTypeMax | integer | No | |
SaveUseGUI | boolean | No | |
SaveValue | integer | Yes | |
SE_AttackType | attacktype | No | |
SE_DamageType | damagetype | No | |
SE_ExplosionDamages | real | Yes | |
SE_ExplosionDamagesAoe | real | Yes | |
SE_ExplosionModel | string | No | |
SE_Hash | hashtable | No | |
SE_Integer | integer | No | |
SE_Integer2 | integer | No | |
SE_Integer3 | integer | No | |
SE_Integer4 | integer | No | |
SE_Point | location | No | |
SE_Point2 | location | No | |
SE_Real | real | No | |
SE_Real2 | real | No | |
SE_Real3 | real | No | |
SE_RockGroup | group | No | |
SE_RockHeightDecrement | real | Yes | |
SE_RockHeightSpeed | real | Yes | |
SE_RocksAngle | real | Yes | |
SE_RocksAngleRandom | real | Yes | |
SE_RockScaleMax | real | Yes | |
SE_RockScaleMin | real | Yes | |
SE_RocksDamages | real | Yes | |
SE_RocksDamagesAoe | real | Yes | |
SE_RocksIntervalAngle | real | Yes | |
SE_RocksNumber | integer | Yes | |
SE_RockSpeed | real | Yes | |
SE_RocksUnitType | unitcode | No | |
SE_SandInterval | integer | Yes | |
SE_SandModel | string | No | |
SE_SandSpeed | real | Yes | |
SE_SandUnitType | unitcode | No | |
SE_Unit | unit | No | |
SE_Unit2 | unit | No | |
SE_WaveGroup | group | No | |
SharpeDagger | boolean | Yes | |
SharpeDeath | boolean | Yes | |
SharpeFlail | boolean | Yes | |
SharpeHalberd | boolean | Yes | |
SharpeJoust | boolean | Yes | |
SharpeLight | boolean | Yes | |
SharpeLongsword | boolean | Yes | |
SharpeMace | boolean | Yes | |
SharpeMine | boolean | Yes | |
SharpeStaff | boolean | Yes | |
SharpeWarhammer | boolean | Yes | |
ShootingRange | destructable | Yes | |
ShootingRange2 | unit | Yes | |
Skill | integer | Yes | |
smoke | effect | Yes | |
spe | effect | Yes | |
start | force | No | |
Tableau | integer | Yes | |
Temp | integer | No | |
TempAngle | real | No | |
TempGroup | group | No | |
TempPoint | location | No | |
TempPoint2 | location | No | |
Temps | timer | No | |
TempTarget | unit | No | |
TempX | real | No | |
TempY | real | No | |
Tourelle | unit | Yes | |
trash | unit | No | |
Trashes | group | No | |
tumb | unit | No | |
UDex | integer | No | |
UDexGen | integer | No | |
UDexNext | integer | Yes | |
UDexPrev | integer | Yes | |
UDexRecycle | integer | No | |
UDexUnits | unit | Yes | |
UDexWasted | integer | No | |
UMovNext | integer | Yes | |
UMovPrev | integer | Yes | |
unique | boolean | Yes | |
UnitIndexerEnabled | boolean | No | |
UnitIndexEvent | real | No | |
UnitMoving | boolean | Yes | |
UnitMovingEvent | real | No | |
UnitMovingX | real | Yes | |
UnitMovingY | real | Yes | |
VARIABLEHEROE | unit | No | |
victime | unit | No | |
victime2 | unit | No | |
Vie | real | No | |
vitesse | real | Yes | |
woodcut | string | No | |
zz_ExperienceFloatingTextTime | real | No | |
zz_ExperiencePerLevel | real | No | |
zz_FinalExperience | real | No | |
zzStr_ExperienceTag | string | No |
function Trig_HeroNames_Actions takes nothing returns nothing
set udg_SaveNameList[0] = null
// Blood Mage
set udg_SaveNameList[72] = "Eldin Sunstrider"
set udg_SaveNameList[1] = "Tanin Hawkwing"
set udg_SaveNameList[2] = "Lorn Bloodseeker"
set udg_SaveNameList[3] = "Aldos Firestar"
set udg_SaveNameList[4] = "Gilaras Drakeson"
set udg_SaveNameList[5] = "Hale Magefire"
set udg_SaveNameList[6] = "Kath'ranis Remar"
set udg_SaveNameList[7] = "Tyoril Sunchaser"
set udg_SaveNameList[8] = "Sylvos Windrunner"
set udg_SaveNameList[9] = "Tenris Mirkblood"
set udg_SaveNameList[10] = "Marakanis Starfury"
set udg_SaveNameList[11] = "Geldor Earthfire"
set udg_SaveNameList[12] = "Halendor Burnkin"
set udg_SaveNameList[13] = "Kelen the Destroyer"
// Tauren Chieften
set udg_SaveNameList[14] = "Marn Thunderhorn"
set udg_SaveNameList[15] = "Tygore Dusthoof"
set udg_SaveNameList[16] = "Tam Windtotem"
set udg_SaveNameList[17] = "Durn Harpyslayer"
set udg_SaveNameList[18] = "Kam Ghoststeer"
set udg_SaveNameList[19] = "Kel Stonebull"
set udg_SaveNameList[20] = "Mull Stormhoof"
set udg_SaveNameList[21] = "Grok Bloodhorn"
set udg_SaveNameList[22] = "Malar Plainstrider"
set udg_SaveNameList[23] = "Taur Runetotem"
// Lich
set udg_SaveNameList[24] = "Ordin Frostbane"
set udg_SaveNameList[25] = "Ras Splinterspine"
set udg_SaveNameList[26] = "Morbent Fell"
set udg_SaveNameList[27] = "Rage Winterchill"
set udg_SaveNameList[28] = "Araj the Summoner"
set udg_SaveNameList[29] = "Kali'naj Dethknell"
set udg_SaveNameList[30] = "Rak Coldskull"
set udg_SaveNameList[31] = "Din Frostfire"
set udg_SaveNameList[32] = "Calis Wraithson"
set udg_SaveNameList[33] = "Venim Iceblade"
set udg_SaveNameList[34] = "Naze the Eternal"
set udg_SaveNameList[35] = "Ras Frostwhisper"
set udg_SaveNameList[36] = "Coldreaver"
set udg_SaveNameList[37] = "Cho'Nammoth"
set udg_SaveNameList[38] = "Kryptikk Soulslayer"
set udg_SaveNameList[39] = "Alandil Lieng"
// Demon Hunter
set udg_SaveNameList[40] = "Shadowsong"
set udg_SaveNameList[41] = "Shadowfury"
set udg_SaveNameList[42] = "Shadowstalker"
set udg_SaveNameList[43] = "Flameseeker"
set udg_SaveNameList[44] = "Darkweaver"
set udg_SaveNameList[45] = "Darkterror"
set udg_SaveNameList[46] = "Darksorrow"
set udg_SaveNameList[47] = "Sindweller"
set udg_SaveNameList[48] = "Painkiller"
set udg_SaveNameList[49] = "Hellbourne"
set udg_SaveNameList[50] = "Wrathbringer"
set udg_SaveNameList[51] = "Ragerunner"
set udg_SaveNameList[52] = "Firebrand"
set udg_SaveNameList[53] = "Bloodwrath"
set udg_SaveNameList[54] = "Terrorblade"
// Naga Sea Witch
set udg_SaveNameList[55] = "Anna Kondra"
set udg_SaveNameList[56] = "Scilla Murkshadow"
set udg_SaveNameList[57] = "Ursula Snakemane"
set udg_SaveNameList[58] = "Lady Venomtongue"
set udg_SaveNameList[59] = "Lady Serpentra"
set udg_SaveNameList[60] = "Lady Darkscale"
set udg_SaveNameList[61] = "Serena Scarscale"
set udg_SaveNameList[62] = "Asprah Serpus"
set udg_SaveNameList[63] = "Venna Seastorm"
set udg_SaveNameList[64] = "Charib'dishal"
// Beastmaster
set udg_SaveNameList[65] = "Mag Bearmaul"
set udg_SaveNameList[66] = "Tagar Bearclaw"
set udg_SaveNameList[67] = "Gorsh Talonfang"
set udg_SaveNameList[68] = "Maxx Rocmane"
set udg_SaveNameList[69] = "Gaz Boartusk"
set udg_SaveNameList[70] = "Mok Rocksnout"
set udg_SaveNameList[71] = "Gish Eagle Eye"
endfunction
//===========================================================================
function InitTrig_HeroNames takes nothing returns nothing
set gg_trg_HeroNames = CreateTrigger( )
call TriggerAddAction( gg_trg_HeroNames, function Trig_HeroNames_Actions )
endfunction
library SaveHelperLib requires Sync, PlayerUtils, SaveFile
// Uses GUI variables from the "Save Init" trigger. You can modify these functions to use your own variables.
private keyword SaveHelperInit
struct SaveHelper extends array
static constant hashtable Hashtable = InitHashtable()
static constant integer KEY_ITEMS = 1
static constant integer KEY_UNITS = 2
static constant integer KEY_NAMES = 3
static method MaxCodeSyncLength takes nothing returns integer
return udg_SaveLoadMaxLength
endmethod
static method GetUserHero takes User user returns unit
return udg_SavePlayerHero[user.id]
endmethod
static method RemoveUserHero takes User user returns nothing
call RemoveUnit(udg_SavePlayerHero[user.id])
set udg_SavePlayerHero[user.id] = null
endmethod
static method SetUserHero takes User user, unit u returns nothing
set udg_SavePlayerHero[user.id] = u
endmethod
static method IsUserLoading takes User user returns boolean
return udg_SavePlayerLoading[user.id]
endmethod
static method SetUserLoading takes User user, boolean flag returns nothing
set udg_SavePlayerLoading[user.id] = flag
endmethod
static method SetSaveSlot takes User user, integer slot returns nothing
set udg_SaveCurrentSlot[user.id] = slot
endmethod
static method GetSaveSlot takes User user returns integer
return udg_SaveCurrentSlot[user.id]
endmethod
static method GetUnitTitle takes unit u returns string
return GetObjectName(GetUnitTypeId(u)) + " (" + GetHeroProperName(u) + ")"
endmethod
static method GetMapName takes nothing returns string
return udg_MapName
endmethod
static method MaxAbilityLevel takes nothing returns integer
return 10
endmethod
static method MaxAbilities takes nothing returns integer
return udg_SaveAbilityTypeMax
endmethod
static method MaxItems takes nothing returns integer
return udg_SaveItemTypeMax
endmethod
static method MaxUnits takes nothing returns integer
return udg_SaveUnitTypeMax
endmethod
static method MaxNames takes nothing returns integer
return udg_SaveNameMax
endmethod
static method MaxHeroStat takes nothing returns integer
return udg_SaveUnitMaxStat
endmethod
static method GetAbility takes integer index returns integer
return udg_SaveAbilityType[index]
endmethod
static method GetItem takes integer index returns integer
return udg_SaveItemType[index]
endmethod
static method GetUnit takes integer index returns integer
return udg_SaveUnitType[index]
endmethod
static method ConvertItemId takes integer itemId returns integer
return LoadInteger(thistype.Hashtable, KEY_ITEMS, itemId)
endmethod
static method ConvertUnitId takes integer unitId returns integer
return LoadInteger(thistype.Hashtable, KEY_UNITS, unitId)
endmethod
static method GetHeroNameFromID takes integer id returns string
return udg_SaveNameList[id]
endmethod
static method GetHeroNameID takes string name returns integer
return LoadInteger(thistype.Hashtable, KEY_NAMES, StringHash(name))
endmethod
static method ConvertHeroName takes string name returns string
return udg_SaveNameList[GetHeroNameID(name)]
endmethod
static method GUILoadNext takes nothing returns nothing
set udg_SaveValue[udg_SaveCount] = Savecode(udg_SaveTempInt).Decode(udg_SaveMaxValue[udg_SaveCount])
endmethod
static method GetLevelXP takes integer level returns real
local real xp = udg_HeroXPLevelFactor // level 1
local integer i = 1
loop
exitwhen i > level
set xp = (xp*udg_HeroXPPrevLevelFactor) + (i+1) * udg_HeroXPLevelFactor
set i = i + 1
endloop
return xp-udg_HeroXPLevelFactor
endmethod
static method Init takes nothing returns nothing // called at the end of "Save Init" trigger
local integer i = 0
loop
exitwhen i >= thistype.MaxItems() //or udg_SaveItemType[i] == 0
call SaveInteger(thistype.Hashtable, KEY_ITEMS, udg_SaveItemType[i], i)
set i = i + 1
endloop
set i = 0
loop
exitwhen i >= thistype.MaxUnits() //or udg_SaveUnitType[i] == 0
call SaveInteger(thistype.Hashtable, KEY_UNITS, udg_SaveUnitType[i], i)
set i = i + 1
endloop
set i = 1
loop
exitwhen i >= SaveHelper.MaxNames() or udg_SaveNameList[i] == "" or udg_SaveNameList[i] == null
call SaveInteger(thistype.Hashtable, KEY_NAMES, StringHash(udg_SaveNameList[i]), i)
set i = i + 1
endloop
endmethod
endstruct
function GetHeroSaveCode takes unit u returns string
local Savecode savecode = Savecode.create()
local player p = GetOwningPlayer(u)
local User user = User[p]
local integer uid = GetUnitTypeId(u)
local integer uidSmall = SaveHelper.ConvertUnitId(uid)
local string title = GetObjectName(uid)
local integer i = 0
local integer l = 0
local integer c = 0
local string s = null
if (udg_SaveUseGUI) then
call TriggerExecute(gg_trg_Save_GUI)
return udg_SaveTempString
endif
// save abilities
loop
exitwhen i > SaveHelper.MaxAbilities()
set l = GetUnitAbilityLevel(u, SaveHelper.GetAbility(i))
if (l > 0) then
call savecode.Encode(l, SaveHelper.MaxAbilityLevel())
call savecode.Encode(i, SaveHelper.MaxAbilities())
set c = c + 1
endif
set i = i + 1
endloop
// save amount of skills and skill points
call savecode.Encode(c, SaveHelper.MaxAbilities())
call savecode.Encode(GetHeroSkillPoints(u), 999)
// save items
set i = 0
loop
exitwhen i > 5
set l = GetItemTypeId(UnitItemInSlot(u, i))
call savecode.Encode(SaveHelper.ConvertItemId(l), SaveHelper.MaxItems())
set i = i + 1
endloop
// save stats
call savecode.Encode(GetHeroStr(u, false), SaveHelper.MaxHeroStat())
call savecode.Encode(GetHeroAgi(u, false), SaveHelper.MaxHeroStat())
call savecode.Encode(GetHeroInt(u, false), SaveHelper.MaxHeroStat())
// save xp
call savecode.Encode(R2I( (GetHeroXP(u)) / SaveHelper.GetLevelXP(GetHeroLevel(u)) * 100), 100) // percentage
call savecode.Encode(GetHeroLevel(u), 100)
// save hero
call savecode.Encode(SaveHelper.GetHeroNameID(GetHeroProperName(u)), SaveHelper.MaxNames())
call savecode.Encode(uidSmall, SaveHelper.MaxUnits())
set s = savecode.Save(p, 1)
call savecode.destroy()
set u = null
return s
endfunction
function LoadHeroFromString takes player p, string s returns boolean
local User user = User[p]
local integer pid = GetPlayerId(p)
local string temp
local unit u
local integer i
local integer uidSmall
local integer array values
local Savecode loadcode = Savecode.create()
// check the code
if (not loadcode.Load(p, s, 1)) then
if (s != "") then
call DisplayTextToPlayer(p, 0 , 0, "Invalid code: \"" + s + "\"")
endif
return false
endif
// remove old hero
call SaveHelper.RemoveUserHero(user)
// create new one
set uidSmall = loadcode.Decode(SaveHelper.MaxUnits())
set u = CreateUnit(p, SaveHelper.GetUnit(uidSmall), 0, 0, 0)
call SaveHelper.SetUserHero(user, u)
// load name
set temp = SaveHelper.GetHeroNameFromID(loadcode.Decode(SaveHelper.MaxNames()))
if (temp != null) then
call BlzSetHeroProperName(u, temp)
endif
// load XP %
set values[0] = loadcode.Decode(100)
set values[1] = loadcode.Decode(100)
set values[2] = R2I((values[1] / 100.) * SaveHelper.GetLevelXP(values[0]))
call SetHeroXP(u, values[2], false)
// load hero level
if (GetHeroLevel(u) != values[0]) then
call SetHeroLevel(u, values[0], false)
endif
// attributes
call SetHeroInt(u, loadcode.Decode(999), false)
call SetHeroAgi(u, loadcode.Decode(999), false)
call SetHeroStr(u, loadcode.Decode(999), false)
// items
set i=0
loop
exitwhen i > 5
call UnitAddItemToSlotById(u, SaveHelper.GetItem(loadcode.Decode(SaveHelper.MaxItems())), 5-i)
set i = i + 1
endloop
// skill points
set values[0] = loadcode.Decode(999)
call UnitModifySkillPoints(u, 0)
call UnitModifySkillPoints(u, values[0] - GetHeroSkillPoints(u))
// abilities
set values[1] = loadcode.Decode(SaveHelper.MaxAbilities())
set i = 0
loop
exitwhen i == values[1]
set values[0] = SaveHelper.GetAbility(loadcode.Decode(SaveHelper.MaxAbilities()))
call UnitAddAbility(u, values[0])
call SetUnitAbilityLevel(u, values[0], loadcode.Decode(SaveHelper.MaxAbilityLevel()))
set i = i + 1
endloop
if (GetLocalPlayer() == p) then
call ClearSelection()
call SelectUnit(u, true)
endif
return true
endfunction
private function LoadSaveSlot_OnLoad takes nothing returns nothing
local SyncData req = GetSyncedData()
local User user = User[req.from]
call SaveHelper.SetUserLoading(user, false)
if (req.lastError > 0) then
call DisplayTextToPlayer(req.from, 0, 0, "There was an issue syncing your character data. Error ID #|cffffcc00" + I2S(req.lastError) + "|r. Please try again.")
return
elseif (not udg_SaveUseGUI) then
if (LoadHeroFromString(req.from, req.readString(0))) then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Loaded " + user.nameColored + "'s character in |cffffcc00" + R2S(req.timeElapsed) + "|r seconds.")
else
call SaveHelper.SetSaveSlot(user, 0)
endif
else
set udg_SaveLoadEvent_Code = req.readString(0)
set udg_SaveLoadEvent_Player = req.from
set udg_SaveLoadEvent = 1.
set udg_SaveLoadEvent = -1
endif
call req.destroy()
endfunction
function LoadSaveSlot takes player p, integer slot returns nothing
local SaveFile savefile = SaveFile(slot)
local User user = User[p]
local SyncData req
if (SaveHelper.IsUserLoading(user)) then
call DisplayTextToPlayer(p, 0, 0, "Please wait while your character synchronizes.")
else
set req = SyncData.create(p)
call req.addEventListener(Filter(function LoadSaveSlot_OnLoad))
call req.syncString(savefile.getData(), SaveHelper.MaxCodeSyncLength())
call ClearTextMessages()
call DisplayTimedTextToPlayer(p, 0, 0, 15, "Synchronzing with other players...")
call SaveHelper.SetSaveSlot(user, slot)
endif
endfunction
function DeleteCharSlot takes player p, integer slot returns nothing
if (GetLocalPlayer() == p) then
call SaveFile(slot).clear(p, slot)
endif
endfunction
function SaveCharToSlot takes unit u, integer slot, string s returns nothing
local player p = GetOwningPlayer(u)
if (GetLocalPlayer() == p) then
call SaveFile(slot).create(p, SaveHelper.GetUnitTitle(u), slot, s)
endif
call SaveHelper.SetSaveSlot(User[p], slot)
endfunction
endlibrary
library SaveFile requires FileIO
private keyword SaveFileInit
struct SaveFile extends array
static constant string ManualPath = "Manual"
static constant string InvalidPath = "Unknown"
static constant integer MIN = 1
static constant integer MAX = 10
private File file
static method operator Folder takes nothing returns string
return udg_MapName
endmethod
static method getPath takes integer slot returns string
if (slot == 0) then
return .Folder + "\\SaveSlot_" + .InvalidPath + ".pld"
elseif (slot > 0 and (slot < .MIN or slot > .MAX)) then
return .Folder + "\\SaveSlot_" + .InvalidPath + ".pld"
elseif (slot < 0) then
return .Folder + "\\SaveSlot_" + .ManualPath + ".pld"
endif
return .Folder + "\\SaveSlot_" + I2S(slot) + ".pld"
endmethod
static method create takes player p, string title, integer slot, string data returns thistype
if (GetLocalPlayer() == p) then
call FileIO_Write(.getPath(slot), title + "\n" + data)
endif
return slot
endmethod
static method clear takes player p, integer slot returns thistype
if (GetLocalPlayer() == p) then
call FileIO_Write(.getPath(slot), "")
endif
return slot
endmethod
static method exists takes integer slot returns boolean // async
return FileIO_Read(.getPath(slot)) != null
endmethod
method getLines takes integer line, boolean includePrevious returns string // async
local string contents = FileIO_Read(.getPath(this))
local integer len = StringLength(contents)
local string char = null
local string buffer = ""
local integer curLine = 0
local integer i = 0
loop
exitwhen i > len
set char = SubString(contents, i, i + 1)
if (char == "\n") then
set curLine = curLine + 1
if (curLine > line) then
return buffer
endif
if (not includePrevious) then
set buffer = ""
endif
else
set buffer = buffer + char
endif
set i = i + 1
endloop
if (curLine == line) then
return buffer
endif
return null
endmethod
method getLine takes integer line returns string // async
return .getLines(line, false)
endmethod
method getTitle takes nothing returns string // async
return .getLines(0, false)
endmethod
method getData takes nothing returns string // async
return .getLines(1, false)
endmethod
implement SaveFileInit
endstruct
private module SaveFileInit
private static method onInit takes nothing returns nothing
//set thistype.Folder = udg_MapName
endmethod
endmodule
endlibrary
library SaveExample initializer Init requires SaveHelperLib
private function OnSave takes nothing returns boolean
local player p = GetTriggerPlayer()
local unit u = SaveHelper.GetUserHero(User[p])
local string s = GetHeroSaveCode(u) // from "SaveHelper" library
if (udg_SaveUseGUI) then
set u = null
return false
endif
if (GetLocalPlayer() == p) then
call SaveFile.create(p, SaveHelper.GetUnitTitle(u), -1, s)
call ClearTextMessages()
endif
call DisplayTimedTextToPlayer(p, 0, 0, 0, "If automatic loading does not work for you, then you may try -load <code>.\n\n|cffffcc00Load Code:|r " + Savecode_colorize(s))
set u = null
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local User user = User.first
loop
exitwhen user == User.NULL
call TriggerRegisterPlayerChatEvent(t, user.toPlayer(), "-save", true)
set user = user.next
endloop
call TriggerAddCondition(t, Filter(function OnSave))
endfunction
endlibrary
library LoadExample initializer Init requires Sync, SaveHelperLib, PlayerUtils
private function OnReceiveCode takes nothing returns boolean
local SyncData d = GetSyncedData()
local User user = User[d.from]
if (d.lastError > 0) then
call DisplayTextToPlayer(d.from, 0, 0, "There was an error syncing save data (" + I2S(d.lastError) + "), attempting to continue...")
endif
call SaveHelper.SetUserLoading(user, false)
if (LoadHeroFromString(d.from, d.readString(0))) then // from "SaveHelper" library
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Loaded " + User[d.from].nameColored + "'s character in |cffffcc00" + R2S(d.timeElapsed) + "|r seconds.")
else
call SaveHelper.SetSaveSlot(user, 0)
endif
call d.destroy()
return false
endfunction
private function Actions takes nothing returns boolean
local player p = GetTriggerPlayer()
local User user = User[p]
local string s = SubString(GetEventPlayerChatString(), 0, 6)
local SaveFile savefile
local SyncData data
if (udg_SaveUseGUI) then
return false
endif
if (SaveHelper.IsUserLoading(user)) then
call DisplayTextToPlayer(p, 0, 0, "Please wait while your character synchronizes.")
return false
endif
if (s == "-load ") then
// check if the user typed a loadslot or a loadcode
set s = SubString(GetEventPlayerChatString(), 6, 999)
if (S2I(s) > 0) then // loadslot
// get the contents of the save slot and sync it
set data = SyncData.create(p)
call data.addEventListener(Filter(function OnReceiveCode))
call data.syncString(SaveFile(S2I(s)).getData(), SaveHelper.MaxCodeSyncLength())
call SaveHelper.SetUserLoading(user, true)
call SaveHelper.SetSaveSlot(user, S2I(s))
else // loadcode
set s = SubString(GetEventPlayerChatString(), 6, 999)
if (LoadHeroFromString(p, s)) then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, user.nameColored + " has loaded their character manually.")
endif
endif
elseif (s == "-load") then
// get the contents of the manual save slot and sync it
set data = SyncData.create(p)
call data.addEventListener(Filter(function OnReceiveCode))
call data.syncString(SaveFile(-1).getData(), SaveHelper.MaxCodeSyncLength())
call SaveHelper.SetUserLoading(user, true)
call SaveHelper.SetSaveSlot(user, S2I(s))
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local User user = User.first
loop
exitwhen user == User.NULL
call TriggerRegisterPlayerChatEvent(t, user.toPlayer(), "-load", false )
set user = user.next
endloop
call TriggerAddCondition(t, Filter(function Actions))
endfunction
endlibrary
library Sync requires SyncInteger, optional PlayerUtils
/***************************************************************
*
* v1.3.0, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*
* This library allows you to quickly synchronize async data such as
* the contents of a local file to all players in the map by using the game cache.
*
* Full Documentation: -http://www.hiveworkshop.com/forums/pastebin.php?id=p4f84s
*
* _________________________________________________________________________
* 1. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script to your map and save it (requires JassHelper *or* JNGP)
*
* SyncInteger: https://www.hiveworkshop.com/threads/syncinteger.278674/
* PlayerUtils: https://www.hiveworkshop.com/threads/playerutils.278559/
* _________________________________________________________________________
* 2. API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* struct SyncData
*
* method start takes nothing returns nothing
* method startChunk takes integer i, integer end returns nothing
* method refresh takes nothing returns nothing
* method destroy takes nothing returns nothing
*
* method addInt takes integer i returns nothing
* method addReal takes integer i returns nothing
* method addString takes string s, integer len returns nothing
* method addBool takes booleanflag returns nothing
*
* method readInt takes integer index returns integer
* method readReal takes integer index returns integer
* method readString takes integer index returns string
* method readBool takes integer index returns boolean
*
* method hasInt takes integer index returns boolean
* method hasReal takes integer index returns boolean
* method hasString takes integer index returns boolean
* method hasBool takes integer index returns boolean
*
* method isPlayerDone takes player p returns boolean
* method isPlayerIdDone takes integer pid returns boolean
*
* method addEventListener takes filterfunc func returns nothing
*
* ---------
*
* filterfunc onComplete
* filterfunc onError
* filterfunc onUpdate
* trigger trigger
*
* readonly player from
*
* readonly real timeStarted
* readonly real timeFinished
* readonly real timeElapsed
*
* readonly integer intCount
* readonly integer boolCount
* readonly integer strCount
* readonly integer realCount
* readonly integer playersDone
*
* readonly boolean buffering
*
* readonly static integer last
* readonly static player LocalPlayer
* readonly static boolean Initialized
*
* static method create takes player from returns SyncData
* static method destroy takes nothing returns nothing
* static method gameTime takes nothing returns real
*
* function GetSyncedData takes nothing returns SyncData
*
***************************************************************/
globals
// characters that can be synced (ascii)
private constant string ALPHABET = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\"\t\n"
// safe characters for use in game cache keys
// (case sensitive)
private constant string SAFE_KEYS = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\"\t\n"
// stop reading the string buffer when reaching this char (this char cannot be synced)
private constant string TERM_CHAR = "~"
// how fast the buffer updates
private constant real UPDATE_PERIOD = 0.03125
// automatically recycle indices when the syncing player leaves
private constant boolean AUTO_DESTROY_ON_LEAVE = true
// automatically stop buffering when an error occurs
private constant boolean STOP_BUFFERING_ON_ERROR = true
// preload game cache key strings on init
private constant boolean PRELOAD_STR_CACHE = true
// size of the alphabet
private constant integer ALPHABET_BASE = StringLength(ALPHABET)
// maximum number of strings *per instance*
private constant integer MAX_STRINGS = 8192 // or any arbitrary high number
// filenames for gc (short names have faster sync time)
private constant string CACHE_FILE = "i"
private constant string CACHE_FILE_STR = "s"
// don't edit below this line
constant integer EVENT_SYNC_CACHE = 3
constant integer SYNC_ERROR_TIMEOUT = 1
constant integer SYNC_ERROR_PLAYERLEFT = 2
private SelectionSync Synchronizer
endglobals
//**************************************************************
function GetSyncedData takes nothing returns SyncData
return SyncData(SyncData.Last)
endfunction
public function I2Char takes string alphabet, integer i returns string
return SubString(alphabet, i, i + 1)
endfunction
public function Char2I takes string alphabet, string c returns integer
local integer i = 0
local string s
local integer l = StringLength(alphabet)
loop
set s = I2Char(alphabet, i)
exitwhen i == l
if (s == c) then
return i
endif
set i = i + 1
endloop
return 0
endfunction
public function ConvertBase takes string alphabet, integer i returns string
local integer b
local string s = ""
local integer l = StringLength(alphabet)
if i < l then
return I2Char(alphabet, i)
endif
loop
exitwhen i <= 0
set b = i - ( i / l ) * l
set s = I2Char(alphabet, b) + s
set i = i / l
endloop
return s
endfunction
public function PopulateString takes string s, integer makeLen returns string
local integer i = 0
local integer l = StringLength(s)
if (l == makeLen) then
return s
endif
set l = makeLen-l
loop
exitwhen i > l
set s = s + TERM_CHAR
set i = i + 1
endloop
return s
endfunction
//**************************************************************
globals
// string table keys
private constant integer KEY_STR_POS = (0*MAX_STRINGS)
private constant integer KEY_STR_LEN = (1*MAX_STRINGS)
// pending data storage space
private constant integer KEY_STR_CACHE = (2*MAX_STRINGS)
endglobals
struct SyncData
real timeout
filterfunc onComplete
filterfunc onError
filterfunc onUpdate
trigger trigger
readonly integer lastError
readonly player from
readonly real timeStarted
readonly real timeFinished
readonly real timeElapsed
readonly integer intCount
readonly integer boolCount
readonly integer strCount
readonly integer realCount
readonly integer playersDone
readonly boolean buffering
readonly static boolean Initialized = false
readonly static integer Last = 0
readonly static player LocalPlayer
readonly static integer LocalPlayerID
private static integer Running = 0
private static real timeCounter = 0.00
private static trigger EventTrig = CreateTrigger()
private static hashtable Table
private static hashtable CharTable
private static gamecache array Cache
private static integer array PendingCount
private static timer Elapsed
private static timer BufferTimer
private static integer AlphaHash
private integer strBufferLen
private trigger eventTrig
private string mkey
private boolean localFinished
private thistype next
private thistype prev
static method bool2I takes boolean b returns integer
if (b) then
return 1
endif
return 0
endmethod
private static method hashString takes string c returns integer
return StringHash(I2S(bool2I(StringCase(c, true) == c)) + c)
endmethod
static method char2I takes string alphabet, string c returns integer // requires preloading table with data
return LoadInteger(SyncData.CharTable, .AlphaHash, .hashString(c))
endmethod
private method resetVars takes nothing returns nothing
set this.intCount = 0
set this.strCount = 0
set this.boolCount = 0
set this.realCount = 0
set this.playersDone = 0
set this.strBufferLen = 0
set this.timeStarted = 0
set this.timeFinished = 0
set this.lastError = 0
set this.onComplete = null
set this.onError = null
set this.onUpdate = null
set this.timeout = 0.00
set this.buffering = false
set this.localFinished = false
set this.trigger = null
endmethod
private static method getKey takes integer pos returns string
local string position=""
if (HaveSavedString(Table, KEY_STR_CACHE, pos)) then
return LoadStr(Table, KEY_STR_CACHE, pos)
endif
set position = ConvertBase(SAFE_KEYS, pos)
call SaveStr(Table, KEY_STR_CACHE, pos, position)
return position
endmethod
static method create takes player from returns thistype
local thistype this
// Player has to be playing because of GetLocalPlayer use.
if (GetPlayerController(from) != MAP_CONTROL_USER or GetPlayerSlotState(from) != PLAYER_SLOT_STATE_PLAYING) then
return 0
endif
set this = thistype.allocate()
set this.from = from
set this.mkey = getKey(this-1)
call this.resetVars()
set thistype(0).next.prev = this
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = 0
return this
endmethod
method refresh takes nothing returns nothing
local integer i = 0
local integer p = 0
loop
static if (LIBRARY_PlayerUtils) then
exitwhen i == User.AmountPlaying
set p = User.fromPlaying(i).id
else
exitwhen i == bj_MAX_PLAYER_SLOTS
set p = i
endif
call RemoveSavedInteger(Table, this, KEY_STR_POS + p)
call RemoveSavedInteger(Table, this, KEY_STR_LEN + p)
call RemoveSavedBoolean(Table, p, this) // playerdone
set i = i + 1
endloop
call FlushStoredMission(Cache[0], this.mkey)
call FlushStoredMission(Cache[1], this.mkey)
call this.resetVars()
endmethod
method destroy takes nothing returns nothing
if (this.eventTrig != null) then
call DestroyTrigger(this.eventTrig)
set this.eventTrig=null
endif
call this.refresh()
set this.next.prev = this.prev
set this.prev.next = this.next
call this.deallocate()
endmethod
method hasInt takes integer index returns boolean
return HaveStoredInteger(Cache[0], this.mkey, getKey(index))
endmethod
method hasReal takes integer index returns boolean
return HaveStoredReal(Cache[0], this.mkey, getKey(index))
endmethod
method hasBool takes integer index returns boolean
return HaveStoredBoolean(Cache[0], this.mkey, getKey(index))
endmethod
method hasString takes integer index returns boolean
local integer i = LoadInteger(Table, this, KEY_STR_POS+index)
if (index > 0 and i == 0) then
return false
endif
return HaveStoredInteger(Cache[1], this.mkey, getKey(i + LoadInteger(Table, this, KEY_STR_LEN+index)))
endmethod
method addInt takes integer i returns nothing
local string position=getKey(intCount)
if (LocalPlayer == this.from) then
call StoreInteger(Cache[0], this.mkey, position, i)
endif
set intCount=intCount+1
endmethod
method addReal takes real i returns nothing
local string position=getKey(realCount)
if (LocalPlayer == this.from) then
call StoreReal(Cache[0], this.mkey, position, i)
endif
set realCount=realCount+1
endmethod
method addBool takes boolean flag returns nothing
local string position=getKey(boolCount)
if (LocalPlayer == this.from) then
call StoreBoolean(Cache[0], this.mkey, position, flag)
endif
set boolCount=boolCount+1
endmethod
// SyncStoredString doesn't work
method addStringEx takes string s, integer maxLen, boolean doSync returns nothing
local string position
local integer i = 0
local integer strPos = 0
local integer strLen = 0
if (StringLength(s) < maxLen) then
set s = PopulateString(s, maxLen)
endif
// store the string position in the table
if (strCount == 0) then
call SaveInteger(Table, this, KEY_STR_POS, 0)
else
set strLen = LoadInteger(Table, this, KEY_STR_LEN + (strCount-1)) + 1
set strPos = LoadInteger(Table, this, KEY_STR_POS + (strCount-1)) + strLen
call SaveInteger(Table, this, KEY_STR_POS + strCount, strPos)
endif
// convert each character in the string to an integer
loop
exitwhen i > maxLen
set position = getKey(strPos + i)
if (LocalPlayer == this.from) then
call StoreInteger(Cache[1], this.mkey, position, .char2I(ALPHABET, SubString(s, i, i + 1)))
if (doSync and LocalPlayer == this.from) then
call SyncStoredInteger(Cache[1], this.mkey, position)
endif
endif
set i = i + 1
endloop
set strBufferLen = strBufferLen + maxLen
call SaveInteger(Table, this, KEY_STR_LEN+strCount, maxLen) // store the length as well
set strCount=strCount+1
endmethod
method addString takes string s, integer maxLen returns nothing
call addStringEx(s, maxLen, false)
endmethod
method readInt takes integer index returns integer
return GetStoredInteger(Cache[0], this.mkey, getKey(index))
endmethod
method readReal takes integer index returns real
return GetStoredReal(Cache[0], this.mkey, getKey(index))
endmethod
method readBool takes integer index returns boolean
return GetStoredBoolean(Cache[0], this.mkey, getKey(index))
endmethod
method readString takes integer index returns string
local string s = ""
local string c
local integer i = 0
local integer strLen = LoadInteger(Table, this, KEY_STR_LEN+index)
local integer strPos
if (not hasString(index)) then
return null
endif
set strLen = LoadInteger(Table, this, KEY_STR_LEN+index)
set strPos = LoadInteger(Table, this, KEY_STR_POS+index)
loop
exitwhen i > strLen
set c = I2Char(ALPHABET, GetStoredInteger(Cache[1], this.mkey, getKey(strPos + i)))
if (c == TERM_CHAR) then
return s
endif
set s = s + c
set i = i + 1
endloop
return s
endmethod
private method fireListeners takes nothing returns nothing
set Last = this
if (this.eventTrig != null) then
call TriggerEvaluate(this.eventTrig)
endif
if (this.trigger != null and TriggerEvaluate(this.trigger)) then
call TriggerExecute(this.trigger)
endif
endmethod
private method fireEvent takes filterfunc func returns nothing
set Last = this
call TriggerAddCondition(EventTrig, func)
call TriggerEvaluate(EventTrig)
call TriggerClearConditions(EventTrig)
endmethod
method addEventListener takes filterfunc func returns nothing
if (this.eventTrig == null) then
set this.eventTrig = CreateTrigger()
endif
call TriggerAddCondition(this.eventTrig, func)
endmethod
public static method gameTime takes nothing returns real
return timeCounter + TimerGetElapsed(Elapsed)
endmethod
private method error takes integer errorId returns nothing
set this.lastError = errorId
if (this.onError != null) then
call this.fireEvent(this.onError)
endif
call this.fireListeners()
static if (STOP_BUFFERING_ON_ERROR) then
set this.buffering = false
endif
endmethod
private static method readBuffer takes nothing returns nothing
local boolean b = true
local integer i = 0
local thistype data = thistype(0).next
loop
exitwhen data == 0
// find the nearest instance that is still buffering
loop
exitwhen data.buffering or data == 0
set data=data.next
endloop
// if none are found, exit
if (not data.buffering) then
return
endif
set data.timeElapsed = data.timeElapsed + UPDATE_PERIOD
if (data.onUpdate != null) then
call data.fireEvent(data.onUpdate)
endif
if (data.timeout > 0 and data.timeElapsed > data.timeout) then
call data.error(SYNC_ERROR_TIMEOUT)
endif
// if the player has left, destroy the instance
if (GetPlayerSlotState(data.from) != PLAYER_SLOT_STATE_PLAYING) then
call data.error(SYNC_ERROR_PLAYERLEFT)
static if (AUTO_DESTROY_ON_LEAVE) then
call data.destroy()
endif
endif
set b = true
// make sure all integers have been synced
if (data.intCount > 0 and not data.hasInt(data.intCount-1)) then
set b = false
endif
// make sure all reals have been synced
if (data.realCount > 0 and not data.hasReal(data.realCount-1)) then
set b = false
endif
// check strings too
if (data.strCount > 0 and not data.hasString(data.strCount-1)) then
set b = false
endif
// and booleans
if (data.boolCount > 0 and not data.hasBool(data.boolCount-1)) then
set b = false
endif
// if everything has been synced
if (b) then
if (not data.localFinished) then // async
set data.localFinished = true
// notify everyone that the local player has recieved all of the data
call Synchronizer.syncValue(LocalPlayer, data)
endif
endif
set data = data.next
endloop
endmethod
public method initInstance takes nothing returns nothing
if (this.timeStarted != 0.00) then
return
endif
set this.timeStarted = gameTime()
set this.playersDone = 0
set this.buffering = true
set this.timeElapsed = (UPDATE_PERIOD - TimerGetElapsed(BufferTimer)) * -1
if (Running==0) then
call TimerStart(BufferTimer, UPDATE_PERIOD, true, function thistype.readBuffer)
call thistype.readBuffer()
endif
set Running=Running+1
endmethod
method syncInt takes integer i returns nothing
local string position = getKey(intCount)
call this.addInt(i)
if (LocalPlayer == this.from) then
call SyncStoredInteger(Cache[0], this.mkey, position)
endif
call this.initInstance()
endmethod
method syncReal takes real r returns nothing
local string position = getKey(realCount)
call this.addReal(r)
if (LocalPlayer == this.from) then
call SyncStoredReal(Cache[0], this.mkey, position)
endif
call this.initInstance()
endmethod
method syncBoolean takes boolean b returns nothing
local string position = getKey(boolCount)
call this.addBool(b)
if (LocalPlayer == this.from) then
call SyncStoredReal(Cache[0], this.mkey, position)
endif
call this.initInstance()
endmethod
method syncString takes string s, integer maxLen returns nothing
local string position = getKey(strCount)
call this.addStringEx(s, maxLen, true)
call this.initInstance()
endmethod
method startChunk takes integer i, integer end returns boolean
local integer n = 0
local integer j = 0
local integer p = 0
local string position
if (this.timeStarted != 0.00) then
return false
endif
// Begin syncing
loop
exitwhen i > end
set position = LoadStr(Table, KEY_STR_CACHE, i)
if (i < intCount and LocalPlayer == this.from) then
call SyncStoredInteger(Cache[0], this.mkey, position)
endif
if (i < realCount and LocalPlayer == this.from) then
call SyncStoredReal(Cache[0], this.mkey, position)
endif
if (i < boolCount and LocalPlayer == this.from) then
call SyncStoredBoolean(Cache[0], this.mkey, position)
endif
if (i < strCount and LocalPlayer == this.from) then
set n = LoadInteger(Table, this, KEY_STR_LEN + i)
set p = LoadInteger(Table, this, KEY_STR_POS + i)
set j = 0
loop
exitwhen j > n
set position = LoadStr(Table, KEY_STR_CACHE, p + j)
if (LocalPlayer == this.from) then
call SyncStoredInteger(Cache[1], this.mkey, position)
endif
set j = j + 1
endloop
endif
set i = i + 1
endloop
call this.initInstance()
return true
endmethod
method start takes nothing returns boolean
local integer l = intCount
// Find the highest count
if (l < realCount) then
set l = realCount
endif
if (l < strCount) then
set l = strCount
endif
if (l < boolCount) then
set l = boolCount
endif
return startChunk(0, l)
endmethod
method isPlayerIdDone takes integer pid returns boolean
return LoadBoolean(Table, pid, this)
endmethod
method isPlayerDone takes player p returns boolean
return isPlayerIdDone(GetPlayerId(p))
endmethod
private static method updateStatus takes nothing returns boolean
local integer i = 0
local integer p = GetSyncedPlayerId()
local boolean b = true
local boolean c = true
local thistype data = GetSyncedInteger()
local triggercondition tc
if (GetSyncedInstance() != Synchronizer or not data.buffering) then
return false
endif
set data.playersDone = data.playersDone + 1
call SaveBoolean(Table, p, data, true) // set playerdone
// check if everyone has received the data
loop
static if (LIBRARY_PlayerUtils) then
exitwhen i == User.AmountPlaying
set p = User.fromPlaying(i).id
set c = User.fromPlaying(i).isPlaying
else
exitwhen i == bj_MAX_PLAYER_SLOTS
set p = i
set c = (GetPlayerController(Player(p)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(p)) == PLAYER_SLOT_STATE_PLAYING)
endif
if (c and not data.isPlayerIdDone(p)) then
set b = false // someone hasn't
endif
set i = i + 1
endloop
// if everyone has recieved the data
if (b) then
set Running = Running-1
if (Running == 0) then
call PauseTimer(BufferTimer)
endif
set data.buffering = false
set data.timeFinished = gameTime()
set data.timeElapsed = data.timeFinished - data.timeStarted
// fire events
if (data.onComplete != null) then
call data.fireEvent(data.onComplete)
endif
call data.fireListeners()
call SyncInteger_FireEvents(EVENT_SYNC_CACHE)
endif
return false
endmethod
private static method trackTime takes nothing returns nothing
set timeCounter = timeCounter + 10
endmethod
private static method preloadChar2I takes nothing returns nothing
local integer i = 0
local string c
set .AlphaHash = .hashString(ALPHABET)
loop
exitwhen i >= ALPHABET_BASE
set c = I2Char(ALPHABET, i)
call SaveInteger(SyncData.CharTable, .AlphaHash, .hashString(c), Char2I(ALPHABET, c))
set i = i + 1
endloop
endmethod
private static method onInit takes nothing returns nothing
static if (SyncInteger_DEFAULT_INSTANCE) then
set Synchronizer = SyncInteger_DefaultInstance
else
set Synchronizer = SelectionSync.create()
endif
set Table = InitHashtable()
set CharTable = InitHashtable()
set Cache[0] = InitGameCache(CACHE_FILE)
set Cache[1] = InitGameCache(CACHE_FILE_STR)
set Elapsed = CreateTimer()
set BufferTimer = CreateTimer()
static if (LIBRARY_PlayerUtils) then
set LocalPlayer = User.Local
set LocalPlayerID = User.fromLocal().id
else
set LocalPlayer = GetLocalPlayer()
set LocalPlayerID = GetPlayerId(LocalPlayer)
endif
call OnSyncInteger(Filter(function thistype.updateStatus))
call TimerStart(Elapsed, 10., true, function thistype.trackTime)
static if (PRELOAD_STR_CACHE) then
loop
exitwhen Last == ALPHABET_BASE
call getKey(Last)
set Last = Last + 1
endloop
set Last = 0
endif
call preloadChar2I()
set Initialized = true
endmethod
endstruct
endlibrary
library SyncInteger uses optional UnitDex /*or any unit indexer*/, optional GroupUtils, optional xebasic, optional PlayerUtils
/***************************************************************
*
* v1.2.1, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*
* This library allows you to send integers to all other players through
* unit selections.
*
* _________________________________________________________________________
* 1. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script to your map and save it (requires JassHelper *or* JNGP)
* _________________________________________________________________________
* 2. How it works
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Creates {DUMMY_COUNT} units and assigns {BASE} of them an integer from 0-{BASE}.
* The 2nd to last dummy is used to signal when the sequence of numbers is over and
* the last dummy signifies a negative number.
*
* 2. Breaks down the number you want to sync to one or more {BASE} integers,
* then selects each dummy unit assoicated with that integer.
*
* 4. The selection event fires for all players when the selection has been sycned
*
* 5. The ID of the selected unit is one of the {BASE} numbers. The current
* total (starts at 0) is multiplied by {BASE} and the latest synced integer is
* added to that. The process will repeat until it selects the 2nd to last dummy,
* and the total is our result.
* _________________________________________________________________________
* 3. Proper Usage
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* - Dummies must be select-able (no locust)
*
* - Run the script in debug mode while testing
*
* _________________________________________________________________________
* 4. Struct API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* struct SelectionSync
*
* static method create takes nothing returns thistype
*
* method syncValue takes player p, integer number returns boolean
* method destroy takes nothing returns nothing
* _________________________________________________________________________
* 5. Function API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* function SyncInteger takes player p, integer number returns boolean
*
* function GetSyncedInteger takes nothing returns integer
* function GetSyncedInstance takes nothing returns integer
* function GetSyncedPlayer takes nothing returns player
* function GetSyncedPlayerId takes nothing returns integer
* function IsPlayerSyncing takes player p returns boolean
* function IsPlayerIdSyncing takes integer pid returns boolean
* function IsSyncEnabled takes nothing returns boolean
* function SyncIntegerToggle takes boolean flag returns nothing
* function SyncIntegerEnable takes nothing returns nothing
* function SyncIntegerDisable takes nothing returns nothing
*
* function OnSyncInteger takes filterfunc func returns triggercondition
* function RemoveSyncEvent takes triggercondition action returns nothing
* function TriggerRegisterSyncEvent takes trigger t, integer eventtype returns nothing
*
* function SyncTerminate takes boolean destroyEvent returns nothing
*
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* -http://www.hiveworkshop.com/threads/syncinteger.278674/
*
*/
globals
// create a struct instance for global use
public constant boolean DEFAULT_INSTANCE = true
// owner of the dummy units
public constant player DUMMY_PLAYER = Player(PLAYER_NEUTRAL_PASSIVE)
// Dummy can *not* have locust and must be selectabe.
public constant integer DUMMY_ID = 'hfoo'
// allow debug messages (also requries JassHelper Debug Mode)
public constant boolean ALLOW_DEBUGGING = true
// higher == more dummies but less selections (faster)
public constant integer BASE = 10
// two higher than BASE (jasshelper doesn't allow BASE + 2)
public constant integer DUMMY_COUNT = 12
// endconfig
constant integer EVENT_SYNC_INTEGER = 1
public integer DefaultInstance = 0
private trigger OnSelectTrigger = CreateTrigger()
private trigger EventTrig = CreateTrigger()
private real FireEvent = 0
private group SelectionGroup
private integer LastPlayer
private integer LastSync
private integer LastInstance
private player LocalPlayer
private integer array ActiveSyncs
private real DUMMY_X = 0
private real DUMMY_Y = 0
private integer array DummyInstance
endglobals
function GetSyncedInteger takes nothing returns integer
return LastSync
endfunction
function GetSyncedPlayer takes nothing returns player
return Player(LastPlayer)
endfunction
function GetSyncedInstance takes nothing returns integer
return LastInstance
endfunction
function GetSyncedPlayerId takes nothing returns integer
return LastPlayer
endfunction
function IsPlayerIdSyncing takes integer pid returns boolean
return ActiveSyncs[pid] > 0
endfunction
function IsPlayerSyncing takes player p returns boolean
return ActiveSyncs[GetPlayerId(p)] > 0
endfunction
function IsSyncEnabled takes nothing returns boolean
return IsTriggerEnabled(OnSelectTrigger)
endfunction
function SyncIntegerEnable takes nothing returns nothing
call EnableTrigger(OnSelectTrigger)
endfunction
function SyncIntegerDisable takes nothing returns nothing
call DisableTrigger(OnSelectTrigger)
endfunction
function SyncIntegerToggle takes boolean flag returns nothing
if (flag) then
call EnableTrigger(OnSelectTrigger)
else
call DisableTrigger(OnSelectTrigger)
endif
endfunction
function OnSyncInteger takes filterfunc func returns triggercondition
return TriggerAddCondition(EventTrig, func)
endfunction
function RemoveSyncEvent takes triggercondition action returns nothing
call TriggerRemoveCondition(EventTrig, action)
endfunction
function TriggerRegisterSyncEvent takes trigger t, integer eventtype returns nothing
call TriggerRegisterVariableEvent(t, SCOPE_PREFIX + "FireEvent", EQUAL, eventtype)
endfunction
public function FireEvents takes real eventtype returns nothing
set FireEvent = eventtype
set FireEvent = 0
endfunction
// This function is called when a unit is selected.
private function OnSelect takes nothing returns boolean
local unit u = GetTriggerUnit()
local player p = GetTriggerPlayer()
local integer id = GetPlayerId(p)
local integer udata = GetUnitUserData(u)
local SelectionSync this = DummyInstance[udata]
local boolean isNeg = (this.Dummy[DUMMY_COUNT-1] == u)
local integer index = this.DummyID[udata] - 1
if (this <= 0) then
return false
endif
if (isNeg) then
set this.SyncingValue[id] = this.SyncingValue[id]*-1
endif
if (isNeg or this.Dummy[DUMMY_COUNT-2] == u) then
set ActiveSyncs[id] = ActiveSyncs[id] - 1
// The number is finished syncing, fire the events
set LastPlayer = id
set LastSync = this.SyncingValue[id]
set LastInstance = this
set FireEvent = EVENT_SYNC_INTEGER
call TriggerEvaluate(EventTrig)
// Reset variables
set FireEvent = 0
set this.SyncingValue[id] = -1
else
if (this.SyncingValue[id] == -1) then
set this.SyncingValue[id] = 0
endif
// Build the number we are trying to sync
set this.SyncingValue[id] = this.SyncingValue[id] * BASE + index
endif
set u = null
return false
endfunction
private keyword SyncIntegerInit
// This struct allows us to dynamically create a group of units
// which we can use to synchronize our integer through unit selections.
struct SelectionSync
public unit array Dummy[DUMMY_COUNT]
public integer array DummyID[DUMMY_COUNT]
public integer array SyncingValue[12]
public static method debugger takes boolean b, string s returns nothing
static if (ALLOW_DEBUGGING and DEBUG_MODE) then
if (b) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "|c00FF0000" + SCOPE_PREFIX + s + "|r")
endif
endif
endmethod
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
local integer i = 0
local integer uid
debug call .debugger(OnSelectTrigger == null, "[SelectionSync.create()] OnSelectTrigger is null and has no events attached to it.")
debug call .debugger(this.Dummy[0] != null, "[SelectionSync.create()] Dummy not null!")
loop
exitwhen i >= DUMMY_COUNT
set this.Dummy[i] = CreateUnit(DUMMY_PLAYER, DUMMY_ID, DUMMY_X, DUMMY_Y, i)
set uid = GetUnitUserData(this.Dummy[i])
if (uid == 0) then
set uid = ( (this-1) * DUMMY_COUNT ) + (i + 1)
call SetUnitUserData(this.Dummy[i], uid)
endif
debug call .debugger((i == 0) and (this.Dummy[i] == null), "[SelectionSync.create()] Dummy unit is null (check DUMMY_ID).")
debug call .debugger((i == 0) and (GetUnitAbilityLevel(this.Dummy[i], 'Aloc') > 0), "[SelectionSync.create()] Dummy units must be selectable (detected locust).")
set this.DummyID[uid] = i + 1
set DummyInstance[uid] = this
// Make dummy only selectable through triggers
call UnitAddAbility(this.Dummy[i], 'Amrf')
call SetUnitFlyHeight(this.Dummy[i], 5000, 0)
call UnitAddAbility(this.Dummy[i], 'Aeth')
call SetUnitScale(this.Dummy[i], 0, 0, 0)
call PauseUnit(this.Dummy[i], true)
// Hide health bar
call UnitAddAbility(this.Dummy[i], 'Aloc')
call ShowUnit(this.Dummy[i], false)
call UnitRemoveAbility(this.Dummy[i], 'Aloc')
call ShowUnit(this.Dummy[i], true)
set i = i + 1
endloop
return this
endmethod
method syncValue takes player p, integer number returns boolean
local integer x = number
local integer i = 0
local integer d = BASE
local integer j = 0
local integer n = 0
local integer l = 0
local integer playerId = GetPlayerId(p)
local unit u
local unit last
debug call .debugger(OnSelectTrigger == null, "[SelectionSync.syncValue()] OnSelectTrigger is destroyed.")
debug call .debugger(IsSyncEnabled() == false, "[SelectionSync.syncValue()] OnSelectTrigger is disabled.")
if (not IsSyncEnabled()) then
return false
endif
set ActiveSyncs[playerId] = ActiveSyncs[playerId] + 1
// Check if the number is negative
if (number < 0) then
set d = DUMMY_COUNT-1
set number = number * -1
endif
loop
set x = x/(BASE)
exitwhen x==0
set i=i+1
endloop
// Count how many units are selected
call GroupEnumUnitsSelected(SelectionGroup, p, null)
set bj_groupCountUnits = 0
set u = FirstOfGroup(SelectionGroup)
loop
exitwhen u == null
set last = u
call GroupRemoveUnit(SelectionGroup, u)
set bj_groupCountUnits = bj_groupCountUnits + 1
set u = FirstOfGroup(SelectionGroup)
endloop
// If the queue is full, de-select the last unit which
// will allow us to select a dummy, and hopefully
// avoid a flickering effect.
if (bj_groupCountUnits >= 12 and LocalPlayer == p) then
call SelectUnit(last, false)
endif
set j=R2I(Pow(BASE, i))
loop
set n = j
set x = number/n
set j = j / BASE
if (LocalPlayer == p) then
call SelectUnit(this.Dummy[x], true)
call SelectUnit(this.Dummy[x], false)
endif
set number = number-x*n
exitwhen i == 0
set i = i - 1
endloop
if (LocalPlayer == p) then
call SelectUnit(this.Dummy[d], true)
call SelectUnit(this.Dummy[d], false)
if (bj_groupCountUnits >= 12) then
call SelectUnit(last, true)
endif
endif
set u = null
set last = null
return true
endmethod
method destroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i >= DUMMY_COUNT
call RemoveUnit(this.Dummy[i])
set this.Dummy[i] = null
set i = i + 1
endloop
endmethod
implement SyncIntegerInit
endstruct
function SyncInteger takes player p, integer number returns boolean
debug call SelectionSync.debugger(DefaultInstance == 0, "[SyncInteger()] DefaultInstance is not initialized (make sure DEFAULT_INSTANCE is true")
return SelectionSync(DefaultInstance).syncValue(p, number)
endfunction
function SyncTerminate takes boolean destroyEvents returns boolean
local integer i = 0
if (OnSelectTrigger == null and EventTrig == null) then
return false
endif
if (destroyEvents) then
call DestroyTrigger(OnSelectTrigger)
call DestroyTrigger(EventTrig)
set OnSelectTrigger = null
set EventTrig = null
static if not LIBRARY_GroupUtils then
call DestroyGroup(SelectionGroup)
set SelectionGroup = null
endif
else
call SyncIntegerDisable()
endif
if (DefaultInstance > 0) then
call SelectionSync(DefaultInstance).destroy()
endif
return true
endfunction
//===========================================================================
private module SyncIntegerInit
private static method onInit takes nothing returns nothing
local integer i = 0
local integer j
loop
call TriggerRegisterPlayerUnitEvent(OnSelectTrigger, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
set i = i + 1
exitwhen i==bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(OnSelectTrigger, Filter(function OnSelect))
static if (LIBRARY_GroupUtils) then
set SelectionGroup=ENUM_GROUP
else
set SelectionGroup=CreateGroup()
endif
static if (LIBRARY_PlayerUtils) then
set LocalPlayer=User.Local
else
set LocalPlayer=GetLocalPlayer()
endif
set DUMMY_X = GetCameraBoundMaxX() + 2000
set DUMMY_Y = GetCameraBoundMaxY() + 2000
static if (DEFAULT_INSTANCE) then
set DefaultInstance = SelectionSync.create()
endif
endmethod
endmodule
endlibrary
library FileIO
/***************************************************************
*
* v1.0.4, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*
* Provides functionality to read and write files.
* _________________________________________________________________________
* 1. Requirements
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* - Patch 1.29 or higher.
* - JassHelper (vJASS)
* _________________________________________________________________________
* 2. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script to your map and save it.
* _________________________________________________________________________
* 3. API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* struct File extends array
*
* readonly static boolean ReadEnabled
* readonly static integer Counter
* readonly static integer array List
*
* static method open takes string filename returns File
* static method create takes string filename returns File
*
* ---------
*
* method write takes string contents returns File
* method read takes nothing returns string
* method append takes string contents returns string
*
* method readEx takes boolean close returns string
* method readAndClose takes nothing returns string
* method readBuffer takes nothing returns string
* method writeBuffer takes string contents returns nothing
* method appendBuffer takes string contents returns nothing
*
* method close takes nothing returns nothing
*
* public function Write takes string filename, string contents returns nothing
* public function Read takes string filename returns string
* public function Append takes string filename, string contents returns nothing
*
***************************************************************/
private keyword FileInit
struct File extends array
readonly static integer Counter = 0
readonly static integer array List
readonly static boolean ReadEnabled // async before patch 1.30
readonly string filename
private string buffer
static method open takes string filename returns thistype
local thistype this = .List[0]
if (this == 0) then
set this = Counter + 1
set Counter = this
else
set .List[0] = .List[this]
endif
set this.filename = filename
set this.buffer = null
debug if (this >= JASS_MAX_ARRAY_SIZE) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0, 120, "FileIO(" + filename + ") WARNING: Maximum instance limit " + I2S(JASS_MAX_ARRAY_SIZE) + " reached.")
debug endif
return this
endmethod
// This is used to detect invalid characters which aren't supported in preload files.
static if (DEBUG_MODE) then
private static method validateInput takes string contents returns string
local integer i = 0
local integer l = StringLength(contents)
local string ch = ""
loop
exitwhen i >= l
set ch = SubString(contents, i, i + 1)
if (ch == "\\") then
return ch
elseif (ch == "\"") then
return ch
endif
set i = i + 1
endloop
return null
endmethod
endif
method write takes string contents returns thistype
debug if (.validateInput(contents) != null) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0, 120, "FileIO(" + filename + ") ERROR: Invalid character |cffffcc00" + .validateInput(contents) + "|r")
debug return this
debug endif
set this.buffer = null
call PreloadGenClear()
call PreloadGenStart()
call Preload("\" ) \n\n\tcall BlzSetAbilityTooltip('Amls', \"" + contents + "\", 1)\nendfunction\nfunction a takes nothing returns nothing\n //")
call PreloadGenEnd(this.filename)
return this
endmethod
private method readPreload takes nothing returns string
local string original = BlzGetAbilityTooltip('Amls', 1)
local string output
// Execute the preload file
call Preloader(this.filename)
// Read the output
set output = BlzGetAbilityTooltip('Amls', 1)
call BlzSetAbilityTooltip('Amls', original, 1)
// Make sure the output is valid
if (output == original) then
return null
endif
return output
endmethod
method close takes nothing returns nothing
if (this.buffer != null) then
call .write(.readPreload() + this.buffer)
set this.buffer = null
endif
set .List[this] = .List[0]
set .List[0] = this
endmethod
method readEx takes boolean close returns string
local string output = .readPreload()
local string buf = this.buffer
if (close) then
call this.close()
endif
if (output == null) then
return buf
endif
if (buf != null) then
set output = output + buf
endif
return output
endmethod
method read takes nothing returns string
return .readEx(false)
endmethod
method readAndClose takes nothing returns string
return .readEx(true)
endmethod
method appendBuffer takes string contents returns thistype
set .buffer = .buffer + contents
return this
endmethod
method readBuffer takes nothing returns string
return .buffer
endmethod
method writeBuffer takes string contents returns nothing
set .buffer = contents
endmethod
method append takes string contents returns thistype
return this.write(this.read() + contents)
endmethod
static method create takes string filename returns thistype
return .open(filename).write("")
endmethod
implement FileInit
endstruct
private module FileInit
private static method onInit takes nothing returns nothing
set File.ReadEnabled = File.open("FileTester.pld").write(SCOPE_PREFIX).readEx(true) == SCOPE_PREFIX
endmethod
endmodule
public function Write takes string filename, string contents returns nothing
call File.open(filename).write(contents).close()
endfunction
public function Read takes string filename returns string
return File.open(filename).readEx(true)
endfunction
public function Append takes string filename, string contents returns nothing
call File.open(filename).write(contents).close()
endfunction
endlibrary
library PlayerUtils
/**************************************************************
*
* v1.2.9 by TriggerHappy
*
* This library provides a struct which caches data about players
* as well as provides functionality for manipulating player colors.
*
* Constants
* ------------------
*
* force FORCE_PLAYING - Player group of everyone who is playing.
*
* Struct API
* -------------------
* struct User
*
* static method fromIndex takes integer i returns User
* static method fromLocal takes nothing returns User
* static method fromPlaying takes integer id returns User
*
* static method operator [] takes integer id returns User
* static method operator count takes nothing returns integer
*
* method operator name takes nothing returns string
* method operator name= takes string name returns nothing
* method operator color takes nothing returns playercolor
* method operator color= takes playercolor c returns nothing
* method operator defaultColor takes nothing returns playercolor
* method operator hex takes nothing returns string
* method operator nameColored takes nothing returns string
*
* method toPlayer takes nothing returns player
* method colorUnits takes playercolor c returns nothing
*
* readonly string originalName
* readonly boolean isPlaying
* readonly static player Local
* readonly static integer LocalId
* readonly static integer AmountPlaying
* readonly static playercolor array Color
* readonly static player array PlayingPlayer
*
**************************************************************/
globals
// automatically change unit colors when changing player color
private constant boolean AUTO_COLOR_UNITS = true
// use an array for name / color lookups (instead of function calls)
private constant boolean ARRAY_LOOKUP = false
// this only applies if ARRAY_LOOKUP is true
private constant boolean HOOK_SAFETY = false // disable for speed, but only use the struct to change name/color safely
constant force FORCE_PLAYING = CreateForce()
private string array Name
private string array Hex
private string array OriginalHex
private playercolor array CurrentColor
endglobals
private keyword PlayerUtilsInit
struct User extends array
static constant integer NULL = bj_MAX_PLAYER_SLOTS
readonly player handle
readonly integer id
readonly thistype next
readonly thistype prev
readonly string originalName
readonly boolean isPlaying
readonly static thistype first
readonly static thistype last
readonly static player Local
readonly static integer LocalId
readonly static integer AmountPlaying = 0
readonly static playercolor array Color
static if not (LIBRARY_GroupUtils) then
readonly static group ENUM_GROUP = CreateGroup()
endif
private static thistype array PlayingPlayer
private static integer array PlayingPlayerIndex
// similar to Player(#)
static method fromIndex takes integer i returns thistype
return thistype(i)
endmethod
// similar to GetLocalPlayer
static method fromLocal takes nothing returns thistype
return thistype(thistype.LocalId)
endmethod
// access active players array
static method fromPlaying takes integer index returns thistype
return PlayingPlayer[index]
endmethod
static method operator [] takes player p returns thistype
return thistype(GetPlayerId(p))
endmethod
method toPlayer takes nothing returns player
return this.handle
endmethod
method operator name takes nothing returns string
static if (ARRAY_LOOKUP) then
return Name[this]
else
return GetPlayerName(this.handle)
endif
endmethod
method operator name= takes string newName returns nothing
call SetPlayerName(this.handle, newName)
static if (ARRAY_LOOKUP) then
static if not (HOOK_SAFETY) then
set Name[this] = newName
endif
endif
endmethod
method operator color takes nothing returns playercolor
static if (ARRAY_LOOKUP) then
return CurrentColor[this]
else
return GetPlayerColor(this.handle)
endif
endmethod
method operator hex takes nothing returns string
return OriginalHex[GetHandleId(this.color)]
endmethod
method operator color= takes playercolor c returns nothing
call SetPlayerColor(this.handle, c)
static if (ARRAY_LOOKUP) then
set CurrentColor[this] = c
static if not (HOOK_SAFETY) then
static if (AUTO_COLOR_UNITS) then
call this.colorUnits(color)
endif
endif
endif
endmethod
method operator defaultColor takes nothing returns playercolor
return Color[this]
endmethod
method operator nameColored takes nothing returns string
return hex + this.name + "|r"
endmethod
method colorUnits takes playercolor c returns nothing
local unit u
call GroupEnumUnitsOfPlayer(ENUM_GROUP, this.handle, null)
loop
set u = FirstOfGroup(ENUM_GROUP)
exitwhen u == null
call SetUnitColor(u, c)
call GroupRemoveUnit(ENUM_GROUP, u)
endloop
endmethod
static method onLeave takes nothing returns boolean
local thistype p = thistype[GetTriggerPlayer()]
local integer i = .PlayingPlayerIndex[p.id]
// clean up
call ForceRemovePlayer(FORCE_PLAYING, p.toPlayer())
// recycle index
set .AmountPlaying = .AmountPlaying - 1
set .PlayingPlayerIndex[i] = .PlayingPlayerIndex[.AmountPlaying]
set .PlayingPlayer[i] = .PlayingPlayer[.AmountPlaying]
if (.AmountPlaying == 1) then
set p.prev.next = User.NULL
set p.next.prev = User.NULL
else
set p.prev.next = p.next
set p.next.prev = p.prev
endif
set .last = .PlayingPlayer[.AmountPlaying]
set p.isPlaying = false
return false
endmethod
implement PlayerUtilsInit
endstruct
private module PlayerUtilsInit
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local thistype p
set thistype.Local = GetLocalPlayer()
set thistype.LocalId = GetPlayerId(thistype.Local)
set OriginalHex[0] = "|cffff0303"
set OriginalHex[1] = "|cff0042ff"
set OriginalHex[2] = "|cff1ce6b9"
set OriginalHex[3] = "|cff540081"
set OriginalHex[4] = "|cfffffc01"
set OriginalHex[5] = "|cfffe8a0e"
set OriginalHex[6] = "|cff20c000"
set OriginalHex[7] = "|cffe55bb0"
set OriginalHex[8] = "|cff959697"
set OriginalHex[9] = "|cff7ebff1"
set OriginalHex[10] = "|cff106246"
set OriginalHex[11] = "|cff4e2a04"
if (bj_MAX_PLAYERS > 12) then
set OriginalHex[12] = "|cff9B0000"
set OriginalHex[13] = "|cff0000C3"
set OriginalHex[14] = "|cff00EAFF"
set OriginalHex[15] = "|cffBE00FE"
set OriginalHex[16] = "|cffEBCD87"
set OriginalHex[17] = "|cffF8A48B"
set OriginalHex[18] = "|cffBFFF80"
set OriginalHex[19] = "|cffDCB9EB"
set OriginalHex[20] = "|cff282828"
set OriginalHex[21] = "|cffEBF0FF"
set OriginalHex[22] = "|cff00781E"
set OriginalHex[23] = "|cffA46F33"
endif
set thistype.first = User.NULL
loop
exitwhen i == bj_MAX_PLAYERS
set p = User(i)
set p.handle = Player(i)
set p.id = i
set thistype.Color[i] = GetPlayerColor(p.handle)
set CurrentColor[i] = thistype.Color[i]
if (GetPlayerController(p.handle) == MAP_CONTROL_USER and GetPlayerSlotState(p.handle) == PLAYER_SLOT_STATE_PLAYING) then
set .PlayingPlayer[AmountPlaying] = p
set .PlayingPlayerIndex[i] = .AmountPlaying
set .last = i
if (.first == User.NULL) then
set .first = i
set User(i).next = User.NULL
set User(i).prev = User.NULL
else
set User(i).prev = PlayingPlayer[AmountPlaying-1].id
set PlayingPlayer[AmountPlaying-1].next = User(i)
set User(i).next = User.NULL
endif
set p.isPlaying = true
call TriggerRegisterPlayerEvent(t, p.handle, EVENT_PLAYER_LEAVE)
call ForceAddPlayer(FORCE_PLAYING, p.handle)
set Hex[p] = OriginalHex[GetHandleId(thistype.Color[i])]
set .AmountPlaying = .AmountPlaying + 1
endif
set Name[p] = GetPlayerName(p.handle)
set p.originalName=Name[p]
set i = i + 1
endloop
call TriggerAddCondition(t, Filter(function thistype.onLeave))
endmethod
endmodule
//===========================================================================
static if (ARRAY_LOOKUP) then
static if (HOOK_SAFETY) then
private function SetPlayerNameHook takes player whichPlayer, string name returns nothing
set Name[GetPlayerId(whichPlayer)] = name
endfunction
private function SetPlayerColorHook takes player whichPlayer, playercolor color returns nothing
local User p = User[whichPlayer]
set Hex[p] = OriginalHex[GetHandleId(color)]
set CurrentColor[p] = color
static if (AUTO_COLOR_UNITS) then
call p.colorUnits(color)
endif
endfunction
hook SetPlayerName SetPlayerNameHook
hook SetPlayerColor SetPlayerColorHook
endif
endif
endlibrary
library Savecode requires BigNum
private constant function uppercolor takes nothing returns string
return "|cffff0000"
endfunction
private constant function lowercolor takes nothing returns string
return "|cff00ff00"
endfunction
private constant function numcolor takes nothing returns string
return "|cff0000ff"
endfunction
private function player_charset takes nothing returns string
return "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
endfunction
private function player_charsetlen takes nothing returns integer
return StringLength(player_charset())
endfunction
private function charset takes nothing returns string
return "!#$%&'()*+,-.0123456789:;=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}`"
endfunction
private function charsetlen takes nothing returns integer
return StringLength(charset())
endfunction
private function BASE takes nothing returns integer
return charsetlen()
endfunction
private constant function HASHN takes nothing returns integer
return 5000 //1./HASHN() is the probability of a random code being valid
endfunction
private constant function MAXINT takes nothing returns integer
return 2147483647
endfunction
private function player_chartoi takes string c returns integer
local integer i = 0
local string cs = player_charset()
local integer len = player_charsetlen()
loop
exitwhen i>=len or c == SubString(cs,i,i+1)
set i = i + 1
endloop
return i
endfunction
private function chartoi takes string c returns integer
local integer i = 0
local string cs = charset()
local integer len = charsetlen()
loop
exitwhen i>=len or c == SubString(cs,i,i+1)
set i = i + 1
endloop
return i
endfunction
private function itochar takes integer i returns string
return SubString(charset(),i,i+1)
endfunction
//You probably want to use a different char set for this
//Also, use a hash that doesn't suck so much
private function scommhash takes string s returns integer
local integer array count
local integer i = 0
local integer len = StringLength(s)
local integer x
set s = StringCase(s,true)
loop
exitwhen i >= len
set x = player_chartoi(SubString(s,i,i+1))
set count[x] = count[x] + 1
set i = i + 1
endloop
set i = 0
set len = player_charsetlen()
set x = 0
loop
exitwhen i>= len
set x = count[i]*count[i]*i+count[i]*x+x+199
// call BJDebugMsg(I2S(x)+" "+I2S(count[i]))
// call TriggerSleepAction(0.)
set i = i + 1
endloop
if x < 0 then
set x = -x
endif
return x
endfunction
private function modb takes integer x returns integer
if x >= BASE() then
return x - BASE()
elseif x < 0 then
return x + BASE()
else
return x
endif
endfunction
struct Savecode
real digits //logarithmic approximation
BigNum bignum
static method create takes nothing returns Savecode
local Savecode sc = Savecode.allocate()
set sc.digits = 0.
set sc.bignum = BigNum.create(BASE())
return sc
endmethod
method onDestroy takes nothing returns nothing
call .bignum.destroy()
endmethod
method Encode takes integer val, integer max returns nothing
set .digits = .digits + log(max+1,BASE())
call .bignum.MulSmall(max+1)
call .bignum.AddSmall(val)
endmethod
method Decode takes integer max returns integer
return .bignum.DivSmall(max+1)
endmethod
method IsEmpty takes nothing returns boolean
return .bignum.IsZero()
endmethod
method Length takes nothing returns real
return .digits
endmethod
method Clean takes nothing returns nothing
call .bignum.Clean()
endmethod
//These functions get too intimate with BigNum_l
method Pad takes nothing returns nothing
local BigNum_l cur = .bignum.list
local BigNum_l prev
local integer maxlen = R2I(1.0 + .Length())
loop
exitwhen cur == 0
set prev = cur
set cur = cur.next
set maxlen = maxlen - 1
endloop
loop
exitwhen maxlen <= 0
set prev.next = BigNum_l.create()
set prev = prev.next
set maxlen = maxlen - 1
endloop
endmethod
method ToString takes nothing returns string
local BigNum_l cur = .bignum.list
local string s = ""
loop
exitwhen cur == 0
set s = itochar(cur.leaf) + s
set cur = cur.next
endloop
return s
endmethod
method FromString takes string s returns nothing
local integer i = StringLength(s)-1
local BigNum_l cur = BigNum_l.create()
set .bignum.list = cur
loop
set cur.leaf = chartoi(SubString(s,i,i+1))
exitwhen i <= 0
set cur.next = BigNum_l.create()
set cur = cur.next
set i = i - 1
endloop
endmethod
method Hash takes nothing returns integer
local integer hash = 0
local integer x
local BigNum_l cur = .bignum.list
loop
exitwhen cur == 0
set x = cur.leaf
set hash = ModuloInteger(hash+79*hash/(x+1) + 293*x/(1+hash - (hash/BASE())*BASE()) + 479,HASHN())
set cur = cur.next
endloop
return hash
endmethod
//this is not cryptographic which is fine for this application
//sign = 1 is forward
//sign = -1 is backward
method Obfuscate takes integer key, integer sign returns nothing
local integer seed = GetRandomInt(0,MAXINT())
local integer advance
local integer x
local BigNum_l cur = .bignum.list
if sign == -1 then
call SetRandomSeed(.bignum.LastDigit())
set cur.leaf = modb(cur.leaf + sign*GetRandomInt(0,BASE()-1))
set x = cur.leaf
endif
call SetRandomSeed(key)
loop
exitwhen cur == 0
if sign == -1 then
set advance = cur.leaf
endif
set cur.leaf = modb(cur.leaf + sign*GetRandomInt(0,BASE()-1))
if sign == 1 then
set advance = cur.leaf
endif
set advance = advance + GetRandomInt(0,BASE()-1)
call SetRandomSeed(advance)
set x = cur.leaf
set cur = cur.next
endloop
if sign == 1 then
call SetRandomSeed(x)
set .bignum.list.leaf = modb(.bignum.list.leaf + sign*GetRandomInt(0,BASE()-1))
endif
call SetRandomSeed(seed)
endmethod
method Dump takes nothing returns nothing
local BigNum_l cur = .bignum.list
local string s = ""
set s = "max: "+R2S(.digits)
loop
exitwhen cur == 0
set s = I2S(cur.leaf)+" "+s
set cur = cur.next
endloop
call BJDebugMsg(s)
endmethod
method Save takes player p, integer loadtype returns string
local integer key = scommhash(GetPlayerName(p))+loadtype*73
local string s
local integer hash
call .Clean()
set hash = .Hash()
call .Encode(hash,HASHN())
call .Clean()
/////////////////////// Save code information. Comment out next two lines in implementation
//call BJDebugMsg("Expected length: " +I2S(R2I(1.0+.Length())))
//call BJDebugMsg("Room left in last char: "+R2S(1.-ModuloReal((.Length()),1)))
///////////////////////
call .Pad()
call .Obfuscate(key,1)
return .ToString()
endmethod
method Load takes player p, string s, integer loadtype returns boolean
local integer ikey = scommhash(GetPlayerName(p))+loadtype*73
local integer inputhash
call .FromString(s)
call .Obfuscate(ikey,-1)
set inputhash = .Decode(HASHN())
call .Clean()
return inputhash == .Hash()
endmethod
endstruct
private function isupper takes string c returns boolean
return c == StringCase(c,true)
endfunction
private function ischar takes string c returns boolean
return S2I(c) == 0 and c!= "0"
endfunction
private function chartype takes string c returns integer
if(ischar(c)) then
if isupper(c) then
return 0
else
return 1
endif
else
return 2
endif
endfunction
private function testchar takes string c returns nothing
if(ischar(c)) then
if isupper(c) then
call BJDebugMsg(c+" isupper")
else
call BJDebugMsg(c+" islower")
endif
else
call BJDebugMsg(c+ " isnumber")
endif
endfunction
public function colorize takes string s returns string
local string out = ""
local integer i = 0
local integer len = StringLength(s)
local integer ctype
local string c
loop
exitwhen i >= len
set c = SubString(s,i,i+1)
set ctype = chartype(c)
if ctype == 0 then
set out = out + uppercolor()+c+"|r"
elseif ctype == 1 then
set out = out + lowercolor()+c+"|r"
else
set out = out + numcolor()+c+"|r"
endif
set i = i + 1
endloop
return out
endfunction
private function prop_Savecode takes nothing returns boolean
local string s
local Savecode loadcode
//--- Data you want to save ---
local integer medal1 = 10
local integer medal2 = 3
local integer medalmax = 13
local integer XP = 1337
local integer XPmax = 1000000
local Savecode savecode = Savecode.create()
call SetPlayerName(Player(0),"yomp")
call SetPlayerName(Player(1),"fruitcup")
call savecode.Encode(medal1,medalmax)
call savecode.Encode(medal2,medalmax)
call savecode.Encode(XP,XPmax)
//--- Savecode_save generates the savecode for a specific player ---
set s = savecode.Save(Player(0),1)
call savecode.destroy()
// call BJDebugMsg("Savecode: " + Savecode_colorize(s))
//--- User writes down code, inputs again ---
set loadcode = Savecode.create()
if loadcode.Load(Player(0),s,1) then
// call BJDebugMsg("load ok")
else
call BJDebugMsg("load failed")
return false
endif
//Must decode in reverse order of encodes
// load object : max value that data can take
if XP != loadcode.Decode(XPmax) then
return false
elseif medal2 != loadcode.Decode(medalmax) then
return false
elseif medal1 != loadcode.Decode(medalmax) then
return false
endif
call loadcode.destroy()
return true
endfunction
endlibrary
//===========================================================================
function InitTrig_save_system takes nothing returns nothing
endfunction
library BigNum
//prefer algebraic approach because of real subtraction issues
function log takes real y, real base returns real
local real x
local real factor = 1.0
local real logy = 0.0
local real sign = 1.0
if(y < 0.) then
return 0.0
endif
if(y < 1.) then
set y = 1.0/y
set sign = -1.0
endif
//Chop out powers of the base
loop
exitwhen y < 1.0001 //decrease this ( bounded below by 1) to improve precision
if(y > base) then
set y = y / base
set logy = logy + factor
else
set base = SquareRoot(base) //If you use just one base a lot, precompute its squareroots
set factor = factor / 2.
endif
endloop
return sign*logy
endfunction
struct BigNum_l
integer leaf
BigNum_l next
debug static integer nalloc = 0
static method create takes nothing returns BigNum_l
local BigNum_l bl = BigNum_l.allocate()
set bl.next = 0
set bl.leaf = 0
debug set BigNum_l.nalloc = BigNum_l.nalloc + 1
return bl
endmethod
method onDestroy takes nothing returns nothing
debug set BigNum_l.nalloc = BigNum_l.nalloc - 1
endmethod
//true: want destroy
method Clean takes nothing returns boolean
if .next == 0 and .leaf == 0 then
return true
elseif .next != 0 and .next.Clean() then
call .next.destroy()
set .next = 0
return .leaf == 0
else
return false
endif
endmethod
method DivSmall takes integer base, integer denom returns integer
local integer quotient
local integer remainder = 0
local integer num
if .next != 0 then
set remainder = .next.DivSmall(base,denom)
endif
set num = .leaf + remainder*base
set quotient = num/denom
set remainder = num - quotient*denom
set .leaf = quotient
return remainder
endmethod
endstruct
struct BigNum
BigNum_l list
integer base
static method create takes integer base returns BigNum
local BigNum b = BigNum.allocate()
set b.list = 0
set b.base = base
return b
endmethod
method onDestroy takes nothing returns nothing
local BigNum_l cur = .list
local BigNum_l next
loop
exitwhen cur == 0
set next = cur.next
call cur.destroy()
set cur = next
endloop
endmethod
method IsZero takes nothing returns boolean
local BigNum_l cur = .list
loop
exitwhen cur == 0
if cur.leaf != 0 then
return false
endif
set cur = cur.next
endloop
return true
endmethod
method Dump takes nothing returns nothing
local BigNum_l cur = .list
local string s = ""
loop
exitwhen cur == 0
set s = I2S(cur.leaf)+" "+s
set cur = cur.next
endloop
call BJDebugMsg(s)
endmethod
method Clean takes nothing returns nothing
local BigNum_l cur = .list
call cur.Clean()
endmethod
//fails if bignum is null
//BASE() + carry must be less than MAXINT()
method AddSmall takes integer carry returns nothing
local BigNum_l next
local BigNum_l cur = .list
local integer sum
if cur == 0 then
set cur = BigNum_l.create()
set .list = cur
endif
loop
exitwhen carry == 0
set sum = cur.leaf + carry
set carry = sum / .base
set sum = sum - carry*.base
set cur.leaf = sum
if cur.next == 0 then
set cur.next = BigNum_l.create()
endif
set cur = cur.next
endloop
endmethod
//x*BASE() must be less than MAXINT()
method MulSmall takes integer x returns nothing
local BigNum_l cur = .list
local integer product
local integer remainder
local integer carry = 0
loop
exitwhen cur == 0 and carry == 0
set product = x * cur.leaf + carry
set carry = product/.base
set remainder = product - carry*.base
set cur.leaf = remainder
if cur.next == 0 and carry != 0 then
set cur.next = BigNum_l.create()
endif
set cur = cur.next
endloop
endmethod
//Returns remainder
method DivSmall takes integer denom returns integer
return .list.DivSmall(.base,denom)
endmethod
method LastDigit takes nothing returns integer
local BigNum_l cur = .list
local BigNum_l next
loop
set next = cur.next
exitwhen next == 0
set cur = next
endloop
return cur.leaf
endmethod
endstruct
private function prop_Allocator1 takes nothing returns boolean
local BigNum b1
local BigNum b2
set b1 = BigNum.create(37)
call b1.destroy()
set b2 = BigNum.create(37)
call b2.destroy()
return b1 == b2
endfunction
private function prop_Allocator2 takes nothing returns boolean
local BigNum b1
local boolean b = false
set b1 = BigNum.create(37)
call b1.AddSmall(17)
call b1.MulSmall(19)
debug if BigNum_l.nalloc < 1 then
debug return false
debug endif
call b1.destroy()
debug set b = BigNum_l.nalloc == 0
return b
endfunction
private function prop_Arith takes nothing returns boolean
local BigNum b1
set b1 = BigNum.create(37)
call b1.AddSmall(73)
call b1.MulSmall(39)
call b1.AddSmall(17)
//n = 2864
if b1.DivSmall(100) != 64 then
return false
elseif b1.DivSmall(7) != 0 then
return false
elseif b1.IsZero() then
return false
elseif b1.DivSmall(3) != 1 then
return false
elseif b1.DivSmall(3) != 1 then
return false
elseif not b1.IsZero() then
return false
endif
return true
endfunction
endlibrary
//===========================================================================
function InitTrig_bignum_lib takes nothing returns nothing
endfunction
library FrameLoader initializer init_function
// in 1.31 and upto 1.32.9 PTR (when I wrote this). Frames are not correctly saved and loaded, breaking the game.
// This library runs all functions added to it with a 0s delay after the game was loaded.
// function FrameLoaderAdd takes code func returns nothing
// func runs when the game is loaded.
globals
private trigger eventTrigger = CreateTrigger()
private trigger actionTrigger = CreateTrigger()
private timer t = CreateTimer()
endglobals
function FrameLoaderAdd takes code func returns nothing
call TriggerAddAction(actionTrigger, func)
endfunction
private function timerAction takes nothing returns nothing
call TriggerExecute(actionTrigger)
endfunction
private function eventAction takes nothing returns nothing
call TimerStart(t, 0, false, function timerAction)
endfunction
private function init_function takes nothing returns nothing
call TriggerRegisterGameEvent(eventTrigger, EVENT_GAME_LOADED)
call TriggerAddAction(eventTrigger, function eventAction)
endfunction
endlibrary
//MyResourceField 1.4b
//By Tasyen
function MyResourceFieldPlayerSize takes nothing returns integer
return 100 //the array is splited into sections of size 100. Each section is used by one player. Player Red uses 101 to 200. Blue Takes 201 to 300, allows to have 100 MyResourceFields.
endfunction
//Allow and Pos the checkbox hidding the additional Bars.
function MyResourceFieldCreateCheckBox takes nothing returns boolean
return false //(true) create a checkbox to tooggle visiblity of the additional ResourceBarFrames
endfunction
function MyResourceFieldCheckBoxX takes nothing returns real
return 0.1 //abs point of checkbox
endfunction
function MyResourceFieldCheckBoxY takes nothing returns real
return 0.57
endfunction
function MyResourceFieldCheckBoxLabelText takes nothing returns string
return "Hide Resources"
endfunction
//Where is the tooltip of this Bars placed.
function MyResourceFieldTooltipX takes nothing returns real
return 0.8
endfunction
function MyResourceFieldTooltipY takes nothing returns real
return 0.16
endfunction
function MyResourceFieldTooltipPoint takes nothing returns framepointtype
return FRAMEPOINT_BOTTOMRIGHT //Which point of Tooltip is positionate to abs point MyResourceFieldTooltipX/MyResourceFieldTooltipY
endfunction
//Default Sizes of TooltipBoxes
//You could change a TooltipBox size after they were created with: x should be a number from 1 to udg_MyResourceFieldCount. udg_MyResourceFieldCount would be the last created.
//call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBoxedText", x), xsize, 0)
function MyResourceFieldTooltipSizeX takes nothing returns real
return 0.285
endfunction
function MyResourceFieldAutoCreateCols takes nothing returns integer
return 4
endfunction
function MyResourceFieldAutoCreateColAddEachRow takes nothing returns integer
return 0 //rows after the first one gain this amount of cols. -values are valid
endfunction
function MyResourceFieldAutoCreateRows takes nothing returns integer
return 1 //0 or below will not create any Fields.
endfunction
function MyResourceFieldAnchor takes nothing returns framepointtype
//Poses the first Bar where in the world Frame?
//I suggest to use a y-offset when using any Bottom Point.
//return FRAMEPOINT_TOPLEFT
//return FRAMEPOINT_TOP
//return FRAMEPOINT_TOPRIGHT
//return FRAMEPOINT_BOTTOMLEFT
return FRAMEPOINT_BOTTOM
//return FRAMEPOINT_BOTTOMRIGHT
//return FRAMEPOINT_LEFT
//return FRAMEPOINT_RIGHT
//return FRAMEPOINT_CENTER
endfunction
function MyResourceFieldAnchor1OffsetX takes nothing returns real
return 0.1 //Offset the first bar by that amount from its FramePoint
endfunction
function MyResourceFieldAnchor1OffsetY takes nothing returns real
return 0.555
endfunction
function MyResourceFieldSizeX takes nothing returns real
return 0.084
endfunction
function MyResourceFieldSizeY takes nothing returns real
return 0.0218
endfunction
function MyResourceFieldCustomHiding takes nothing returns nothing
local integer index = udg_MyResourceFieldCount
local integer playerIndex
local integer playerId
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then //not Replay Mode?
set playerId = GetConvertedPlayerId(GetLocalPlayer())
else
set playerId = R2I(BlzFrameGetValue(BlzGetFrameByName("ReplayVisionMenu",0))) + 1 //Replay Mode use the player observed
endif
set playerIndex = playerId * MyResourceFieldPlayerSize()
//Wana hide all, yes -> hide the parent?
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossSBest",0), not udg_MyResourceFieldHideData[playerId])
//Hide Specific Fields for that player.
loop
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceField", index), not udg_MyResourceFieldHideData[playerIndex + index])
set index = index -1
exitwhen index == 0
endloop
endfunction
function MyResourceFieldUpdateBars takes nothing returns nothing
local integer playerIndex
local integer index = 1
local integer visibleTooltipIndex = 0
//share visiblity for tooltips to Resources
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossF",0), BlzFrameIsVisible(BlzGetFrameByName("MyResourceFieldBossS",0)))
if MyResourceFieldCreateCheckBox() then //Has checkbox enabled?
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldCheckBox",0), not bj_cineModeAlreadyIn) //hide in cinematic
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldCheckBoxLabel",0), not bj_cineModeAlreadyIn)
endif
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then //not replay mode?
set playerIndex = GetConvertedPlayerId(GetLocalPlayer()) * MyResourceFieldPlayerSize()
else
set playerIndex = (R2I(BlzFrameGetValue(BlzGetFrameByName("ReplayVisionMenu",0))) + 1) * MyResourceFieldPlayerSize()
endif
//Takes over all udg_MyResourceFieldValue data into the MyResourceFields also updates the title
//The outher Loop are the Bars, the inner Loop handles the tooltipTitle update
loop
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldText", index), udg_MyResourceFieldValue[playerIndex + index])
if udg_MyResourceFieldIcons[playerIndex + index] == null or udg_MyResourceFieldIcons[playerIndex + index] == "" then
call BlzFrameSetTexture(BlzGetFrameByName("MyResourceFieldIcon", index), udg_MyResourceFieldIcons[index], 0 ,true)
else
call BlzFrameSetTexture(BlzGetFrameByName("MyResourceFieldIcon", index), udg_MyResourceFieldIcons[playerIndex + index], 0 ,true)
endif
// if this Frames shows its tooltip then update the tooltip
if BlzFrameIsVisible(BlzGetFrameByName("MyResourceFieldTooltip", index)) then
set visibleTooltipIndex = index
endif
set index = index + 1
exitwhen index > udg_MyResourceFieldCount
endloop
// when an tooltip is visible update the tooltip and show it
if visibleTooltipIndex != 0 then
set index = visibleTooltipIndex
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBoxedText", 0), true)
if udg_MyResourceFieldTooltipText[playerIndex + index] == null then
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", 0), udg_MyResourceFieldTooltipText[index])
else
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextValue", 0), udg_MyResourceFieldTooltipText[playerIndex + index])
endif
if udg_MyResourceFieldTooltipTitle[playerIndex + index] == null then
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", 0), udg_MyResourceFieldTooltipTitle[index]+": "+udg_MyResourceFieldValue[playerIndex +index])
else
call BlzFrameSetText(BlzGetFrameByName("MyResourceFieldBoxedTextTitle", 0), udg_MyResourceFieldTooltipTitle[playerIndex + index]+": "+udg_MyResourceFieldValue[playerIndex + index])
endif
else
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBoxedText", 0), false)
endif
endfunction
function CreateMyResourceFieldFree takes nothing returns nothing
local framehandle field = BlzCreateSimpleFrame("MyResourceField", BlzGetFrameByName("MyResourceFieldBossS",0), udg_MyResourceFieldCount + 1)
local framehandle tooltip = BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldTooltip", field, "", udg_MyResourceFieldCount + 1)
set udg_MyResourceFieldCount = udg_MyResourceFieldCount + 1
call BlzFrameSetAbsPoint(field, FRAMEPOINT_BOTTOMLEFT, udg_MyResourceFieldFreeX, udg_MyResourceFieldFreeY)
call BlzFrameSetSize(field, MyResourceFieldSizeX(), MyResourceFieldSizeY())
call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBackground", udg_MyResourceFieldCount), MyResourceFieldSizeX(), MyResourceFieldSizeY() + 0.0102)
call BlzFrameSetTooltip(field, tooltip)
call BlzFrameSetVisible(tooltip, false) // BlzFrameSetTooltip, does not hide the SimpleFrame-tooltip hence enforce it. Does not happen for Frames.
set tooltip = null
set field = null
endfunction
function CreateMyResourceField takes boolean newLine returns nothing
local framehandle field = BlzCreateSimpleFrame("MyResourceField", BlzGetFrameByName("MyResourceFieldBossS",0), udg_MyResourceFieldCount + 1)
local framehandle tooltip = BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldTooltip", field, "", udg_MyResourceFieldCount + 1)
set udg_MyResourceFieldCount = udg_MyResourceFieldCount + 1
call BlzFrameSetTooltip(field, tooltip)
call BlzFrameSetVisible(tooltip, false) // BlzFrameSetTooltip, does not hide the SimpleFrame-tooltip hence enforce it. Does not happen for Frames.
set tooltip = null
if udg_MyResourceFieldCount == 1 then //if this is the first create one Pos it below the default one
call BlzFrameSetPoint(field, MyResourceFieldAnchor(), BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME,0), MyResourceFieldAnchor(), MyResourceFieldAnchor1OffsetX(), MyResourceFieldAnchor1OffsetY())
set udg_MyResourceFieldLastLineStart = 1
else
if not newLine then
if MyResourceFieldAnchor() == FRAMEPOINT_BOTTOMLEFT or MyResourceFieldAnchor() == FRAMEPOINT_TOPLEFT or MyResourceFieldAnchor() == FRAMEPOINT_LEFT or MyResourceFieldAnchor() == FRAMEPOINT_TOP or MyResourceFieldAnchor() == FRAMEPOINT_BOTTOM then
call BlzFrameSetPoint(field, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPRIGHT, 0, 0)
elseif MyResourceFieldAnchor() == FRAMEPOINT_BOTTOMRIGHT or MyResourceFieldAnchor() == FRAMEPOINT_RIGHT or MyResourceFieldAnchor() == FRAMEPOINT_TOPRIGHT then
call BlzFrameSetPoint(field, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPLEFT, 0, 0)
else
call BlzFrameSetPoint(field, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldCount - 1), FRAMEPOINT_TOPLEFT, 0, 0)
endif
else
if MyResourceFieldAnchor() == FRAMEPOINT_TOPRIGHT or MyResourceFieldAnchor() == FRAMEPOINT_TOPLEFT or MyResourceFieldAnchor() == FRAMEPOINT_LEFT or MyResourceFieldAnchor() == FRAMEPOINT_TOP or MyResourceFieldAnchor() == FRAMEPOINT_RIGHT or MyResourceFieldAnchor() == FRAMEPOINT_CENTER then
call BlzFrameSetPoint(field, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldLastLineStart), FRAMEPOINT_BOTTOMLEFT, 0, 0)
else
call BlzFrameSetPoint(field, FRAMEPOINT_BOTTOMLEFT, BlzGetFrameByName("MyResourceField", udg_MyResourceFieldLastLineStart), FRAMEPOINT_TOPLEFT, 0, 0)
endif
set udg_MyResourceFieldLastLineStart = udg_MyResourceFieldCount
endif
endif
call BlzFrameSetSize(field, MyResourceFieldSizeX(), MyResourceFieldSizeY())
call BlzFrameSetSize(BlzGetFrameByName("MyResourceFieldBackground", udg_MyResourceFieldCount), MyResourceFieldSizeX(), MyResourceFieldSizeY() + 0.0102)
set field = null
endfunction
function MyResourceFieldsCheckBox takes nothing returns nothing
if GetTriggerPlayer() == GetLocalPlayer() then //only do something for the player having pressed the checkbox
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossF",0), BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_UNCHECKED)
call BlzFrameSetVisible(BlzGetFrameByName("MyResourceFieldBossS",0), BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_UNCHECKED)
endif
endfunction
function MyResourceFieldCreateCheckBoxAction takes nothing returns nothing
local trigger trig = CreateTrigger()
local framehandle fh = BlzCreateFrameByType("GLUECHECKBOX", "MyResourceFieldCheckBox", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),"QuestCheckBox",0)
local framehandle fhText = BlzCreateFrameByType("TEXT", "MyResourceFieldCheckBoxLabel", fh, "", 0)
call BlzFrameSetAbsPoint(fh, FRAMEPOINT_TOPLEFT, MyResourceFieldCheckBoxX(), MyResourceFieldCheckBoxY())
call BlzFrameSetPoint(fhText, FRAMEPOINT_TOP, fh, FRAMEPOINT_BOTTOM, 0.0, 0.0)
call BlzFrameSetEnable(fhText, false)
call BlzFrameSetText(fhText, MyResourceFieldCheckBoxLabelText())
call BlzTriggerRegisterFrameEvent(trig, fh, FRAMEEVENT_CHECKBOX_CHECKED)
call BlzTriggerRegisterFrameEvent(trig, fh, FRAMEEVENT_CHECKBOX_UNCHECKED)
call TriggerAddAction(trig, function MyResourceFieldsCheckBox)
set fh = null
set fhText = null
set trig = null
endfunction
function MyResourceFieldInit takes nothing returns nothing
local integer rows = 1
local integer cols
local integer colsExit = MyResourceFieldAutoCreateCols()
local framehandle tooltip
local framehandle tooltipText
local framehandle tooltipTitle
call BlzLoadTOCFile("war3mapImported\\MyResourceField.toc")
set udg_MyResourceFieldCount = 0
if not BlzFrameIsVisible(BlzGetFrameByName("SimpleReplayPanel",0)) then
call TriggerAddAction( gg_trg_MyResourceField, function MyResourceFieldUpdateBars)
if MyResourceFieldCreateCheckBox() then
call MyResourceFieldCreateCheckBoxAction()
endif
else
call TriggerAddAction( gg_trg_MyResourceField, function MyResourceFieldUpdateBars)
endif
call BlzCreateFrameByType("FRAME", "MyResourceFieldBossF", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),"",0) //Parent of Frames (tooltips stuff)
call BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldBossSBest", BlzGetFrameByName("ResourceBarFrame",0),"",0) //Upper Parent of the SimpleFrames it is used for the Hide Feature.
call BlzCreateFrameByType("SIMPLEFRAME", "MyResourceFieldBossS", BlzGetFrameByName("MyResourceFieldBossSBest",0),"",0) //Parent of SimpleFrames (bar and its content)
set tooltip = BlzCreateFrame("MyResourceFieldBoxedText", BlzGetFrameByName("MyResourceFieldBossF", 0), 0, 0)
set tooltipTitle = BlzGetFrameByName("MyResourceFieldBoxedTextTitle", 0)
set tooltipText = BlzGetFrameByName("MyResourceFieldBoxedTextValue", 0)
// when using TOP LEFT/RIGHT Title is the placed one, otherwise the Text
if GetHandleId(MyResourceFieldTooltipPoint()) <= 2 then
call BlzFrameSetAbsPoint(tooltipTitle, MyResourceFieldTooltipPoint(), MyResourceFieldTooltipX(), MyResourceFieldTooltipY())
call BlzFrameSetPoint(tooltipText, FRAMEPOINT_TOPLEFT, tooltipTitle, FRAMEPOINT_BOTTOMLEFT, 0, -0.002)
else
call BlzFrameSetAbsPoint(tooltipText, MyResourceFieldTooltipPoint(), MyResourceFieldTooltipX(), MyResourceFieldTooltipY())
call BlzFrameSetPoint(tooltipTitle, FRAMEPOINT_BOTTOMLEFT, tooltipText, FRAMEPOINT_TOPLEFT, 0, 0.002)
endif
call BlzFrameSetSize(tooltipTitle, MyResourceFieldTooltipSizeX(), 0)
call BlzFrameSetSize(tooltipText, MyResourceFieldTooltipSizeX(), 0)
call BlzFrameSetPoint(tooltip, FRAMEPOINT_TOPLEFT, tooltipTitle, FRAMEPOINT_TOPLEFT, -0.005, 0.005)
call BlzFrameSetPoint(tooltip, FRAMEPOINT_BOTTOMRIGHT, tooltipText, FRAMEPOINT_BOTTOMRIGHT, 0.005, -0.005)
set tooltip = null
if MyResourceFieldAutoCreateRows()> 0 then
loop
set cols = 1
loop
call CreateMyResourceField(cols == 1)
set cols = cols + 1
exitwhen cols > colsExit
endloop
set rows = rows + 1
set colsExit = colsExit + MyResourceFieldAutoCreateColAddEachRow()
exitwhen rows > MyResourceFieldAutoCreateRows() or colsExit <= 0
endloop
endif
endfunction
//===========================================================================
function InitTrig_MyResourceField takes nothing returns nothing
set gg_trg_MyResourceField = CreateTrigger()
set udg_MyResourceFieldCreateFree = CreateTrigger()
set udg_MyResourceFieldHideTrigger = CreateTrigger()
call TriggerRegisterTimerEventPeriodic( gg_trg_MyResourceField , 0.1)
call TimerStart(CreateTimer(),0.0, false, function MyResourceFieldInit)
call FrameLoaderAdd(function MyResourceFieldInit)
call TriggerAddAction(udg_MyResourceFieldCreateFree, function CreateMyResourceFieldFree)
call TriggerAddAction(udg_MyResourceFieldHideTrigger, function MyResourceFieldCustomHiding)
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag_Actions takes nothing returns nothing
local integer MAX_CHARGES = 10
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00M')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag takes nothing returns nothing
set gg_trg_GoldBag = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag, function Trig_GoldBag_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag1_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00Z')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag1 takes nothing returns nothing
set gg_trg_GoldBag1 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag1, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag1, function Trig_GoldBag1_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag2_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00L')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag2 takes nothing returns nothing
set gg_trg_GoldBag2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag2, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag2, function Trig_GoldBag2_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag3_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I002')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag3 takes nothing returns nothing
set gg_trg_GoldBag3 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag3, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag3, function Trig_GoldBag3_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag4_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I005')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag4 takes nothing returns nothing
set gg_trg_GoldBag4 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag4, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag4, function Trig_GoldBag4_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag5_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I003')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag5 takes nothing returns nothing
set gg_trg_GoldBag5 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag5, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag5, function Trig_GoldBag5_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag6_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00E')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag6 takes nothing returns nothing
set gg_trg_GoldBag6 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag6, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag6, function Trig_GoldBag6_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag7_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I001')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag7 takes nothing returns nothing
set gg_trg_GoldBag7 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag7, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag7, function Trig_GoldBag7_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag8_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00A')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag8 takes nothing returns nothing
set gg_trg_GoldBag8 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag8, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag8, function Trig_GoldBag8_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag9_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00O')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag9 takes nothing returns nothing
set gg_trg_GoldBag9 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag9, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag9, function Trig_GoldBag9_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag10_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00N')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag10 takes nothing returns nothing
set gg_trg_GoldBag10 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag10, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag10, function Trig_GoldBag10_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag11_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I017')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag11 takes nothing returns nothing
set gg_trg_GoldBag11 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag11, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag11, function Trig_GoldBag11_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag12_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I016')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag12 takes nothing returns nothing
set gg_trg_GoldBag12 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag12, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag12, function Trig_GoldBag12_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag13_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00J')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag13 takes nothing returns nothing
set gg_trg_GoldBag13 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag13, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag13, function Trig_GoldBag13_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag14_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I014')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag14 takes nothing returns nothing
set gg_trg_GoldBag14 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag14, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag14, function Trig_GoldBag14_Actions )
endfunction
//TESH.scrollpos=9
//TESH.alwaysfold=0
function Trig_GoldBag15_Actions takes nothing returns nothing
local integer MAX_CHARGES = 200
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00D')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag15 takes nothing returns nothing
set gg_trg_GoldBag15 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag15, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag15, function Trig_GoldBag15_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag16_Actions takes nothing returns nothing
local integer MAX_CHARGES = 10
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00F')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag16 takes nothing returns nothing
set gg_trg_GoldBag16 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag16, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag16, function Trig_GoldBag16_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag17_Actions takes nothing returns nothing
local integer MAX_CHARGES = 10
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00I')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag17 takes nothing returns nothing
set gg_trg_GoldBag17 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag17, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag17, function Trig_GoldBag17_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag18_Actions takes nothing returns nothing
local integer MAX_CHARGES = 10
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01B')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag18 takes nothing returns nothing
set gg_trg_GoldBag18 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag18, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag18, function Trig_GoldBag18_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag19_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01F')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag19 takes nothing returns nothing
set gg_trg_GoldBag19 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag19, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag19, function Trig_GoldBag19_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag20_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01H')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag20 takes nothing returns nothing
set gg_trg_GoldBag20 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag20, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag20, function Trig_GoldBag20_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag21_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01J')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag21 takes nothing returns nothing
set gg_trg_GoldBag21 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag21, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag21, function Trig_GoldBag21_Actions )
endfunction
//TESH.scrollpos=3
//TESH.alwaysfold=0
function Trig_GoldBag22_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01Q')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag22 takes nothing returns nothing
set gg_trg_GoldBag22 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag22, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag22, function Trig_GoldBag22_Actions )
endfunction
//TESH.scrollpos=6
//TESH.alwaysfold=0
function Trig_GoldBag23_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01L')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag23 takes nothing returns nothing
set gg_trg_GoldBag23 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag23, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag23, function Trig_GoldBag23_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag24_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I01X')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag24 takes nothing returns nothing
set gg_trg_GoldBag24 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag24, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag24, function Trig_GoldBag24_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag25_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02A')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag25 takes nothing returns nothing
set gg_trg_GoldBag25 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag25, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag25, function Trig_GoldBag25_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag26_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00L')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag26 takes nothing returns nothing
set gg_trg_GoldBag26 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag26, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag26, function Trig_GoldBag26_Actions )
endfunction
//TESH.scrollpos=8
//TESH.alwaysfold=0
function Trig_GoldBag27_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I03K')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag27 takes nothing returns nothing
set gg_trg_GoldBag27 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag27, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag27, function Trig_GoldBag27_Actions )
endfunction
//TESH.scrollpos=8
//TESH.alwaysfold=0
function Trig_GoldBag28_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02N')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag28 takes nothing returns nothing
set gg_trg_GoldBag28 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag28, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag28, function Trig_GoldBag28_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag29_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I04A')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag29 takes nothing returns nothing
set gg_trg_GoldBag29 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag29, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag29, function Trig_GoldBag29_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag30_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I048')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag30 takes nothing returns nothing
set gg_trg_GoldBag30 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag30, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag30, function Trig_GoldBag30_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag31_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I04B')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag31 takes nothing returns nothing
set gg_trg_GoldBag31 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag31, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag31, function Trig_GoldBag31_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag32_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I038')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag32 takes nothing returns nothing
set gg_trg_GoldBag32 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag32, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag32, function Trig_GoldBag32_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag33_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I03A')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag33 takes nothing returns nothing
set gg_trg_GoldBag33 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag33, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag33, function Trig_GoldBag33_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag34_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I03T')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag34 takes nothing returns nothing
set gg_trg_GoldBag34 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag34, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag34, function Trig_GoldBag34_Actions )
endfunction
//TESH.scrollpos=9
//TESH.alwaysfold=0
function Trig_GoldBag35_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02T')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag35 takes nothing returns nothing
set gg_trg_GoldBag35 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag35, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag35, function Trig_GoldBag35_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag36_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02N')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag36 takes nothing returns nothing
set gg_trg_GoldBag36 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag36, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag36, function Trig_GoldBag36_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag37_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I04O')then
loop
exitwhen i > 5 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag37 takes nothing returns nothing
set gg_trg_GoldBag37 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag37, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag37, function Trig_GoldBag37_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag38_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I04P')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag38 takes nothing returns nothing
set gg_trg_GoldBag38 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag38, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag38, function Trig_GoldBag38_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag39_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02O')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag39 takes nothing returns nothing
set gg_trg_GoldBag39 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag39, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag39, function Trig_GoldBag39_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag40_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02W')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag40 takes nothing returns nothing
set gg_trg_GoldBag40 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag40, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag40, function Trig_GoldBag40_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag41_Actions takes nothing returns nothing
local integer MAX_CHARGES = 1000
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I00C')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag41 takes nothing returns nothing
set gg_trg_GoldBag41 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag41, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag41, function Trig_GoldBag41_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag42_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02S')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag42 takes nothing returns nothing
set gg_trg_GoldBag42 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag42, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag42, function Trig_GoldBag42_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag43_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02U')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag43 takes nothing returns nothing
set gg_trg_GoldBag43 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag43, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag43, function Trig_GoldBag43_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag44_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02T')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag44 takes nothing returns nothing
set gg_trg_GoldBag44 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag44, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag44, function Trig_GoldBag44_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag45_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02V')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag45 takes nothing returns nothing
set gg_trg_GoldBag45 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag45, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag45, function Trig_GoldBag45_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag46_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02K')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag46 takes nothing returns nothing
set gg_trg_GoldBag46 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag46, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag46, function Trig_GoldBag46_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag47_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02I')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag47 takes nothing returns nothing
set gg_trg_GoldBag47 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag47, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag47, function Trig_GoldBag47_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag48_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02L')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag48 takes nothing returns nothing
set gg_trg_GoldBag48 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag48, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag48, function Trig_GoldBag48_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag49_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02J')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag49 takes nothing returns nothing
set gg_trg_GoldBag49 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag49, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag49, function Trig_GoldBag49_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag50_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02M')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag50 takes nothing returns nothing
set gg_trg_GoldBag50 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag50, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag50, function Trig_GoldBag50_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag51_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02H')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag51 takes nothing returns nothing
set gg_trg_GoldBag51 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag51, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag51, function Trig_GoldBag51_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag52_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02E')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag52 takes nothing returns nothing
set gg_trg_GoldBag52 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag52, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag52, function Trig_GoldBag52_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag53_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02G')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag53 takes nothing returns nothing
set gg_trg_GoldBag53 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag53, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag53, function Trig_GoldBag53_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag54_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02O')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag54 takes nothing returns nothing
set gg_trg_GoldBag54 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag54, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag54, function Trig_GoldBag54_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag55_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I02W')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag55 takes nothing returns nothing
set gg_trg_GoldBag55 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag55, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag55, function Trig_GoldBag55_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GoldBag56_Actions takes nothing returns nothing
local integer MAX_CHARGES = 99
local unit u = GetTriggerUnit()
local item picked_item = GetManipulatedItem()
local item slot_item = null
local integer picked_item_id = GetItemTypeId(picked_item)
local integer charges_source = GetItemCharges(picked_item)
local integer charges_target = 0
local integer i = 0
if(picked_item_id=='I05T')then
loop
exitwhen i > 10 or charges_source <= 0
set slot_item = UnitItemInSlot(u,i)
set charges_target = GetItemCharges(slot_item)
if (slot_item!=picked_item) and (GetItemTypeId(slot_item)==picked_item_id) and (charges_target<MAX_CHARGES) then
if(charges_target+charges_source>MAX_CHARGES)then
call SetItemCharges(slot_item,MAX_CHARGES)
set charges_source = charges_source-(MAX_CHARGES-charges_target)
else
call SetItemCharges(slot_item,charges_target+charges_source)
set charges_source = 0
endif
endif
set i = i + 1
endloop
if charges_source == 0 then
call RemoveItem(picked_item)
else
call SetItemCharges(picked_item,charges_source)
endif
endif
set picked_item = null
set u = null
set slot_item = null
endfunction
//===========================================================================
function InitTrig_GoldBag56 takes nothing returns nothing
set gg_trg_GoldBag56 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GoldBag56, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_GoldBag56, function Trig_GoldBag56_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
library DestructableLib initializer Initialization
//* ============================================================================ *
//* Made by PitzerMike *
//* *
//* I made this to detect if a destructable is a tree or not. It works not only *
//* for the standard trees but also for custom destructables created with the *
//* object editor. It uses a footie as a dummy with the goul's harvest ability. *
//* The dummy ids can be changed though. I also added the IsDestructableDead *
//* function for completeness. *
//* ============================================================================ *
globals
private constant integer DUMMY_UNIT_ID = 'hfoo' // footman
private constant integer HARVEST_ID = 'Ahrl' // ghouls harvest
private constant player OWNING_PLAYER = Player(15)
private unit dummy = null
endglobals
function IsDestructableDead takes destructable dest returns boolean
return GetDestructableLife(dest) <= 0.405
endfunction
function IsDestructableTree takes destructable dest returns boolean
local boolean result = false
if (dest != null) then
call PauseUnit(dummy, false)
set result = IssueTargetOrder(dummy, "harvest", dest)
call PauseUnit(dummy, true) // stops order
endif
return result
endfunction
private function Initialization takes nothing returns nothing
set dummy = CreateUnit(OWNING_PLAYER, DUMMY_UNIT_ID, 0.0, 0.0, 0.0)
call ShowUnit(dummy, false) // cannot enumerate
call UnitAddAbility(dummy, HARVEST_ID)
call UnitAddAbility(dummy, 'Aloc') // unselectable, invulnerable
call PauseUnit(dummy, true)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library RT initializer Init
globals
private trigger Trig = CreateTrigger()
private constant real RegrowTime = 20
endglobals
function RegrowTrees takes nothing returns nothing
local destructable d = GetTriggerDestructable()
call TriggerSleepAction(RegrowTime)
call DestructableRestoreLife( d, GetDestructableMaxLife(d), true )
set d=null
endfunction
function Revival takes nothing returns nothing
if IsDestructableTree(GetEnumDestructable())==true then
call TriggerRegisterDeathEvent( Trig, GetEnumDestructable() )
endif
endfunction
function Init takes nothing returns nothing
call EnumDestructablesInRect(bj_mapInitialPlayableArea,null,function Revival )
call TriggerAddAction(Trig,function RegrowTrees)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Init initializer Set
globals
private real MAP_MIN_X
private real MAP_MAX_X
private real MAP_MIN_Y
private real MAP_MAX_Y
endglobals
function IsInMapXY takes real x , real y returns boolean
return x > MAP_MIN_X and x < MAP_MAX_X and y > MAP_MIN_Y and y < MAP_MAX_Y
endfunction
private function Set takes nothing returns nothing
set MAP_MIN_X = GetRectMinX(bj_mapInitialPlayableArea)
set MAP_MAX_X = GetRectMaxX(bj_mapInitialPlayableArea)
set MAP_MIN_Y = GetRectMinY(bj_mapInitialPlayableArea)
set MAP_MAX_Y = GetRectMaxY(bj_mapInitialPlayableArea)
endfunction
endlibrary
//***************************************************************************
//*
//* SetUnitZ - By TriggerHappy187
//*
//***************************************************************************
//*
//* Installation
//* * All you need to do is copy this script into your map and you can use
//* the provided functions.
//*
//***************************************************************************
//*
//* Requirements
//* * This requires no external systems, all it requires is JassHelper.
//*
//***************************************************************************
//
// Precautions
// * If this function is used on a point with a terarin deformation
// A desync may occur.
//
//***************************************************************************
library SetUnitZ
globals
private location heightFixer = Location(0,0)
endglobals
function GetCoordZ takes real x, real y returns real
call MoveLocation(heightFixer, x, y)
return GetLocationZ(heightFixer)
endfunction
function SetUnitZ takes unit u, real h returns nothing
local location loc = GetUnitLoc(u)
local real z = GetLocationZ(loc)
call RemoveLocation(loc)
set loc = null
call SetUnitFlyHeight(u,h-z,0.)
endfunction
//function SetUnitZ takes unit whichUnit, real height, real rate returns nothing
// if GetUnitFlyHeight(whichUnit) == 0 then
// if UnitAddAbility(whichUnit, 'Arav') then
// call UnitRemoveAbility(whichUnit, 'Arav')
// endif
// endif
// //call MoveLocation(heightFixer, GetUnitX(whichUnit), GetUnitY(whichUnit))
// call SetUnitFlyHeight(whichUnit, height-GetCoordZ(GetUnitX(whichUnit), GetUnitY(whichUnit)), rate)
//endfunction
function GetUnitZ takes unit whichUnit returns real
call MoveLocation(heightFixer, GetUnitX(whichUnit), GetUnitY(whichUnit))
return GetUnitFlyHeight(whichUnit)+GetLocationZ(heightFixer)
endfunction
endlibrary
library GetTerrainZ
// How to Implement:
//
// by D.V.D
//
// Copy this code
// Create a trigger in your map
// Change the trigger to custom script
// Paste the code into the trigger
globals
location GL = Location(0,0)
endglobals
function GetTerrainZ takes real x, real y returns real
call MoveLocation(GL, x, y)
return GetLocationZ(GL)
endfunction
function GetTerrainZLoc takes location loc returns real
call MoveLocation(GL, GetLocationX(loc), GetLocationY(loc))
return GetLocationZ(GL)
endfunction
endlibrary
//TESH.scrollpos=-1
//TESH.alwaysfold=0
scope Grenade initializer Init
private keyword Data
globals
// Editable Globals
private constant integer GRENADE_ID = 'gdum' // Grenade unit
private constant integer GRENADE_SFX1 = 'xdum' // SFX 1
private constant integer GRENADE_SFX2 = 'xsfx' // SFX 2
private constant integer SPELL_ID = 'GAId' // Ability ID
private constant real MAX_RANGE = 1000
private constant real MIN_RANGE = 400
private constant real MAX_HEIGHT = 200
private constant attacktype AT = ATTACK_TYPE_NORMAL
private constant damagetype DT = DAMAGE_TYPE_NORMAL
private constant weapontype WT = WEAPON_TYPE_WHOKNOWS
private constant boolean DAMAGE_SELF = true// Can it hurt player units ?
private constant boolean DAMAGE_ALLY = true// Can it hurt ally units ?
// Editable Globals
// Don't change...
private constant real PERIOD = 0.04 // Depends on what period you like ... don't moan at me if your .0001 period lags though...
private constant real SPEED = 700 * PERIOD// How fast the grenade travels per second
private Data DATA //Temp Globals
private real X //Temp Globals
private real Y //Temp Globals
private real DIST //Temp Globals
private integer COUNT = 0
private Data array GData
private timer TIMER = CreateTimer()
private location LOC = Location(0,0)
//Don't change
endglobals
private constant function AOE_Range takes integer lvl returns real
return 150 + lvl*50 *1.0
endfunction
private function MinMax takes real val,real min,real max returns real
if(min>val) then
return min
elseif(val>max) then
return max
else
return val
endif
endfunction
private function GetParabolaZ takes real x,real d,real h returns real
return 4 * h * x * (d - x) / (d * d)
endfunction // By AceHart
private function GetDamage takes integer level returns real
return GetRandomReal (400,500) + 15 * (level-1)
endfunction// I guess Flare @ TH.net helped me with this O_o...
private struct Data
unit Grenade
unit caster
player p
real x
real y
real DistCur
real DistMax
real baseH
real aoe
integer level
real cos
real sin
static group GROUP = CreateGroup()
static method Damage takes nothing returns boolean
local unit u = GetFilterUnit()
local player p = GetOwningPlayer(u)
local Data d = DATA
local real damage = GetDamage(d.level)
local boolean dmg = false
if(DAMAGE_SELF and p==d.p)then
set dmg = true
elseif(DAMAGE_ALLY and IsPlayerAlly(p,d.p))then
set dmg = true
elseif(IsPlayerEnemy(p,d.p))then
set dmg = true
endif
if(dmg) then
call UnitDamageTarget(d.caster,u,damage,true,true,AT,DT,WT)
endif
set u = null
return false
endmethod
static method InCircle takes nothing returns boolean
local destructable d = GetFilterDestructable()
local real x = DATA.x - GetDestructableX(d)
local real y = DATA.y - GetDestructableY(d)
local real dist = x*x+y*y
set d = null
if(dist>DATA.aoe*DATA.aoe)then// or SquareRoot(dist) > AOE_RANGE either workz...
return false
else
return true
endif
endmethod
static method TreeDestroy takes nothing returns nothing
local destructable d = GetEnumDestructable()
if IsDestructableTree(d) then
call KillDestructable(d)
endif
set d = null
endmethod
method KillTrees takes real x,real y returns nothing
local rect r = Rect(x-.aoe,y-.aoe,x+.aoe,y+.aoe)
call EnumDestructablesInRect(r,Filter(function Data.InCircle),function Data.TreeDestroy)
call RemoveRect(r)
set r = null
endmethod
method Explode takes nothing returns nothing
call UnitApplyTimedLife(CreateUnit(.p,GRENADE_SFX1,.x,.y,0),0,1)
call UnitApplyTimedLife(CreateUnit(.p,GRENADE_SFX2,.x,.y,0),0,1)
set DATA = this
call GroupEnumUnitsInRange(.GROUP,.x,.y,this.aoe,Filter(function Data.Damage))
call .KillTrees(.x,.y)
call .destroy()
endmethod
method onDestroy takes nothing returns nothing
call ShowUnit(.Grenade,false)// Don't know wether this is neccesary ?
call RemoveUnit(.Grenade)
endmethod
endstruct
private function Execute takes nothing returns nothing
local integer i = 0
local Data d
local unit u
local boolean zhit
loop
exitwhen i == COUNT
set zhit = false
set d = GData[i]
set u = d.Grenade
set d.DistCur = d.DistCur + SPEED
set d.x = d.x + SPEED * d.cos
set d.y = d.y + SPEED * d.sin
if IsInMapXY(d.x,d.y) == true then
call SetUnitX(u,d.x)
call SetUnitY(u,d.y)
call SetUnitZ(u,d.baseH+GetParabolaZ(d.DistCur,d.DistMax,MAX_HEIGHT))
call MoveLocation(LOC,d.x,d.y)
if(R2I(GetUnitZ(u))==R2I(GetLocationZ(LOC)))then
// R2I because it gives me '0.001' and stuff ... so it isn't 'equal' unit height
set zhit=true
endif
if zhit==true then
set COUNT = COUNT - 1
set GData[i] = GData[COUNT]
call d.Explode()
else
set i = i + 1
endif
else
set COUNT = COUNT - 1
set GData[i] = GData[COUNT]
call d.destroy()
endif
endloop
set u = null
if COUNT == 0 then
call PauseTimer(TIMER)
endif
endfunction
private function Run takes nothing returns nothing
local Data d = Data.create()
local location l = GetSpellTargetLoc()
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real dist = 0
local real facing
call RemoveLocation(l)// do I need to 'set l = null' ?
set d.caster = GetTriggerUnit()
set l = GetUnitLoc(d.caster)
set d.baseH = GetLocationZ(l)
call RemoveLocation(l)
set l = null
set d.p = GetOwningPlayer(d.caster)
set d.x = GetUnitX(d.caster)
set d.y = GetUnitY(d.caster)
set d.level = GetUnitAbilityLevel(d.caster,SPELL_ID)
set d.aoe = AOE_Range(d.level)
set x = x - d.x
set y = y - d.y
set facing = Atan2(y,x)
set d.cos = Cos(facing)
set d.sin = Sin(facing)
set d.Grenade = CreateUnit(d.p,GRENADE_ID,d.x,d.y,facing)
call UnitAddAbility(d.Grenade,'Amrf')// I have to do this or else it goes buggy over raised terrain
call UnitRemoveAbility(d.Grenade,'Amrf')
set d.DistMax = MinMax(SquareRoot(x*x+y*y),MIN_RANGE,MAX_RANGE)
set d.DistCur = 0
set GData[COUNT] = d
set COUNT = COUNT + 1
if COUNT == 1 then
call TimerStart(TIMER,PERIOD,true,function Execute)
endif
endfunction
private function Cond takes nothing returns boolean
if GetSpellAbilityId() == SPELL_ID then
call Run()
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t,Condition(function Cond))
endfunction
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
//
//
// To Implement the spell
//
//
// Copy the following : UNITS
//
// Explosion -> 'xdum'
// Explosion SFX -> 'xsfx''
// Grenade -> ' gdum''
//
//
//
// Copy the following : ABILITy
//
// Grenade -> 'GAId'
//
//
// Copy the following : Triggers
//
// Regrow Trees
// IsDestructableTree
// InitLibrary
//
//
//
// You can change many of the grenades features, such as :
//
// max height , max/min range , aoe range
// damage , wether it can hurt allied or player units
//
//TESH.scrollpos=-1
//TESH.alwaysfold=0
scope BouncyGrenade initializer Init
private keyword Data
globals
// Editable Globals
private constant integer GRENADE_ID = 'n007'
private constant integer GRENADE_SFX1 = 'n00C'
private constant integer GRENADE_SFX2 = 'n00D'
private constant integer SPELL_ID = 'A009'
private constant integer MAX_BOUNCES = 2// How many bounces ?
private constant real BOUNCE_DECREASE = 1.5// How much the range divises by per bounce
private constant real MAX_RANGE = 1200// max range of grenade
private constant real MIN_RANGE = 400// min range of grenade
private constant real MAX_HEIGHT = 200// maximum height reachable
private constant attacktype AT = ATTACK_TYPE_NORMAL // attack type..
private constant damagetype DT = DAMAGE_TYPE_NORMAL// damage type..
private constant weapontype WT = WEAPON_TYPE_WHOKNOWS// Weapon type..
private constant boolean DAMAGE_SELF = true// Can it hurt player units ?
private constant boolean DAMAGE_ALLY = true// Can it hurt ally units ?
//
// Don't change...
private constant real PERIOD = 0.04 // Depends on what period you like ... don't moan at me if your .0001 period lags though...
private constant real SPEED = 700 *PERIOD // How fast the grenade travels per second
private Data DATA// Temp Globals
private real X //Temp Globals
private real Y //Temp Globals
private real DIST //Temp Globals
private integer COUNT = 0
private Data array GData
private timer TIMER = CreateTimer()
//You can now continue to the rest of the code...
endglobals
private constant function AOE_Range takes integer lvl returns real
return 150 + lvl*50 *1.0// Find AoE for Grenade explosion
endfunction
private function MinMax takes real val,real min,real max returns real
if(min>val) then
return min
elseif(val>max) then
return max
else
return val
endif
endfunction
private function GetRange takes real range returns real
return range/BOUNCE_DECREASE// devise the range
endfunction
private function GetSpeed takes real range returns real
return (range/MAX_RANGE)*SPEED*2// find speed with this 'formula'
endfunction
private function GetHeight takes real range returns real// find the max height for that bounce
return MinMax((range/MAX_RANGE)*MAX_HEIGHT*3,0,MAX_HEIGHT)
endfunction
private function GetParabolaZ takes real x,real d,real h returns real
return 4 * h * x * (d - x) / (d * d)
endfunction // By AceHart
private function GetDamage takes integer level returns real
return GetRandomReal (400,500) + 15 * (level-1)
endfunction// I guess Flare @ TH.net helped me with this O_o...
private struct Data
unit Grenade
unit caster
player p
real x
real y
real DistCur
real DistMax
real HeightMax
real heightBase
real baseH
real aoe
real facing
integer level
real speed
real cos
real sin
integer bounce
boolean justBounced
static group GROUP = CreateGroup()
static method Damage takes nothing returns boolean// To damage the targets near grenade
local unit u = GetFilterUnit()
local player p = GetOwningPlayer(u)
local Data d = DATA
local real damage = GetDamage(d.level)
local boolean dmg = false
if(DAMAGE_SELF and p==d.p)then// damage the caster's and player units ... if possible ?
set dmg = true
elseif(DAMAGE_ALLY and IsPlayerAlly(p,d.p))then// hurt allies ?
set dmg = true
elseif(IsPlayerEnemy(p,d.p))then// or just enemies...
set dmg = true
endif
if(dmg) then
call UnitDamageTarget(d.caster,u,damage,true,true,AT,DT,WT)// the damage..
endif
set u = null
return false// return false to not add to global group..
endmethod
static method InCircle takes nothing returns boolean
local destructable d = GetFilterDestructable()
local real x = DATA.x - GetDestructableX(d)
local real y = DATA.y - GetDestructableY(d)
local real dist = x*x+y*y
// Check if the destructable is in range of the grenade AoE
set d = null
if(dist>DATA.aoe*DATA.aoe)then// or SquareRoot(dist) > AOE_RANGE either workz...
return false
else
return true
endif
endmethod
static method TreeDestroy takes nothing returns nothing
local destructable d = GetEnumDestructable()
if IsDestructableTree(d) then
call KillDestructable(d)// Destroy the tree if its a tree...
endif
set d = null//nulls...
endmethod
method KillTrees takes real x,real y returns nothing
local rect r = Rect(x-.aoe,y-.aoe,x+.aoe,y+.aoe)
// find trees within a rect then find within a circle...
call EnumDestructablesInRect(r,Filter(function Data.InCircle),function Data.TreeDestroy)
call RemoveRect(r)// nulls...
set r = null
endmethod
method Explode takes nothing returns nothing
call UnitApplyTimedLife(CreateUnit(.p,GRENADE_SFX1,.x,.y,0),0,1)
call UnitApplyTimedLife(CreateUnit(.p,GRENADE_SFX2,.x,.y,0),0,1)// Add each SFX for a second
set DATA = this
// global data for enums ...
call GroupEnumUnitsInRange(.GROUP,.x,.y,this.aoe,Filter(function Data.Damage))
call .KillTrees(.x,.y)
call .destroy()// kill trees then destroy self..
endmethod
method onDestroy takes nothing returns nothing
call ShowUnit(.Grenade,false)// Don't know wether this is neccesary ?
call RemoveUnit(.Grenade)
endmethod
method NewBounce takes nothing returns nothing// set new data for that bounce
local location l = GetUnitLoc(.Grenade)
set .bounce = .bounce + 1// increase bounce
set .DistMax = .DistCur/BOUNCE_DECREASE// find the distmax from the distance traveled / decrement
set .DistCur = 0// reset dist traveled
set .HeightMax = GetHeight(.DistMax)// formula for height
set .speed = GetSpeed(.DistMax)// find the speed for new bounce
set .baseH = GetLocationZ(l)//find 'this' bounce height again..
call RemoveLocation(l)// leaks
set l = null
endmethod
endstruct
private function Execute takes nothing returns nothing
local integer i = 0
local Data d
local unit u
local boolean zhit // Z - Hit if anyone has a weird font like me which looks like an s ...
local location l = Location(0,0)
loop
exitwhen i == COUNT
set zhit = false
set d = GData[i]
set u = d.Grenade
set d.DistCur = d.DistCur + d.speed
set d.x = d.x + d.speed * d.cos// moving data...
set d.y = d.y + d.speed * d.sin
if IsInMapXY(d.x,d.y) == true then// grenade in map
call SetUnitX(u,d.x)
call SetUnitY(u,d.y)// move the grenade
call SetUnitZ(u,d.baseH+GetParabolaZ(d.DistCur,d.DistMax,d.HeightMax))
// set unit Z
call MoveLocation(l,d.x,d.y)
if(R2I(GetUnitZ(u))==R2I(GetLocationZ(l)))then
// R2I because it gives me '0.001' and stuff ... so it isn't 'equal' unit height
set zhit=true
endif
// I dont think the dist current can go higher than the max... but just in case
if zhit==true then
if d.bounce==2 then
set COUNT = COUNT - 1
set GData[i] = GData[COUNT]// next instance
call d.Explode()
else
call d.NewBounce()// new bounce because of zhit
endif
else
set i = i + 1// just increase the value to the next instance
endif
else
set COUNT = COUNT - 1// change to next instance
set GData[i] = GData[COUNT]
call d.destroy()
endif
endloop
call RemoveLocation(l)
set u = null// leaks
set l = null
if COUNT == 0 then
call PauseTimer(TIMER)// pause
endif
endfunction
private function Run takes nothing returns nothing
local Data d = Data.create()
local location l = GetSpellTargetLoc()
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real dist = 0// locals for data
local real facing
call RemoveLocation(l)// do I need to 'set l = null' ?
set d.caster = GetTriggerUnit()
set l = GetUnitLoc(d.caster)
set d.baseH = GetLocationZ(l)
call RemoveLocation(l)
set l = null// leaks
set d.caster = GetTriggerUnit()
set d.p = GetOwningPlayer(d.caster)
set d.x = GetUnitX(d.caster)// caster data
set d.y = GetUnitY(d.caster)
set d.level = GetUnitAbilityLevel(d.caster,SPELL_ID)
set d.aoe = AOE_Range(d.level)
set d.bounce = 0
set x = x - d.x
set y = y - d.y
set facing = Atan2(y,x)
set d.cos = Cos(facing)
set d.sin = Sin(facing)// facing,,,
set d.Grenade = CreateUnit(d.p,GRENADE_ID,d.x,d.y,facing)
call UnitAddAbility(d.Grenade,'Amrf')// I have to do this or else it goes buggy over raised terrain
call UnitRemoveAbility(d.Grenade,'Amrf')
set d.DistMax = MinMax(SquareRoot(x*x+y*y)/Pow(BOUNCE_DECREASE,MAX_BOUNCES),0,MAX_RANGE)
set d.HeightMax = GetHeight(d.DistMax)// height, dist , speed data
set d.speed = GetSpeed(d.DistMax)
//MinMax(SquareRoot(x*x+y*y),MIN_RANGE,MAX_RANGE)
set d.DistCur = 0
set GData[COUNT] = d
set COUNT = COUNT + 1
if COUNT == 1 then
call TimerStart(TIMER,PERIOD,true,function Execute)
endif
endfunction
private function Cond takes nothing returns boolean
if GetSpellAbilityId() == SPELL_ID then
call Run()
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t,Condition(function Cond))
endfunction
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
//
//
// To Implement the spell
//
//
// Copy the following : UNITS
//
// Explosion -> 'xdum'
// Explosion SFX -> 'xsfx''
// Grenade -> ' gdum''
//
//
//
// Copy the following : ABILITy
//
// Grenade -> 'BGid'
//
//
// Copy the following : Triggers
//
// Regrow Trees
// IsDestructableTree
// InitLibrary
//
//
// You can change many of the grenades features, such as :
//
// max height , max/min range , aoe range
// damage , wether it can hurt allied or player units
// max bounces , how far each bounce ... bounces
//
// I tried to make the formulas even as if they were a real grenade...
// slowing down , not bouncing as high , and traveling less distance
//TESH.scrollpos=12
//TESH.alwaysfold=0
library TerrainPathability initializer Init
//******************************************************************************
//* BY: Rising_Dusk
//*
//* This script can be used to detect the type of pathing at a specific point.
//* It is valuable to do it this way because the IsTerrainPathable is very
//* counterintuitive and returns in odd ways and aren't always as you would
//* expect. This library, however, facilitates detecting those things reliably
//* and easily.
//*
//******************************************************************************
//*
//* > function IsTerrainDeepWater takes real x, real y returns boolean
//* > function IsTerrainShallowWater takes real x, real y returns boolean
//* > function IsTerrainLand takes real x, real y returns boolean
//* > function IsTerrainPlatform takes real x, real y returns boolean
//* > function IsTerrainWalkable takes real x, real y returns boolean
//*
//* These functions return true if the given point is of the type specified
//* in the function's name and false if it is not. For the IsTerrainWalkable
//* function, the MAX_RANGE constant below is the maximum deviation range from
//* the supplied coordinates that will still return true.
//*
//* The IsTerrainPlatform works for any preplaced walkable destructable. It will
//* return true over bridges, destructable ramps, elevators, and invisible
//* platforms. Walkable destructables created at runtime do not create the same
//* pathing hole as preplaced ones do, so this will return false for them. All
//* other functions except IsTerrainWalkable return false for platforms, because
//* the platform itself erases their pathing when the map is saved.
//*
//* After calling IsTerrainWalkable(x, y), the following two global variables
//* gain meaning. They return the X and Y coordinates of the nearest walkable
//* point to the specified coordinates. These will only deviate from the
//* IsTerrainWalkable function arguments if the function returned false.
//*
//* Variables that can be used from the library:
//* [real] TerrainPathability_X
//* [real] TerrainPathability_Y
//*
globals
private constant real MAX_RANGE = 10.
private constant integer DUMMY_ITEM_ID = 'wolg'
endglobals
globals
private item Item = null
private rect Find = null
private item array Hid
private integer HidMax = 0
public real X = 0.
public real Y = 0.
endglobals
function IsTerrainDeepWater takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
function IsTerrainShallowWater takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
function IsTerrainLand takes real x, real y returns boolean
return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY)
endfunction
function IsTerrainPlatform takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
private function HideItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set Hid[HidMax] = GetEnumItem()
call SetItemVisible(Hid[HidMax], false)
set HidMax = HidMax + 1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
//Hide any items in the area to avoid conflicts with our item
call MoveRectTo(Find, x, y)
call EnumItemsInRect(Find ,null, function HideItem)
//Try to move the test item and get its coords
call SetItemPosition(Item, x, y) //Unhides the item
set X = GetItemX(Item)
set Y = GetItemY(Item)
static if LIBRARY_IsTerrainWalkable then
//This is for compatibility with the IsTerrainWalkable library
set IsTerrainWalkable_X = X
set IsTerrainWalkable_Y = Y
endif
call SetItemVisible(Item, false)//Hide it again
//Unhide any items hidden at the start
loop
exitwhen HidMax <= 0
set HidMax = HidMax - 1
call SetItemVisible(Hid[HidMax], true)
set Hid[HidMax] = null
endloop
//Return walkability
return (X-x)*(X-x)+(Y-y)*(Y-y) <= MAX_RANGE*MAX_RANGE and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
private function Init takes nothing returns nothing
set Find = Rect(0., 0., 128., 128.)
set Item = CreateItem(DUMMY_ITEM_ID, 0, 0)
call SetItemVisible(Item, false)
endfunction
endlibrary
//TESH.scrollpos=135
//TESH.alwaysfold=0
scope StaticFieldE
//native UnitAlive takes unit id returns boolean
globals
private constant real FPS = 0.0312500
private constant string MODEL_PATH = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
private constant integer SPELL_ID = 'A04J'
private constant string LIGHTNING_ID = "FORK"
private constant real LIGHTNING_RED = 1
private constant real LIGHTNING_GREEN = 0.45
private constant real LIGHTNING_BLUE = 0.15
private constant real LIGHTNING_ALPHA = 1.
private constant real DURATION = 0.75
private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC
private constant damagetype D_TYPE = DAMAGE_TYPE_MAGIC
private constant real SPEED = 300.
endglobals
private constant function MaxDamage takes integer level returns real
return 75.*level
endfunction
private constant function MinDamage takes integer level returns real
return 30.*level
endfunction
private constant function Aoe takes integer level returns real
return 300 + 75.*level
endfunction
private function UnitFilter takes player source, unit targ returns boolean
return IsUnitEnemy(targ, source) and UnitAlive(targ) and not IsUnitType(targ, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
//! textmacro_once STATIC_FIELD_ALLOC
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
//! endtextmacro
private struct SF extends array
unit targ
unit cast
lightning light
real dmg
real cx
real cy
real cz
real tx
real ty
real x
real y
real z
integer steps
thistype prev
thistype next
static integer count
static timer period
static group g
static location loc
method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
call UnitDamageTarget(this.cast, this.targ, this.dmg, true, false, A_TYPE, D_TYPE, null)
call DestroyLightning(this.light)
call SetUnitPropWindow(this.targ, GetUnitDefaultPropWindow(this.targ)*bj_DEGTORAD)
set this.light = null
set this.cast = null
set this.targ = null
endmethod
static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.tx = this.tx+this.x
set this.ty = this.ty+this.y
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(this.targ)
if IsTerrainWalkable(this.tx, this.ty) then
call MoveLightningEx(this.light, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetUnitX(this.targ, this.tx)
call SetUnitY(this.targ, this.ty)
endif
set this.steps = this.steps - 1
if this.steps == 0 then
call this.destroy()
endif
set this = this.next
endloop
endmethod
static method cond takes nothing returns boolean
local thistype this
local integer lvl
local real angle
local unit u
local unit v
local real x
local real y
local player p
local real dist
if GetSpellAbilityId() == SPELL_ID then
set u = GetTriggerUnit()
set x = GetUnitX(u)
set y = GetUnitY(u)
set p = GetOwningPlayer(u)
set lvl = GetUnitAbilityLevel(u, SPELL_ID)
call GroupEnumUnitsInRange(g, x, y, Aoe(lvl), null)
call DestroyEffect(AddSpecialEffect(MODEL_PATH, x, y))
loop
set v = FirstOfGroup(g)
exitwhen v == null
call GroupRemoveUnit(g,v)
if UnitFilter(p,v) then
//! runtextmacro STATIC_FIELD_ALLOC()
set this.cast = u
set this.targ = v
set this.cx = x
set this.cy = y
set this.tx = GetUnitX(v)
set this.ty = GetUnitY(v)
set angle = Atan2(this.ty-y, this.tx-x)
set dist = SquareRoot((this.tx-x)*(this.tx-x) + (this.ty-y)*(this.ty-y))
set this.dmg = MinDamage(lvl) + (1-(dist/Aoe(lvl)))*(MaxDamage(lvl)-MinDamage(lvl))
set this.x = SPEED*FPS*Cos(angle)
set this.y = SPEED*FPS*Sin(angle)
call MoveLocation(loc, x, y)
set this.cz = GetLocationZ(loc)
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(v)
set this.light = AddLightningEx(LIGHTNING_ID, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
set this.steps = R2I(DURATION/FPS)
call SetUnitPropWindow(this.targ, 0)
endif
endloop
set u = null
set p = null
endif
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.cond))
call Preload(MODEL_PATH)
set count = 0
set period = CreateTimer()
set g = CreateGroup()
set loc = Location(0,0)
set t = null
endmethod
endstruct
endscope
//TESH.scrollpos=186
//TESH.alwaysfold=0
scope StaticFieldA
native UnitAlive takes unit id returns boolean
globals
private constant real FPS = 0.0312500
private constant string MODEL_PATH = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
private constant integer SPELL_ID = 'A150'
private constant string LIGHTNING_ID = "FORK"
private constant real LIGHTNING_RED = 0.15
private constant real LIGHTNING_GREEN = 0.45
private constant real LIGHTNING_BLUE = 1.
private constant real LIGHTNING_ALPHA = 1.
private constant real DURATION = 0.75
private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC
private constant damagetype D_TYPE = DAMAGE_TYPE_MAGIC
endglobals
private constant function MaxDamage takes integer level returns real
return 75.*level
endfunction
private constant function MinDamage takes integer level returns real
return 30.*level
endfunction
private constant function Aoe takes integer level returns real
return 600 + 75.*level
endfunction
private function UnitFilter takes player source, unit targ returns boolean
return IsUnitEnemy(targ, source) and UnitAlive(targ) and not IsUnitType(targ, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
//! textmacro_once STATIC_FIELD_ALLOC
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
//! endtextmacro
private struct Caster extends array
real x
real y
real temp
thistype prev
thistype next
static integer count
static timer period
method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
endmethod
static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.temp = this.temp - FPS
if this.temp <= 0 then
call DestroyEffect(AddSpecialEffect(MODEL_PATH, this.x, this.y))
call this.destroy()
endif
set this = this.next
endloop
endmethod
static method add takes real x, real y returns nothing
local thistype this
//! runtextmacro STATIC_FIELD_ALLOC()
set this.x = x
set this.y = y
set this.temp = DURATION
endmethod
static method onInit takes nothing returns nothing
set count = 0
set period = CreateTimer()
endmethod
endstruct
private struct SF extends array
unit targ
unit cast
lightning light
real dmg
real cx
real cy
real cz
real tx
real ty
real x
real y
real z
integer steps
thistype prev
thistype next
static integer count
static timer period
static group g
static location loc
method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
call UnitDamageTarget(this.cast, this.targ, this.dmg, true, false, A_TYPE, D_TYPE, null)
call DestroyLightning(this.light)
call SetUnitPropWindow(this.targ, GetUnitDefaultPropWindow(this.targ)*bj_DEGTORAD)
set this.light = null
set this.cast = null
set this.targ = null
endmethod
static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.tx = this.tx+this.x
set this.ty = this.ty+this.y
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(this.targ)
if IsTerrainWalkable(this.tx, this.ty) then
call MoveLightningEx(this.light, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetUnitX(this.targ, this.tx)
call SetUnitY(this.targ, this.ty)
endif
set this.steps = this.steps - 1
if this.steps == 0 then
call this.destroy()
endif
set this = this.next
endloop
endmethod
static method cond takes nothing returns boolean
local thistype this
local integer lvl
local real angle
local unit u
local unit v
local real x
local real y
local player p
local real dist
if GetSpellAbilityId() == SPELL_ID then
set u = GetTriggerUnit()
set x = GetUnitX(u)
set y = GetUnitY(u)
set p = GetOwningPlayer(u)
set lvl = GetUnitAbilityLevel(u, SPELL_ID)
call GroupEnumUnitsInRange(g, x, y, Aoe(lvl), null)
loop
set v = FirstOfGroup(g)
exitwhen v == null
call GroupRemoveUnit(g,v)
if UnitFilter(p,v) then
//! runtextmacro STATIC_FIELD_ALLOC()
set this.cast = u
set this.targ = v
set this.cx = x
set this.cy = y
set this.tx = GetUnitX(v)
set this.ty = GetUnitY(v)
set angle = Atan2(this.ty-y, this.tx-x)
set dist = SquareRoot((this.tx-x)*(this.tx-x) + (this.ty-y)*(this.ty-y))
set this.dmg = MinDamage(lvl) + (dist/Aoe(lvl))*(MaxDamage(lvl)-MinDamage(lvl))
set this.x = -(dist/DURATION)*FPS*Cos(angle)
set this.y = -(dist/DURATION)*FPS*Sin(angle)
call MoveLocation(loc, x, y)
set this.cz = GetLocationZ(loc) + 20
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(v)
set this.light = AddLightningEx(LIGHTNING_ID, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
set this.steps = R2I(DURATION/FPS)
call SetUnitPropWindow(this.targ, 0)
endif
endloop
call Caster.add(x,y)
set u = null
set p = null
endif
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.cond))
call Preload(MODEL_PATH)
set count = 0
set period = CreateTimer()
set g = CreateGroup()
set loc = Location(0,0)
set t = null
endmethod
endstruct
endscope
//TESH.scrollpos=183
//TESH.alwaysfold=0
scope DistantFieldA
//native UnitAlive takes unit id returns boolean
globals
private constant real FPS = 0.0312500
private constant string MODEL_PATH = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
private constant integer SPELL_ID = 'A162'
private constant string LIGHTNING_ID = "FORK"
private constant real LIGHTNING_RED = 0.15
private constant real LIGHTNING_GREEN = 0.45
private constant real LIGHTNING_BLUE = 1.
private constant real LIGHTNING_ALPHA = 1.
private constant real DURATION = 0.75
private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC
private constant damagetype D_TYPE = DAMAGE_TYPE_MAGIC
endglobals
private constant function MaxDamage takes integer level returns real
return 75.*level
endfunction
private constant function MinDamage takes integer level returns real
return 30.*level
endfunction
private constant function Aoe takes integer level returns real
return 600 + 75.*level
endfunction
private function UnitFilter takes player source, unit targ returns boolean
return IsUnitEnemy(targ, source) and UnitAlive(targ) and not IsUnitType(targ, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
//! textmacro_once STATIC_FIELD_ALLOC
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
//! endtextmacro
private struct Caster extends array
real x
real y
real temp
thistype prev
thistype next
static integer count
static timer period
method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
endmethod
static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.temp = this.temp - FPS
if this.temp <= 0 then
call DestroyEffect(AddSpecialEffect(MODEL_PATH, this.x, this.y))
call this.destroy()
endif
set this = this.next
endloop
endmethod
static method add takes real x, real y returns nothing
local thistype this
//! runtextmacro STATIC_FIELD_ALLOC()
set this.x = x
set this.y = y
set this.temp = DURATION
endmethod
static method onInit takes nothing returns nothing
set count = 0
set period = CreateTimer()
endmethod
endstruct
private struct SF extends array
unit targ
unit cast
lightning light
real dmg
real cx
real cy
real cz
real tx
real ty
real x
real y
real z
integer steps
thistype prev
thistype next
static integer count
static timer period
static group g
static location loc
method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
call UnitDamageTarget(this.cast, this.targ, this.dmg, true, false, A_TYPE, D_TYPE, null)
call DestroyLightning(this.light)
call SetUnitPropWindow(this.targ, GetUnitDefaultPropWindow(this.targ)*bj_DEGTORAD)
set this.light = null
set this.cast = null
set this.targ = null
endmethod
static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.tx = this.tx+this.x
set this.ty = this.ty+this.y
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(this.targ)
if IsTerrainWalkable(this.tx, this.ty) then
call MoveLightningEx(this.light, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetUnitX(this.targ, this.tx)
call SetUnitY(this.targ, this.ty)
endif
set this.steps = this.steps - 1
if this.steps == 0 then
call this.destroy()
endif
set this = this.next
endloop
endmethod
static method cond takes nothing returns boolean
local thistype this
local integer lvl
local real angle
local unit u
local unit v
local real x
local real y
local player p
local real dist
if GetSpellAbilityId() == SPELL_ID then
set u = GetTriggerUnit()
set x = GetSpellTargetX()
set y = GetSpellTargetY()
set p = GetOwningPlayer(u)
set lvl = GetUnitAbilityLevel(u, SPELL_ID)
call GroupEnumUnitsInRange(g, x, y, Aoe(lvl), null)
loop
set v = FirstOfGroup(g)
exitwhen v == null
call GroupRemoveUnit(g,v)
if UnitFilter(p,v) then
//! runtextmacro STATIC_FIELD_ALLOC()
set this.cast = u
set this.targ = v
set this.cx = x
set this.cy = y
set this.tx = GetUnitX(v)
set this.ty = GetUnitY(v)
set angle = Atan2(this.ty-y, this.tx-x)
set dist = SquareRoot((this.tx-x)*(this.tx-x) + (this.ty-y)*(this.ty-y))
set this.dmg = MinDamage(lvl) + (dist/Aoe(lvl))*(MaxDamage(lvl)-MinDamage(lvl))
set this.x = -(dist/DURATION)*FPS*Cos(angle)
set this.y = -(dist/DURATION)*FPS*Sin(angle)
call MoveLocation(loc, x, y)
set this.cz = GetLocationZ(loc) + 20
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(v)
set this.light = AddLightningEx(LIGHTNING_ID, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
set this.steps = R2I(DURATION/FPS)
call SetUnitPropWindow(this.targ, 0)
endif
endloop
call Caster.add(x,y)
set u = null
set p = null
endif
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.cond))
call Preload(MODEL_PATH)
set count = 0
set period = CreateTimer()
set g = CreateGroup()
set loc = Location(0,0)
set t = null
endmethod
endstruct
endscope
//TESH.scrollpos=139
//TESH.alwaysfold=0
scope DistantFieldE
//native UnitAlive takes unit id returns boolean
globals
private constant real FPS = 0.0312500
private constant string MODEL_PATH = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
private constant integer SPELL_ID = 'A163'
private constant string LIGHTNING_ID = "FORK"
private constant real LIGHTNING_RED = 1
private constant real LIGHTNING_GREEN = 0.45
private constant real LIGHTNING_BLUE = 0.15
private constant real LIGHTNING_ALPHA = 1.
private constant real DURATION = 0.75
private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC
private constant damagetype D_TYPE = DAMAGE_TYPE_MAGIC
private constant real SPEED = 600.
endglobals
private constant function MaxDamage takes integer level returns real
return 75.*level
endfunction
private constant function MinDamage takes integer level returns real
return 30.*level
endfunction
private constant function Aoe takes integer level returns real
return 600 + 75.*level
endfunction
private function UnitFilter takes player source, unit targ returns boolean
return IsUnitEnemy(targ, source) and UnitAlive(targ) and not IsUnitType(targ, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
//! textmacro_once STATIC_FIELD_ALLOC
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
//! endtextmacro
private struct SF extends array
unit targ
unit cast
lightning light
real dmg
real cx
real cy
real cz
real tx
real ty
real x
real y
real z
integer steps
thistype prev
thistype next
static integer count
static timer period
static group g
static location loc
method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
call UnitDamageTarget(this.cast, this.targ, this.dmg, true, false, A_TYPE, D_TYPE, null)
call DestroyLightning(this.light)
call SetUnitPropWindow(this.targ, GetUnitDefaultPropWindow(this.targ)*bj_DEGTORAD)
set this.light = null
set this.cast = null
set this.targ = null
endmethod
static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.tx = this.tx+this.x
set this.ty = this.ty+this.y
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(this.targ)
if IsTerrainWalkable(this.tx, this.ty) then
call MoveLightningEx(this.light, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetUnitX(this.targ, this.tx)
call SetUnitY(this.targ, this.ty)
endif
set this.steps = this.steps - 1
if this.steps == 0 then
call this.destroy()
endif
set this = this.next
endloop
endmethod
static method cond takes nothing returns boolean
local thistype this
local integer lvl
local real angle
local unit u
local unit v
local real x
local real y
local player p
local real dist
if GetSpellAbilityId() == SPELL_ID then
set u = GetTriggerUnit()
set x = GetSpellTargetX()
set y = GetSpellTargetY()
set p = GetOwningPlayer(u)
set lvl = GetUnitAbilityLevel(u, SPELL_ID)
call GroupEnumUnitsInRange(g, x, y, Aoe(lvl), null)
call DestroyEffect(AddSpecialEffect(MODEL_PATH, x, y))
loop
set v = FirstOfGroup(g)
exitwhen v == null
call GroupRemoveUnit(g,v)
if UnitFilter(p,v) then
//! runtextmacro STATIC_FIELD_ALLOC()
set this.cast = u
set this.targ = v
set this.cx = x
set this.cy = y
set this.tx = GetUnitX(v)
set this.ty = GetUnitY(v)
set angle = Atan2(this.ty-y, this.tx-x)
set dist = SquareRoot((this.tx-x)*(this.tx-x) + (this.ty-y)*(this.ty-y))
set this.dmg = MinDamage(lvl) + (1-(dist/Aoe(lvl)))*(MaxDamage(lvl)-MinDamage(lvl))
set this.x = SPEED*FPS*Cos(angle)
set this.y = SPEED*FPS*Sin(angle)
call MoveLocation(loc, x, y)
set this.cz = GetLocationZ(loc) + 20
call MoveLocation(loc, this.tx, this.ty)
set this.z = GetLocationZ(loc) + 20 + GetUnitFlyHeight(v)
set this.light = AddLightningEx(LIGHTNING_ID, true, this.cx, this.cy, this.cz, this.tx, this.ty, this.z)
call SetLightningColor(this.light, LIGHTNING_RED, LIGHTNING_GREEN, LIGHTNING_BLUE, LIGHTNING_ALPHA)
set this.steps = R2I(DURATION/FPS)
call SetUnitPropWindow(this.targ, 0)
endif
endloop
set u = null
set p = null
endif
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.cond))
call Preload(MODEL_PATH)
set count = 0
set period = CreateTimer()
set g = CreateGroup()
set loc = Location(0,0)
set t = null
endmethod
endstruct
endscope
//TESH.scrollpos=8
//TESH.alwaysfold=0
library ListModule
//===========================================================================
// Information:
//==============
//
// This library provides the List module, which allows you to easily create
// a linked list of all of the allocated instances of a struct-type. Iterating
// through a linked list is about 12% faster than iteratating through an array
// in JASS. There is no faster method to iterate through a list of structs than
// the method used by this module. Aside from the marginal speed gain, the best
// use of this library is to hide some ugly low-level code from your structs.
// Rather than manually building and maintaining a list of struct instances,
// just implement the List module, and your code will become much prettier.
//
//===========================================================================
// How to use the List module:
//=============================
//
// Using the List module is pretty simple. First, implement it in your
// struct (preferably at the top to avoid unnecessary TriggerEvaluate calls).
// In the struct's create method, you must call listAdd(). In the onDestroy
// method, you must also call listRemove(). An example is shown below:
/*
struct Example
implement List
static method create takes nothing returns Example
local Example this = allocate()
call listAdd() //This method adds the instance to the list.
return this
endmethod
method onDestroy takes nothing returns nothing
call listRemove() //This method removes the instance from the list.
endmethod
endstruct
*/
// The requirement to call listAdd() and listRemove() will be done away
// with once JassHelper supports module onDestroy and module onCreate, but
// for now, it is not too much of a burden.
//
// Once this is done, your struct will gain all of the methods detailed
// in the API section. Below is an example of how to iterate through the list
// of allocated structs of the implementing struct-type:
/*
function IterationExample takes nothing returns nothing
local Example e = Example.first
loop
exitwhen e == 0
//Do something with e here.
set e = e.next
endloop
//Use .last and .prev instead to iterate backwards.
endmethod
*/
//
//===========================================================================
// List module API:
//==================
//
// (readonly)(static) first -> thistype
// This member contains the first instance of thistype in the list.
//
// (readonly)(static) last -> thistype
// This member contains the last instance of thistype in the list.
//
// (readonly)(static) count -> integer
// This member contains the number of allocated structs of thistype.
//
// (readonly) next -> thistype
// This member contains the next instance of thistype in the list.
//
// (readonly) prev -> thistype
// This member contains the previous instance of thistype in the list.
//
// listAdd()
// This method adds this instance to the list of structs of thistype.
// This should be called on each instance after it is allocated (within
// the create method).
//
// listRemove()
// This method removes this instance from the list of structs of thistype.
// This should be called on each instance before it is destroyed (within
// the onDestroy method).
//
// (static) listDestroy()
// This method destroys all the structs of thistype within the list.
//
//===========================================================================
module List
private static boolean destroying = false
private boolean inlist = false
readonly static integer count = 0
readonly thistype next = 0
readonly thistype prev = 0
static method operator first takes nothing returns thistype
return thistype(0).next
endmethod
static method operator last takes nothing returns thistype
return thistype(0).prev
endmethod
method listRemove takes nothing returns nothing
if not inlist then
return
endif
set inlist = false
set prev.next = next
set next.prev = prev
set count = count - 1
endmethod
method listAdd takes nothing returns nothing
if inlist or destroying then
return
endif
set inlist = true
set last.next = this
set prev = last
set thistype(0).prev = this
set count = count + 1
endmethod
static method listDestroy takes nothing returns nothing
local thistype this = last
set destroying = true
loop
exitwhen this == 0
call destroy()
set this = prev
endloop
set destroying = false
endmethod
endmodule
endlibrary
//TESH.scrollpos=291
//TESH.alwaysfold=0
library AirplaneSystem requires ListModule, optional AutoIndex
/*
.~@ FINGOLFINS AIRPLANE MOVEMENT SYSTEM @~.
INSTRUCTIONS:
- Implement AutoIndex as specified in its description
- Create your airplane units as you would with any normal unit
- Set the turn speed of your airplanes to something below 0.1 (use shift-click)
- Register plane types by adding this line to the initPlaneTypes function:
call registerPlaneType('xxxx')
where 'xxxx' is the id of your airplane.
*/
//=======================//
//======= GLOBALS =======//
//=======================//
globals
private constant real UPDATE_INTERVAL = 0.03125 //I SUBMIT TO THIS FOLLY
private constant real ORDER_INTERVAL = 1 // HOW OFTEN ORDERS ARE REFRESHED
private constant real DEFAULT_FACING = 270
private constant integer MAX_PLAYERS = 24
//LOWER NUMBERS = LESS INERTIA. SET TO ZERO TO REMOVE INERTIA COMPLETELY. THIS VALUE MUST BE LOWER THAN 1!
private constant real AIR_FRICTION = 0.945
//A CONSTANT MULTIPILER TO THE UNIT SPEED, TO CIRCUMVENT THE HARDCODED SPEED LIMIT OF WC3.
private constant real SPEED_FACTOR = 1.6
//MAX DISTANCE TO MAP BORDER WHERE PLANES CAN TRAVEL
private constant real BORDER_WIDTH = 200
//MAP BOUNDS
private real MAP_MAX_X
private real MAP_MAX_Y
private real MAP_MIN_X
private real MAP_MIN_Y
private constant integer ORDER_SMART = OrderId("smart")
private constant integer ORDER_MOVE = OrderId("move")
private constant integer ORDER_ATTACK = OrderId("attack")
private constant integer TYPES_KEY = StringHash("Airplane Types")
private constant integer INSTANCES_KEY = StringHash("Airplane Instances")
private hashtable Hash = InitHashtable()
endglobals
native UnitAlive takes unit id returns boolean
//=======================//
//===== SYSTEM CODE =====//
//=======================//
function IsUnitPlane takes unit whichunit returns boolean
return HaveSavedInteger(Hash, TYPES_KEY, GetUnitTypeId(whichunit))
endfunction
private function RegisterPlaneType takes integer unitid returns nothing
call SaveInteger(Hash, TYPES_KEY, unitid, 1)
endfunction
private function InitPlaneTypes takes nothing returns nothing
//REGISTER YOUR PLANE TYPES LIKE THIS
call RegisterPlaneType('n01W')
call RegisterPlaneType('n01X')
endfunction
struct Plane
implement List
unit plane = null
unit target = null
real vx = 0
real vy = 0
real tx = 0
real ty = 0
real speed = 0
integer order = 0
private static timer t1
private static timer t2
private static method get takes unit whichunit returns thistype
return LoadInteger(Hash, INSTANCES_KEY, GetHandleId(whichunit))
endmethod
method onDestroy takes nothing returns nothing
//DON'T GIVE ME CRAP ABOUT USING onDestroy(), IT POSES NO PERFORMANCE ISSUE IN THIS CASE.
call .listRemove()
call RemoveSavedInteger(Hash, INSTANCES_KEY, GetHandleId(.plane))
if .count == 0 then
call PauseTimer(.t1)
call PauseTimer(.t2)
endif
endmethod
private static method updateOrder takes nothing returns nothing
local thistype this = .first
local thistype temp
local real x
local real y
if .count == 0 then
call PauseTimer(.t1)
call PauseTimer(.t2)
endif
loop
exitwhen this == 0
set temp = .next
if GetUnitTypeId(.plane) == 0 then
//DESTROY THE STRUCT WHEN THE PLANE NO LONGER EXISTS
call .destroy()
else
if .target != null then
if UnitAlive(.target) == false or GetUnitTypeId(.target) == 0 then
set .target = null
set .tx = GetUnitX(.plane)
set .ty = GetUnitY(.plane)
set .order = ORDER_ATTACK
else
call IssueTargetOrderById(.plane, .order, .target)
endif
else
if .order == ORDER_MOVE or .order == ORDER_SMART then
set x = GetUnitX(.plane)
set y = GetUnitY(.plane)
if (x - .tx)*(x - .tx) + (y - .ty)*(y - .ty) < 10000 then
//ALLOW THE UNIT TO ATTACK ONCE IT HAS REACHED ITS DESTINATION
set .order = ORDER_ATTACK
endif
endif
call IssuePointOrderById(.plane, .order, .tx, .ty)
endif
endif
set this = temp
endloop
endmethod
private static method updatePosition takes nothing returns nothing
local thistype this = .first
local real x = 0
local real y = 0
local real f = 0
loop
exitwhen this == 0
set f = GetUnitFacing(.plane)*bj_DEGTORAD
//ADD FRICTION FIRST INCASE IT IS ZEROED
set .vx = (.vx * AIR_FRICTION) + .speed * Cos(f)
set .vy = (.vy * AIR_FRICTION) + .speed * Sin(f)
set x = GetUnitX(.plane)+.vx
set y = GetUnitY(.plane)+.vy
//ENFORCE BOUNDS
if x > MAP_MAX_X then
set x = MAP_MAX_X
elseif x < MAP_MIN_X then
set x = MAP_MIN_X
endif
if y > MAP_MAX_Y then
set y = MAP_MAX_Y
elseif y < MAP_MIN_Y then
set y = MAP_MIN_Y
endif
call SetUnitX(.plane, x)
call SetUnitY(.plane, y)
set this = .next
endloop
endmethod
private static method onOrderTarget takes nothing returns boolean
local thistype this = thistype.get(GetTriggerUnit())
if this == 0 then
return false
endif
set .target = GetOrderTargetUnit()
set .tx = GetUnitX(.target)
set .ty = GetUnitY(.target)
set .order = GetIssuedOrderId()
return false
endmethod
private static method onOrderPoint takes nothing returns boolean
local real x = GetOrderPointX()
local real y = GetOrderPointY()
local thistype this = thistype.get(GetTriggerUnit())
if this == 0 then
return false
endif
set .tx = x
set .ty = y
set .target = null
set .order = GetIssuedOrderId()
return false
endmethod
static method create takes unit whichunit returns thistype
local thistype this = thistype.allocate()
call .listAdd()
call SaveInteger(Hash, INSTANCES_KEY, GetHandleId(whichunit), this)
//=========SOME MATH TRIVIA!=========//
//The acceleration is given by the following differential equation:
// v(t)' = a = v(t) - v(t)*(1-R), where R = AIR_FRICTION
//And it's solution:
//v(t) = (a/(1-R)*(1 + e^-(1-R)t)
//Calculating the limit when (t -> infinity) gives:
//vmax = a/(1-R)
//vmax*(1-R) = a (in this case 'vmax' is known and 'a' is unknown)
//===========END OF TRIVIA===========//
set .plane = whichunit
set .speed = GetUnitDefaultMoveSpeed(.plane)*(1-AIR_FRICTION)*UPDATE_INTERVAL*SPEED_FACTOR
set .tx = GetUnitX(.plane) + 500 * Cos(DEFAULT_FACING*bj_DEGTORAD)
set .ty = GetUnitY(.plane) + 500 * Sin(DEFAULT_FACING*bj_DEGTORAD)
set .order = ORDER_SMART
call SetUnitMoveSpeed(.plane, 0.01)
call SetUnitFacing(.plane, DEFAULT_FACING)
call SetUnitFlyHeight(.plane, 0, 0)
call SetUnitFlyHeight(.plane, GetUnitDefaultFlyHeight(.plane), GetUnitDefaultFlyHeight(.plane)/3)
if .count == 1 then
call TimerStart(.t1, UPDATE_INTERVAL, true, function thistype.updatePosition)
call TimerStart(.t2, ORDER_INTERVAL, true, function thistype.updateOrder)
endif
return this
endmethod
private static method onUnitEntersMap takes nothing returns boolean
call thistype.onIndex(GetFilterUnit())
return false
endmethod
private static method onIndex takes unit u returns nothing
if IsUnitPlane(u) then
call .create(u)
endif
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local rect r = GetWorldBounds()
local region map = CreateRegion()
local group g = CreateGroup()
set MAP_MAX_X = GetRectMaxX(r)-BORDER_WIDTH
set MAP_MAX_Y = GetRectMaxY(r)-BORDER_WIDTH
set MAP_MIN_X = GetRectMinX(r)+BORDER_WIDTH
set MAP_MIN_Y = GetRectMinY(r)+BORDER_WIDTH
set Plane.t1 = CreateTimer()
set Plane.t2 = CreateTimer()
call InitPlaneTypes()
loop
exitwhen i > MAX_PLAYERS
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
set i = i+1
endloop
call TriggerAddCondition(t, Condition(function Plane.onOrderTarget))
set t = CreateTrigger()
set i = 0
loop
exitwhen i > MAX_PLAYERS
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
set i = i+1
endloop
call TriggerAddCondition(t, Condition(function Plane.onOrderPoint))
static if (LIBRARY_AutoIndex) then
call OnUnitIndexed(Plane.onIndex)
else
set t = CreateTrigger()
call RegionAddRect(map, r)
call TriggerRegisterEnterRegion(t, map, function Plane.onUnitEntersMap)
set i = 0
loop
exitwhen i > MAX_PLAYERS
call GroupEnumUnitsOfPlayer(g, Player(i), function Plane.onUnitEntersMap)
set i = i+1
endloop
endif
call DestroyGroup(g)
call RemoveRect(r)
set g = null
set r = null
set t = null
set map = null
endmethod
endstruct
endlibrary