//TESH.scrollpos=0
//TESH.alwaysfold=0
native UnitAlive takes unit u returns boolean
Name | Type | is_array | initial_value |
HASH | hashtable | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
[COLOR="Yellow"][B][SIZE="3"]Luck Aura v1.3[/SIZE][/B][/COLOR]
Once activated, it brings good luck to the caster and his allies, giving a chance to drop random items from kills depending on the level of the spell.
|cffffcc00Level 1|r - 15% of Level 1 items,
|cffffcc00Level 2|r - 20% of Level 1-3 items.
|cffffcc00Level 3|r - 25% of Level 1-4 items.
|cffffcc00Level 4|r - 30% of Level 1-5 items.
[jass]
/*
===Luck Aura v1.3
===By Mckill2009
INSTALLATION:
- Copy the custom dummy unit/buff/abilities to your map
- You MUST input or change the correct rawID's (see below)
- To view rawID, press CTRL+D in the object editor
- Copy ALL the required libraries and the LuckAura trigger to your map (SimError is optional)
- Change the CONFIGURABLES and AOE if needed
- DONE!
REQUIRED LIBRARIES:
- RegisterPlayerUnitEvent by Magtheridon96
- Table by Bribe
- SpellEffectEvent by Bribe
- *SimError (Optional)
FULL DESCRIPTION:
Once activated, it brings good luck to the caster and his allies, giving a chance to drop random items from kills depending on the level of the spell.
|cffffcc00Level 1|r - 15% of Level 1 items,
|cffffcc00Level 2|r - 20% of Level 1-3 items.
|cffffcc00Level 3|r - 25% of Level 1-4 items.
|cffffcc00Level 4|r - 30% of Level 1-5 items.
|cffffcc00Spell lasts 30 seconds.|r
*/
scope LuckAura
globals
private Table lu //NEVER TOUCH THIS!
private constant itemtype ITEMID = ITEM_TYPE_ANY
private constant real AOE = 600 //Buff Effect or range, make sure that this matches the AOE of DUMMY_SPELL_ID
private constant integer SPELL_ID = 'A001' //Hero ability rawID
private constant integer DUMMY_SPELL_ID = 'A000' //Buff Aura rawID
private constant integer DUMMY_ID = 'h000' //Dummy Unit rawID
private constant integer BUFF = 'B000' //Buff Aura rawID
endglobals
//===CONFIGURABLES:
private function GetDuration takes integer i returns real
return 30.
endfunction
private function GetChance takes integer i returns integer
return 10 + i * 5
endfunction
//===END OF CONFIGURABLES
private function EnemyDies takes unit u, unit k returns nothing
local unit first
local integer level
call GroupEnumUnitsInRange(bj_lastCreatedGroup,GetUnitX(k),GetUnitY(k),AOE,null)
loop
set first = FirstOfGroup(bj_lastCreatedGroup)
exitwhen first==null
if UnitAlive(first) and lu.has(GetHandleId(first)) then
set level = lu[GetHandleId(first)]
if GetRandomInt(1,100) <= GetChance(level) and not IsUnitType(u, UNIT_TYPE_STRUCTURE) then
if level==1 then
call CreateItem(ChooseRandomItemEx(ITEMID, 1), GetUnitX(u), GetUnitY(u))
else
call CreateItem(ChooseRandomItemEx(ITEMID, GetRandomInt(1,level+1)), GetUnitX(u), GetUnitY(u))
endif
endif
endif
call GroupRemoveUnit(bj_lastCreatedGroup,first)
endloop
endfunction
private function EnemyDiesCond takes nothing returns nothing
if (GetUnitAbilityLevel(GetKillingUnit(), BUFF) > 0) and IsUnitEnemy(GetKillingUnit(),GetTriggerPlayer()) then
call EnemyDies(GetTriggerUnit(), GetKillingUnit())
endif
endfunction
private struct Luck
unit caster
unit dummy
real duration
private static timer tim
private static integer index = 0
private static integer array indexAR
private static thistype DATA
private static method looper takes nothing returns nothing
local thistype this
local integer i = 0
loop
set i = i+1
set this = indexAR[i]
if .duration > 0 and UnitAlive(.caster) then
set .duration = .duration - 0.5
call SetUnitX(.dummy, GetUnitX(.caster))
call SetUnitY(.dummy, GetUnitY(.caster))
else
call KillUnit(.dummy)
call lu.remove(GetHandleId(.caster))
set .caster = null
set .dummy = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set i = i-1
set index = index - 1
if index==0 then
call PauseTimer(tim)
call DestroyTimer(tim)
endif
endif
exitwhen i==index
endloop
endmethod
private static method cast takes nothing returns nothing
local thistype this
local unit u = GetTriggerUnit()
local timer t
local integer timerID
local integer casterID = GetHandleId(u)
local integer level
local player p = GetTriggerPlayer()
if not lu.has(casterID) then
set this = allocate()
set level = GetUnitAbilityLevel(u, SPELL_ID)
set lu[casterID] = level
set .caster = GetTriggerUnit()
set .dummy = CreateUnit(p, DUMMY_ID, GetUnitX(u), GetUnitY(u), 0)
set .duration = GetDuration(level)
if index==0 then
set tim = CreateTimer()
call TimerStart(tim, 0.5, true, function thistype.looper)
endif
set index = index + 1
set indexAR[index] = this
call UnitAddAbility(dummy, DUMMY_SPELL_ID)
call SetUnitAbilityLevel(dummy, DUMMY_SPELL_ID, level)
else
call IssueImmediateOrder(u, "stop")
static if LIBRARY_SimError then
call SimError(p, "Can't be used yet!")
endif
endif
set u = null
set p = null
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function EnemyDiesCond)
set lu = Table.create()
endmethod
endstruct
endscope
[/jass]
[Hidden=Changelogs]
v1.3
- Changed to structs
- Uses only 1 timer
- Uses 2 additional libraries
v1.2
- 6 Lines reduced.
- "u" is nulled from FilterThem.
- Ability level reduced to 4, as suggested by Bribe (I dont really understand why).
- Description changed.
v1.1
- Converted to vJass with optimized coding.
- Uses known libraries.
- Description changed.
[/hidden]
//TESH.scrollpos=0
//TESH.alwaysfold=0
//==========RESPAWN ON ORIGINAL XY INCLUDING HEROES==========
//===HOW TO USE:
//- Create a HASH variable in the trigger editor
//- Initialize the HASH
//- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
//- The trigger name MUST be >>> RespawnThem (or you may change it as long as it matches InitTrig_NAME_OF_TRIGGER below
//- Copy ALL that is written here (overwrite the existing texts in the trigger)
//- You may configure the time
//===============CONFIGURABLES====================
function RESPAWN_TIMER takes nothing returns real
return 5. //You may configure this on how many seconds it will respawn
endfunction
function RESPAWN_PLAYER_UNIT takes nothing returns integer
return PLAYER_NEUTRAL_AGGRESSIVE //You may configure this on which player respawns, at the moment the default is Neutral Hostile
endfunction
function RESPAWN_SFX takes nothing returns string
return "Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl" //You may configure youw own SFX
endfunction
//===============================================
function FilterThem takes nothing returns boolean
local unit u = GetFilterUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real facing = GetUnitFacing(u)
local integer ID = GetHandleId(u)
if GetOwningPlayer(u)==Player(RESPAWN_PLAYER_UNIT()) and IsUnitType(u, UNIT_TYPE_STRUCTURE)==false then
call SaveUnitHandle(udg_HASH, ID, 1, u)
call SaveReal(udg_HASH, ID, 2, x)
call SaveReal(udg_HASH, ID, 3, y)
call SaveReal(udg_HASH, ID, 4, facing)
endif
set u = null
return true
endfunction
function RespawnGet takes nothing returns nothing
call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, Filter(function FilterThem))
endfunction
function RespawnNow takes nothing returns nothing
local integer ID = GetHandleId(GetTriggerUnit())
local unit u = LoadUnitHandle(udg_HASH, ID, 1)
local real x = LoadReal(udg_HASH, ID, 2)
local real y = LoadReal(udg_HASH, ID, 3)
local real facing = LoadReal(udg_HASH, ID, 4)
local integer ty = GetUnitTypeId(u)
local unit newunit
local integer newunitID
if GetOwningPlayer(u)==Player(RESPAWN_PLAYER_UNIT()) then
//call BJDebugMsg("OK")
call TriggerSleepAction(RESPAWN_TIMER())
call DestroyEffect(AddSpecialEffect(RESPAWN_SFX(), x, y))
if IsUnitType(u, UNIT_TYPE_HERO)==true then
call ReviveHero(u, x, y,true)
else
set newunit = CreateUnit(GetOwningPlayer(GetTriggerUnit()), ty, x, y, facing)
set newunitID = GetHandleId(newunit)
call SaveUnitHandle(udg_HASH, newunitID, 1, newunit)
call SaveReal(udg_HASH, newunitID, 2, GetUnitX(newunit))
call SaveReal(udg_HASH, newunitID, 3, GetUnitY(newunit))
call SaveReal(udg_HASH, newunitID, 4, GetUnitFacing(newunit))
call FlushChildHashtable(udg_HASH, ID)
endif
endif
set u = null
set newunit = null
endfunction
//====================================================================
function InitTrig_RespawnThem takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger tt = CreateTrigger()
call TriggerRegisterTimerEvent (t, 0.5, false)
call TriggerRegisterAnyUnitEventBJ (tt, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction (t, function RespawnGet)
call TriggerAddAction (tt, function RespawnNow)
set t = null
set tt = null
endfunction
//TESH.scrollpos=3
//TESH.alwaysfold=0
library SimError initializer init
//**************************************************************************************************
//*
//* SimError
//*
//* Mimic an interface error message
//* call SimError(ForPlayer, msg)
//* ForPlayer : The player to show the error
//* msg : The error
//*
//* To implement this function, copy this trigger and paste it in your map.
//* Unless of course you are actually reading the library from wc3c's scripts section, then just
//* paste the contents into some custom text trigger in your map.
//*
//**************************************************************************************************
//==================================================================================================
globals
private sound error
endglobals
//====================================================================================================
function SimError takes player ForPlayer, string msg returns nothing
set msg="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00"+msg+"|r"
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
call DisplayTimedTextToPlayer( ForPlayer, 0.52, 0.96, 2.00, msg )
call StartSound( error )
endif
endfunction
private function init takes nothing returns nothing
set error=CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
//call StartSound( error ) //apparently the bug in which you play a sound for the first time
//and it doesn't work is not there anymore in patch 1.22
endfunction
endlibrary
//TESH.scrollpos=15
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v4.2.0.0
* By Magtheridon96
*
* I would like to give a special thanks to Bribe, azlier
* and BBQ for improving this library. For modularity, it only
* supports player unit events.
*
* Functions passed to RegisterPlayerUnitEvent must
* return false. They can return nothing as well.
*
* Disclaimer:
* -----------
*
* - Don't use TriggerSleepAction inside registered code.
*
* API:
* ----
*
* function RegisterPlayerUnitEvent
* takes
* playerunitevent whichEvent : The event you would like to register
* code whichFunction : The code you would like to register
* returns
* nothing
*
* - Registers code that will execute when an event fires.
*
**************************************************************/
library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
endlibrary
//TESH.scrollpos=41
//TESH.alwaysfold=0
//============================================================================
// SpellEffectEvent
// - Version 1.1.0.0
//
// API
// ---
// RegisterSpellEffectEvent(integer abil, code onCast)
//
// Requires
// --------
// RegisterPlayerUnitEvent: hiveworkshop.com/forums/showthread.php?t=203338
//
// Optional
// --------
// Table: hiveworkshop.com/forums/showthread.php?t=188084
//
library SpellEffectEvent requires RegisterPlayerUnitEvent, optional Table
//============================================================================
private module M
static if LIBRARY_Table then
static Table tb
else
static hashtable ht = InitHashtable()
endif
static method onCast takes nothing returns nothing
static if LIBRARY_Table then
call TriggerEvaluate(.tb.trigger[GetSpellAbilityId()])
else
call TriggerEvaluate(LoadTriggerHandle(.ht, 0, GetSpellAbilityId()))
endif
endmethod
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set .tb = Table.create()
endif
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.onCast)
endmethod
endmodule
//============================================================================
private struct S extends array
implement M
endstruct
//============================================================================
function RegisterSpellEffectEvent takes integer abil, code onCast returns nothing
static if LIBRARY_Table then
if not S.tb.handle.has(abil) then
set S.tb.trigger[abil] = CreateTrigger()
endif
call TriggerAddCondition(S.tb.trigger[abil], Filter(onCast))
else
if not HaveSavedHandle(S.ht, 0, abil) then
call SaveTriggerHandle(S.ht, 0, abil, CreateTrigger())
endif
call TriggerAddCondition(LoadTriggerHandle(S.ht, 0, abil), Filter(onCast))
endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
===Luck Aura v1.3
===By Mckill2009
INSTALLATION:
- Copy the custom dummy unit/buff/abilities to your map
- You MUST input or change the correct rawID's (see below)
- To view rawID, press CTRL+D in the object editor
- Copy ALL the required libraries and the LuckAura trigger to your map (SimError is optional)
- Change the CONFIGURABLES and AOE if needed
- DONE!
REQUIRED LIBRARIES:
- RegisterPlayerUnitEvent by Magtheridon96
- Table by Bribe
- SpellEffectEvent by Bribe
- *SimError (Optional)
FULL DESCRIPTION:
Once activated, it brings good luck to the caster and his allies, giving a chance to drop random items from kills depending on the level of the spell.
|cffffcc00Level 1|r - 15% of Level 1 items,
|cffffcc00Level 2|r - 20% of Level 1-3 items.
|cffffcc00Level 3|r - 25% of Level 1-4 items.
|cffffcc00Level 4|r - 30% of Level 1-5 items.
|cffffcc00Spell lasts 30 seconds.|r
*/
scope LuckAura
globals
private Table lu //NEVER TOUCH THIS!
private constant itemtype ITEMID = ITEM_TYPE_ANY
private constant real AOE = 600 //Buff Effect or range, make sure that this matches the AOE of DUMMY_SPELL_ID
private constant integer SPELL_ID = 'A001' //Hero ability rawID
private constant integer DUMMY_SPELL_ID = 'A000' //Buff Aura rawID
private constant integer DUMMY_ID = 'h000' //Dummy Unit rawID
private constant integer BUFF = 'B000' //Buff Aura rawID
endglobals
//===CONFIGURABLES:
private function GetDuration takes integer i returns real
return 30.
endfunction
private function GetChance takes integer i returns integer
return 10 + i * 5
endfunction
//===END OF CONFIGURABLES
private function EnemyDies takes unit u, unit k returns nothing
local unit first
local integer level
call GroupEnumUnitsInRange(bj_lastCreatedGroup,GetUnitX(k),GetUnitY(k),AOE,null)
loop
set first = FirstOfGroup(bj_lastCreatedGroup)
exitwhen first==null
if UnitAlive(first) and lu.has(GetHandleId(first)) then
set level = lu[GetHandleId(first)]
if GetRandomInt(1,100) <= GetChance(level) and not IsUnitType(u, UNIT_TYPE_STRUCTURE) then
if level==1 then
call CreateItem(ChooseRandomItemEx(ITEMID, 1), GetUnitX(u), GetUnitY(u))
else
call CreateItem(ChooseRandomItemEx(ITEMID, GetRandomInt(1,level+1)), GetUnitX(u), GetUnitY(u))
endif
endif
endif
call GroupRemoveUnit(bj_lastCreatedGroup,first)
endloop
endfunction
private function EnemyDiesCond takes nothing returns nothing
if (GetUnitAbilityLevel(GetKillingUnit(), BUFF) > 0) and IsUnitEnemy(GetKillingUnit(),GetTriggerPlayer()) then
call EnemyDies(GetTriggerUnit(), GetKillingUnit())
endif
endfunction
private struct Luck
unit caster
unit dummy
real duration
private static timer tim
private static integer index = 0
private static integer array indexAR
private static thistype DATA
private static method looper takes nothing returns nothing
local thistype this
local integer i = 0
loop
set i = i+1
set this = indexAR[i]
if .duration > 0 and UnitAlive(.caster) then
set .duration = .duration - 0.5
call SetUnitX(.dummy, GetUnitX(.caster))
call SetUnitY(.dummy, GetUnitY(.caster))
else
call KillUnit(.dummy)
call lu.remove(GetHandleId(.caster))
set .caster = null
set .dummy = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set i = i-1
set index = index - 1
if index==0 then
call PauseTimer(tim)
call DestroyTimer(tim)
endif
endif
exitwhen i==index
endloop
endmethod
private static method cast takes nothing returns nothing
local thistype this
local unit u = GetTriggerUnit()
local timer t
local integer timerID
local integer casterID = GetHandleId(u)
local integer level
local player p = GetTriggerPlayer()
if not lu.has(casterID) then
set this = allocate()
set level = GetUnitAbilityLevel(u, SPELL_ID)
set lu[casterID] = level
set .caster = GetTriggerUnit()
set .dummy = CreateUnit(p, DUMMY_ID, GetUnitX(u), GetUnitY(u), 0)
set .duration = GetDuration(level)
if index==0 then
set tim = CreateTimer()
call TimerStart(tim, 0.5, true, function thistype.looper)
endif
set index = index + 1
set indexAR[index] = this
call UnitAddAbility(dummy, DUMMY_SPELL_ID)
call SetUnitAbilityLevel(dummy, DUMMY_SPELL_ID, level)
else
call IssueImmediateOrder(u, "stop")
static if LIBRARY_SimError then
call SimError(p, "Can't be used yet!")
endif
endif
set u = null
set p = null
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function EnemyDiesCond)
set lu = Table.create()
endmethod
endstruct
endscope