//*************************************************************************************************
// Caster System Free Attach Variables / Sets and Tables (from 12.7)
//
// Requirement: gamecache global variable udg_cscache
//
//*************************************************************************************************
//##Begin of CS Gamecache engine##
//=================================================================================================
// GameCache - Return bug module : Without gamecache or return bug, JASS would be a
// retarded-limited scripting language.
//
//=================================================================================================
// a.k.a H2I, changed name to CS_H2I to prevent conflicts with other systems (I intended this
// system to be easy to copy
//
function CS_H2I takes handle h returns integer
return h
return 0
endfunction
//=================================================================================================
// Main Gamecache handler
//
function CSCache takes nothing returns gamecache
if udg_cscache==null then
call FlushGameCache(InitGameCache("CasterSystem.vx"))
set udg_cscache=InitGameCache("CasterSystem.vx")
call StoreInteger(udg_cscache,"misc","TableMaxReleasedIndex",100)
endif
return udg_cscache
endfunction
//==================================================================================================
// Attachable vars : Attacheable variables are what most other people call Handle Variables, they
// allow to relate data with any handle, using a label, and its value, the stuff auto flushes if
// the value is 0, false, "", or null .
//
// Differences between Attacheable variables and "Local Handle Variables" :
// - The names of the functions
// - The name of the function group does not cause confusion, it is difficult to say:
// "you should set local handle variables to null at the end of a function" since
// it sounds as if you were talking about the "Local Handle Variables"
// - Also Have Attacheable Sets.
// - And can work together with Tables.
//
// Notes: don't "attach" variables on texttags nor those handle types used mostly for parameters
// (for example damagetype) , Although there is no reason to do so anyways
//
// Gamecache stuff are NOT Case Sensitive, don't ever use "" for label (Crashes game!)
//
//============================================================================================================
// For integers
//
function AttachInt takes handle h, string label, integer x returns nothing
local string k=I2S(CS_H2I(h))
if x==0 then
call FlushStoredInteger(CSCache(),k,label)
else
call StoreInteger(CSCache(),k,label,x)
endif
endfunction
function GetAttachedInt_FromSet takes handle h, gamecache g returns integer
return GetStoredInteger(g,I2S(CS_H2I(h))+";"+GetStoredString(g,"argpass","set"),GetStoredString(g,"argpass","seti"))
endfunction
function GetAttachedInt takes handle h, string label returns integer
if (label=="") then
return GetAttachedInt_FromSet(h,CSCache())
endif
return GetStoredInteger(CSCache(), I2S(CS_H2I(h)), label)
endfunction
//=============================================================================================================
function AttachReal takes handle h, string label, real x returns nothing
local string k=I2S(CS_H2I(h))
if x==0 then
call FlushStoredReal(CSCache(),k,label)
else
call StoreReal(CSCache(),k,label,x)
endif
endfunction
function GetAttachedReal takes handle h, string label returns real
return GetStoredReal(CSCache(),I2S(CS_H2I(h)),label)
endfunction
//=============================================================================================================
function AttachBoolean takes handle h, string label, boolean x returns nothing
local string k=I2S(CS_H2I(h))
if not x then
call FlushStoredBoolean(CSCache(),k,label)
else
call StoreBoolean(CSCache(),k,label,x)
endif
endfunction
function GetAttachedBoolean takes handle h, string label returns boolean
return GetStoredBoolean(CSCache(),I2S(CS_H2I(h)),label)
endfunction
//=============================================================================================================
function AttachString takes handle h, string label, string x returns nothing
local string k=I2S(CS_H2I(h))
if x=="" then
call FlushStoredString(CSCache(),k,label)
else
call StoreString(CSCache(),k,label,x)
endif
endfunction
function GetAttachedString takes handle h, string label returns string
return GetStoredString(CSCache(),I2S(CS_H2I(h)),label)
endfunction
//=============================================================================================================
function AttachObject takes handle h, string label, handle x returns nothing
local string k=I2S(CS_H2I(h))
if (x==null) then
call FlushStoredInteger(CSCache(),k,label)
else
call StoreInteger(CSCache(),k,label,CS_H2I(x))
endif
endfunction
function GetAttachedObject takes handle h, string label returns handle
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedWidget takes handle h, string label returns widget
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedRect takes handle h, string label returns rect
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedRegion takes handle h, string label returns region
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedTimerDialog takes handle h, string label returns timerdialog
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedUnit takes handle h, string label returns unit
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedItem takes handle h, string label returns item
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedEffect takes handle h, string label returns effect
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedBoolExpr takes handle h, string label returns boolexpr
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedDestructable takes handle h, string label returns destructable
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedTrigger takes handle h, string label returns trigger
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedTimer takes handle h, string label returns timer
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedGroup takes handle h, string label returns group
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedTriggerAction takes handle h, string label returns triggeraction
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedLightning takes handle h, string label returns lightning
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedImage takes handle h, string label returns image
return GetAttachedInt(h,label)
return null
endfunction
function GetAttachedUbersplat takes handle h, string label returns ubersplat
return GetAttachedInt(h,label)
return null
endfunction
//============================================================================================================
// Attached Sets: Attachable Sets are handy in some situations and are a part of attachable variables,
// you can add integers or objects to a set, order doesn't matter and adding the same object twice is
// meaningless. CleanAttachedVars is always ready to clean every set owned by the handle.
//
//============================================================================================================
function AttachedSetAddInt takes handle h, string setn, integer int returns nothing
local gamecache g=CSCache()
local string k=I2S(CS_H2I(h))
local integer n
local integer x=GetStoredInteger(g,k,"#setnumberof;"+setn)
local integer y
if x==0 then
set y=GetStoredInteger(g,k,"#totalsets")+1
call StoreInteger(g,k,"#totalsets",y)
call StoreInteger(g,k,"#setnumberof;"+setn,y)
call StoreString(g,k,"#setName;"+I2S(y),setn)
endif
set k=k+";"+setn
if not HaveStoredInteger(g,k,"Pos"+I2S(int)) then
set n=GetStoredInteger(g,k,"n")+1
call StoreInteger(g,k,"n",n)
call StoreInteger(g,k,I2S(n),int)
call StoreInteger(g,k,"Pos"+I2S(int),n)
endif
set g=null
endfunction
function AttachedSetAddObject takes handle h, string setn, handle val returns nothing
call AttachedSetAddInt(h,setn,CS_H2I(val))
endfunction
//============================================================================================================
function AttachedSetHasInt takes handle h, string setn, integer int returns boolean
return HaveStoredInteger(CSCache(),I2S(CS_H2I(h))+";"+setn,"Pos"+I2S(int))
endfunction
function AttachedSetHasObject takes handle h, string setn, handle val returns boolean
return AttachedSetHasInt(h,setn,CS_H2I(val))
endfunction
//============================================================================================================
function GetAttachedSetSize takes handle h, string setn returns integer
return GetStoredInteger(CSCache(),I2S(CS_H2I(h))+";"+setn,"n")
endfunction
//============================================================================================================
function AttachedSetRemInt takes handle h, string setn, integer int returns nothing
local gamecache g=CSCache()
local string k=I2S(CS_H2I(h))+";"+setn
local integer n
local integer x
local integer y
if HaveStoredInteger(g,k,"Pos"+I2S(int)) then
set x=GetStoredInteger(g,k,"Pos"+I2S(int))
set n=GetStoredInteger(g,k,"n")
if x!=n then
set y=GetStoredInteger(g,k,I2S(n))
call StoreInteger(g,k,I2S(x),y)
call StoreInteger(g,k,"Pos"+I2S(y),x)
endif
call FlushStoredInteger(g,k,"Pos"+I2S(int))
call FlushStoredInteger(g,k,I2S(n))
call StoreInteger(g,k,"n",n-1)
endif
set g=null
endfunction
function AttachedSetRemObject takes handle h, string setn, handle val returns nothing
call AttachedSetRemInt(h,setn,CS_H2I(val))
endfunction
//============================================================================================================
function FromSetElement takes string setn, integer index returns string
local gamecache g=CSCache()
call StoreString(g,"argpass","set",setn)
call StoreString(g,"argpass","seti",I2S(index))
set g=null
return ""
endfunction
//============================================================================================================
function ClearAttachedSet takes handle h, string setn returns nothing
call FlushStoredMission(CSCache(),I2S(CS_H2I(h))+";"+setn)
endfunction
function CleanAttachedVars takes handle h returns nothing
local gamecache g=CSCache()
local string k=I2S(CS_H2I(h))
local integer n=GetStoredInteger(g,k,"#totalsets")
local integer i=1
loop
exitwhen i>n
call FlushStoredMission(g,k+";"+GetStoredString(g,k,"#setName;"+I2S(i)))
set i=i+1
endloop
call FlushStoredMission(g, k )
set g=null
endfunction
function CleanAttachedVars_NoSets takes handle h returns nothing
call FlushStoredMission(CSCache(), I2S(CS_H2I(h)) )
endfunction
Name | Type | is_array | initial_value |
AddLives | button | No | |
AddLives_Super | button | No | |
AntiLeakPoint | location | No | |
AntiLeakPoint2 | location | No | |
Boot | dialog | No | |
BootedPlayer | player | No | |
BootNo | button | No | |
BootVote | integer | No | |
BootVotePlayerButton | button | Yes | |
BootYes | button | No | |
Boss | unit | No | |
CanRepick | boolean | Yes | true |
Circle | unit | Yes | |
CircleIndex | integer | Yes | |
cscache | gamecache | No | |
Difficulty | integer | No | 2 |
DifficultyDialog | dialog | No | |
Done | button | No | |
Easy | button | No | |
Fast | boolean | No | |
FirstTimer | timer | No | |
GolemCount | integer | No | |
Hard | button | No | |
Kills | integer | Yes | |
Leaks | integer | Yes | |
Level | integer | No | 1 |
LevelType | unitcode | Yes | |
Lives | integer | No | 50 |
LivesDialog | dialog | No | |
Medium | button | No | |
Order | ordercode | No | |
Paused | boolean | No | |
Player | player | Yes | |
RandomNumber | integer | No | |
RemovedUnits | group | No | |
SubtractLives | button | No | |
SubtractLives_Super | button | No | |
UnitGroup | group | No | |
VeryEasy | button | No | |
VeryHard | button | No | |
Wagon | unit | No | UnitNull |
function OnAttackDamage_Child takes nothing returns nothing
local unit u = GetEventDamageSource()//I have already created
local unit u2 = GetTriggerUnit()//any variables that you may
local real r = GetEventDamage()//need to use for you
local real ang = Atan2( GetUnitY( u2 ) - GetUnitY( u ), GetUnitX( u2 ) - GetUnitX( u ) ) * bj_RADTODEG
local group g
local unit t
call DestroyBoolExpr( GetAttachedBoolExpr( GetTriggeringTrigger(), "b" ) )
call DestroyTrigger( GetAttachedTrigger( GetTriggeringTrigger(), "t" ) )
call CleanAttachedVars_NoSets( GetTriggeringTrigger() )
call DestroyTrigger( GetTriggeringTrigger() )
if GetUnitTypeId( u ) == 'h013' then//Harpy Witch
set t = CreateUnit( GetOwningPlayer( u ), 'n001', GetUnitX( u2 ), GetUnitY( u2 ), 0 )
call UnitDamageTarget( t, u2, GetUnitState( u, UNIT_STATE_MANA ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null )
set t = null
call TriggerSleepAction( .01 )
if GetUnitState( u2, UNIT_STATE_LIFE ) <= 0 then
call SetUnitState( u, UNIT_STATE_MANA, GetUnitState( u, UNIT_STATE_MANA ) + 4 )
else
call SetUnitState( u, UNIT_STATE_MANA, GetUnitState( u, UNIT_STATE_MANA ) - 1 )
endif
endif
if GetUnitTypeId( u ) == 'h01L' then//Mine Layer
call CreateUnit( GetOwningPlayer( u ), 'n01H', GetUnitX( u2 ), GetUnitY( u2 ), 0 )
endif
set u = null
set u2 = null
endfunction
function OnAttackDamage_isSamePlayer takes nothing returns boolean
return GetAttachedUnit( GetTriggeringTrigger(), "attack" ) == GetEventDamageSource()
endfunction
function OnAttackDamage_Cleanup takes nothing returns nothing
local trigger t = GetAttachedTrigger( GetTriggeringTrigger(), "t" )
call DestroyBoolExpr( GetAttachedBoolExpr( t, "b" ) )
call DestroyTrigger( t )
call CleanAttachedVars_NoSets( GetTriggeringTrigger() )
call DestroyTrigger( GetTriggeringTrigger() )
set t = null
endfunction
function OnAttackDamage_Antilag takes nothing returns boolean
return GetOwningPlayer( GetAttacker() ) != Player( 11 )
endfunction
function OnAttackDamage takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger t2 = CreateTrigger()
local boolexpr b = Condition( function OnAttackDamage_isSamePlayer )
call AttachObject( t, "t", t2 )
call AttachObject( t2, "t", t )
call AttachObject( t, "attack", GetAttacker() )
call AttachObject( t, "b", b )
call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
call TriggerAddCondition( t, b )
call TriggerAddAction( t, function OnAttackDamage_Child )
call TriggerRegisterUnitEvent( t2, GetAttacker(), EVENT_UNIT_ISSUED_ORDER )
call TriggerAddAction( t2, function OnAttackDamage_Cleanup )
set t = null
set t2 = null
endfunction
//===========================================================================
function InitTrig_OnAttackDamage takes nothing returns nothing
set gg_trg_OnAttackDamage = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_OnAttackDamage, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_OnAttackDamage, Condition( function OnAttackDamage_Antilag ) )
call TriggerAddAction( gg_trg_OnAttackDamage, function OnAttackDamage )
endfunction