Name | Type | is_array | initial_value |
//TESH.scrollpos=36
//TESH.alwaysfold=0
library_once TimerUtils initializer redInit
//*********************************************************************
//* TimerUtils (Red flavor)
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3campaigns.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Red flavor: Fastest, method in existence for timer attaching,
//* only takes an array lookup, H2I and subtraction.
//* However, all the code in your map requires extra care
//* not to forget to call ReleaseTimer. It also requires
//* to preload a lot of timers at map init, they use
//* memory and handle ids.
//*
//* I recommend you run your map in debug mode the first
//* time after adding it, make sure you can see map init messages
//* if nothing appears, all is done, if an error appears, it might
//* suggest you a value with OFFSET, in that case, update that value
//* if it still does not work after updating (rare), try a bigger
//* OFFSET by 1000 for example. (Sounds hard? Then use blue or purple
//* timerutils that are friendlier though not as fast)
//*
//********************************************************************
//================================================================
globals
private constant integer OFFSET = 0x100000
private constant integer QUANTITY = 256
private constant integer ARRAY_SIZE = 8191 //changing this to a higher value would effectively
//cripple the performance making this thing irrelevant
endglobals
//=================================================================================================
private function H2I takes handle h returns integer
return GetHandleId( h )
endfunction
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
debug if(H2I(t)-OFFSET<0) then
debug call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
debug endif
set data[H2I(t)-OFFSET]=value
endfunction
function GetTimerData takes timer t returns integer
debug if(H2I(t)-OFFSET<0) then
debug call BJDebugMsg("GetTimerData: Wrong handle id, only use GetTimerData on timers created by NewTimer")
debug endif
return data[H2I(t)-OFFSET]
endfunction
//==========================================================================================
globals
private timer array tT
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
endglobals
//==========================================================================================
function NewTimer takes nothing returns timer
if (tN==0) then
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, please increase it for your map, fix your map's timer leaks or switch to blue flavor when applicable")
set tT[0]=CreateTimer()
if (H2I(tT[0])-OFFSET<0) or (H2I(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably switch to the blue flavor or fix timer leaks.")
return null
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],0)
return tT[tN]
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==8191) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function redInit takes nothing returns nothing
local integer i=0
local integer bestoffset=-1
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set bestoffset=H2I(tT[i])
endif
if (H2I(tT[i])-OFFSET>=ARRAY_SIZE) then
debug call BJDebugMsg("TimerUtils_redInit: Failed a initializing attempt")
debug call BJDebugMsg("The timer limit is "+I2S(i))
debug call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low, to change OFFSET to "+I2S(bestoffset) )
exitwhen true
endif
if (H2I(tT[i])-OFFSET>=0) then
set i=i+1
endif
endloop
set tN=i
endfunction
endlibrary
//TESH.scrollpos=44
//TESH.alwaysfold=0
library BoundSentinel initializer init
//*************************************************
//* BoundSentinel
//* -------------
//* Don't leave your units unsupervised, naughty
//* them may try to get out of the map bounds and
//* crash your game.
//*
//* To implement, just get a vJass compiler and
//* copy this library/trigger to your map.
//*
//*************************************************
//==================================================
globals
// High enough so the unit is no longer visible, low enough so the
// game doesn't crash...
//
// I think you need 0.0 or soemthing negative prior to patch 1.22
//
private constant real EXTRA = 500.0
endglobals
//=========================================================================================
globals
private real maxx
private real maxy
private real minx
private real miny
endglobals
//=======================================================================
private function dis takes nothing returns nothing
local unit u=GetTriggerUnit()
local real x=GetUnitX(u)
local real y=GetUnitY(u)
if(x>maxx) then
set x=maxx
elseif(x<minx) then
set x=minx
endif
if(y>maxy) then
set y=maxy
elseif(y<miny) then
set y=miny
endif
call SetUnitX(u,x)
call SetUnitY(u,y)
set u=null
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local region r=CreateRegion()
local rect rc
set minx=GetCameraBoundMinX() - EXTRA
set miny=GetCameraBoundMinY() - EXTRA
set maxx=GetCameraBoundMaxX() + EXTRA
set maxy=GetCameraBoundMaxY() + EXTRA
set rc=Rect(minx,miny,maxx,maxy)
call RegionAddRect(r, rc)
call RemoveRect(rc)
call TriggerRegisterLeaveRegion(t,r, null)
call TriggerAddAction(t, function dis)
//this is not necessary but I'll do it anyway:
set t=null
set r=null
set rc=null
endfunction
endlibrary
//TESH.scrollpos=21
//TESH.alwaysfold=0
library IsTerrainWalkable initializer Init
//*****************************************************************
//* IsTerrainWalkable
//*
//* rewritten in vJass by: Anitarf
//* original implementation: Vexorian
//*
//* A function for checking if a point is pathable for ground
//* units (it does so by attempting to move an item there and
//* checking where it ended up), typically used to stop sliding
//* units before they end up stuck in trees. If the point is not
//* pathable, the function will also determine the nearest point
//* that is (the point where the item ends up).
//*****************************************************************
globals
// this value is how far from a point the item may end up for the point to be considered pathable
private constant real MAX_RANGE = 10.0
// the following two variables are set to the position of the item after each pathing check
// that way, if a point isn't pathable, these will be the coordinates of the nearest point that is
public real X = 0.0
public real Y = 0.0
// END OF CALIBRATION SECTION
// ================================================================
private rect r
private item check
private item array hidden
private integer hiddenMax = 0
endglobals
private function Init takes nothing returns nothing
set check = CreateItem('ciri',0,0)
call SetItemVisible(check,false)
set r = Rect(0.0,0.0,128.0,128.0)
endfunction
private function HideBothersomeItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set hidden[hiddenMax]=GetEnumItem()
call SetItemVisible(hidden[hiddenMax],false)
set hiddenMax=hiddenMax+1
endif
endfunction
// ================================================================
function IsTerrainWalkable takes real x, real y returns boolean
// first, hide any items in the area so they don't get in the way of our item
call MoveRectTo(r, x,y)
call EnumItemsInRect(r,null,function HideBothersomeItem)
// try to move the check item and get it's coordinates
call SetItemPosition(check,x,y)//this unhides the item...
set X = GetItemX(check)
set Y = GetItemY(check)
call SetItemVisible(check,false)//...so we must hide it again
// before returning, unhide any items that got hidden at the start
loop
exitwhen hiddenMax<=0
set hiddenMax=hiddenMax-1
call SetItemVisible(hidden[hiddenMax],true)
set hidden[hiddenMax]=null
endloop
// return pathability status
return (x-X)*(x-X)+(y-Y)*(y-Y) < MAX_RANGE*MAX_RANGE
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope ShadowShot initializer init
//*************************************************************************************************************//
// Shadow Shot v0.02 //
// by //
// cedi //
// //
// needs: TimerUtils by Vexorian //
// Bound Sentinel by Vexorian //
// Dummy Model by //
// IsTerrainWalkable by Antiarf //
// //
//*************************************************************************************************************//
//For use, copy the trigger to your map, copy the dummy create a spell and adjust the values below.
private keyword Main
private keyword Sub
private keyword Arrow
globals
//ID of the spell
private constant integer SPELL_ID = 'A000'
//ID of your dummy
private constant integer DUMMY_ID = 'h000'
//Interval of the moves
private constant real TIMER_INTERVAL = 0.035
//Shooters
//Color in rgb
private constant integer S_COLOR_RED = 255
private constant integer S_COLOR_GREEN = 255
private constant integer S_COLOR_BLUE = 255
//Alpha color reached befor shot.
private constant integer S_COLOR_ALPHA = 125
//Time the units need to appear.
private constant real SHOW_TIME = 1.00
//Time the units need to disappear.
private constant real HIDE_TIME = 1.00
//Time of the attack animation.
private constant real ANIMATION_TIME = 0.70
//Size of the units
private constant real SHOOTER_SIZE = 1.00
//Z-start of the missiles
private constant real SHOOTER_MISSILE_Z = 60.00
//Place a unit needs
private constant real SHOOTER_COL = 100.00
//Max angle the units can have
private constant real SHOOTER_ANGLE = 45.00
//Animation string
private constant string ANIMATION = "attack"
//Missile
//Color in rgb
private constant integer M_COLOR_RED = 255
private constant integer M_COLOR_GREEN = 255
private constant integer M_COLOR_BLUE = 255
private constant integer M_COLOR_ALPHA = 125
//Pick units in each
private constant integer PICK_EACH_X_TIMES = 3
//Speed of the arrows in wc3 units
private constant real SPEED = 600.00
//Size of the missile
private constant real MISSILE_SIZE = 1.00
//Model of the missile
private constant string MODEL = "Abilities\\Weapons\\Arrow\\ArrowMissile.mdl"
//SFX on damage
private constant string DAMAGE_SFX = "Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodFootman.mdl"
//Additionall model
private constant string ADD_MODEL = "Abilities\\Weapons\\AvengerMissile\\AvengerMissile.mdl"
//Should the missile disappear on collision with doodads cliff ...
private constant boolean IS_COLLISION = false
//System
private Main TEMPMAIN
private Sub TEMPSUB
private Arrow TEMPARROW
private group TEMPGROUP = CreateGroup()
private hashtable HASH = InitHashtable()
endglobals
private function HIT_FUNC takes Arrow arrow, unit target returns nothing
//Do your uber crazy things, like knockback, dot, slow ...
endfunction
private function DAMAGE takes integer level returns real
return 100.00 + 50 * level
endfunction
private function AOE takes integer level returns real
return 55.00 + 5 * level
endfunction
//*************************************************************************************************************//
// !SYSTEM! //
//*************************************************************************************************************//
private function AngleBetweenCoordinates takes real x1, real x2, real y1, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
private function DistanceBetweenCoordinates takes real x1, real x2, real y1, real y2 returns real
local real dx = x2 - x1
local real dy = y2 - y1
return SquareRoot(dx * dx + dy * dy)
endfunction
private function IsAliveAndUnitAndNotMagicImmune takes nothing returns boolean
return GetWidgetLife( GetFilterUnit() ) > 0.405 and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false
endfunction
private function OuterControl takes nothing returns nothing
set TEMPMAIN = GetTimerData( GetExpiredTimer() )
call TEMPMAIN.control()
endfunction
private function A_OuterControl takes nothing returns nothing
set TEMPARROW = GetTimerData( GetExpiredTimer() )
call TEMPARROW.control()
endfunction
private struct Arrow
unit u = null
unit caster = null
effect model = null
effect sfx = null
group g = null
real range = 0.00
real dist = 0.00
real vx = 0.00
real vy = 0.00
real alpha = M_COLOR_ALPHA
real alphalose = 0.00
integer level = 1
integer times = 0
timer t = null
boolean vanish = false
method onDestroy takes nothing returns nothing
call ReleaseTimer( .t )
set .t = null
call DestroyEffect( .model )
call DestroyEffect( .sfx )
set .model = null
set .sfx = null
call KillUnit( .u )
set .u = null
call GroupClear( .g )
call DestroyGroup( .g )
set .g = null
endmethod
method dealDamage takes unit u returns nothing
call DestroyEffect( AddSpecialEffectTarget( DAMAGE_SFX, u, "chest" ) )
if .vanish then
call UnitDamageTarget( .caster, u, DAMAGE( .level ) * .alpha / M_COLOR_ALPHA, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null )
else
call UnitDamageTarget( .caster, u, DAMAGE( .level ), true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null )
endif
call HIT_FUNC( this, u )
endmethod
method control takes nothing returns nothing
local real x = GetUnitX( .u ) + .vx
local real y = GetUnitY( .u ) + .vy
local unit u
if GetWidgetLife( .u ) <= 0.405 then
call .destroy()
endif
if not .vanish then
set .dist = .dist - SPEED * TIMER_INTERVAL
if .dist <= 0.00 then
set .vanish = true
endif
endif
if .vanish then
set .alpha = .alpha - .alphalose
call SetUnitVertexColor( .u, M_COLOR_RED, M_COLOR_GREEN, M_COLOR_GREEN, R2I( .alpha + 0.5 ) )
endif
set .range = .range - SPEED * TIMER_INTERVAL
call SetUnitX( .u, x )
call SetUnitY( .u, y )
if IS_COLLISION then
if not IsTerrainWalkable( x, y ) then
call .destroy()
endif
endif
set .times = .times + 1
if .times >= PICK_EACH_X_TIMES then
set .times = 0
call GroupEnumUnitsInRange( TEMPGROUP, x, y, AOE( .level ), Condition( function IsAliveAndUnitAndNotMagicImmune ) )
loop
set u = FirstOfGroup( TEMPGROUP )
exitwhen u == null
if IsUnitEnemy( u, GetOwningPlayer( .caster ) ) then
if not IsUnitInGroup( u, .g ) then
call .dealDamage( u )
call GroupAddUnit( .g, u )
endif
endif
call GroupRemoveUnit( TEMPGROUP, u )
set u = null
endloop
endif
if .range <= 0.00 then
call .destroy()
endif
endmethod
static method create takes Main root, real x, real y, real angle returns thistype
local thistype this = thistype.allocate()
set .caster = root.caster
set .g = CreateGroup()
set .range = root.distance * 2.00
set .level = root.level
set .dist = root.distance
set .vx = Cos( angle * bj_DEGTORAD ) * SPEED * TIMER_INTERVAL
set .vy = Sin( angle * bj_DEGTORAD ) * SPEED * TIMER_INTERVAL
set .u = CreateUnit( GetOwningPlayer( .caster ), DUMMY_ID, x, y, angle )
set .model = AddSpecialEffectTarget( MODEL, .u, "origin" )
set .sfx = AddSpecialEffectTarget( ADD_MODEL, .u, "origin" )
set .alphalose = M_COLOR_ALPHA * TIMER_INTERVAL / ( .dist / ( SPEED * TIMER_INTERVAL ) )
call SetUnitFlyHeight( .u, SHOOTER_MISSILE_Z, 0 )
call SetUnitScale( .u, MISSILE_SIZE, MISSILE_SIZE, MISSILE_SIZE )
call SetUnitVertexColor( .u, S_COLOR_RED, S_COLOR_GREEN, S_COLOR_BLUE, S_COLOR_ALPHA )
set .t = NewTimer()
call SetTimerData( .t, this )
call TimerStart( .t, TIMER_INTERVAL, true, function A_OuterControl )
return this
endmethod
endstruct
private struct Sub
unit u = null
real angle = 0.00
Main root = 0
method onDestroy takes nothing returns nothing
call KillUnit( .u )
call RemoveUnit( .u )
set .u = null
endmethod
method shot takes nothing returns nothing
call Arrow.create( .root, GetUnitX( .u ), GetUnitY( .u ), .angle )
endmethod
method attack takes nothing returns nothing
call SetUnitAnimation( .u, ANIMATION )
endmethod
method adjustAlpha takes nothing returns nothing
call SetUnitVertexColor( .u, S_COLOR_RED, S_COLOR_GREEN, S_COLOR_BLUE, R2I( .root.alpha + 0.5 ) )
endmethod
static method create takes Main root, real angle returns thistype
local thistype this = thistype.allocate()
local real x = root.x + Cos( angle * bj_DEGTORAD ) * root.distance
local real y = root.y + Sin( angle * bj_DEGTORAD ) * root.distance
set .root = root
set .angle = angle + 180.00
set .u = CreateUnit( Player( 12 ), GetUnitTypeId( root.caster ), x, y, .angle )
call SetUnitColor( .u, GetPlayerColor( GetOwningPlayer( root.caster ) ) )
call SetUnitScale( .u, SHOOTER_SIZE, SHOOTER_SIZE, SHOOTER_SIZE )
call SetUnitVertexColor( .u, S_COLOR_RED, S_COLOR_GREEN, S_COLOR_BLUE, R2I( root.alpha ) )
call SetUnitPathing( .u, false )
call SetUnitX( .u, x )
call SetUnitY( .u, y )
call UnitAddAbility( .u, 'Aloc' )
call PauseUnit( .u, true )
return this
endmethod
endstruct
private struct Main
unit caster = null
integer shooter = 0
real alpha = 0
integer level = 1
real time = 0.00
real x = 0.00
real y = 0.00
real distance = 0.00
timer t = null
boolean show = true
boolean shot = false
boolean hide = false
method control takes nothing returns nothing
local real r
local integer i
//SHOW
if .show then
set r = S_COLOR_ALPHA * TIMER_INTERVAL / SHOW_TIME
set .alpha = .alpha + r
set .time = .time - TIMER_INTERVAL
set i = 0
loop
exitwhen i > .shooter
set TEMPSUB = LoadInteger( HASH, this, i )
call TEMPSUB.adjustAlpha()
set i = i + 1
endloop
if .time <= 0.00 then
set .show = false
set .shot = true
set .time = ANIMATION_TIME
set i = 0
loop
exitwhen i > .shooter
set TEMPSUB = LoadInteger( HASH, this, i )
call TEMPSUB.attack()
set i = i + 1
endloop
endif
return
endif
//ATTACK
if .shot then
set .time = .time - TIMER_INTERVAL
if .time <= 0.00 then
set i = 0
set .shot = false
set .hide = true
set .time = HIDE_TIME
loop
exitwhen i > .shooter
set TEMPSUB = LoadInteger( HASH, this, i )
call TEMPSUB.shot()
set i = i + 1
endloop
endif
return
endif
//HIDE
if .hide then
set r = S_COLOR_ALPHA * TIMER_INTERVAL / SHOW_TIME
set .alpha = .alpha - r
set .time = .time - TIMER_INTERVAL
set i = 0
loop
exitwhen i > .shooter
set TEMPSUB = LoadInteger( HASH, this, i )
call TEMPSUB.adjustAlpha()
set i = i + 1
endloop
if .time <= 0.00 then
call .destroy()
endif
endif
endmethod
method onDestroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i > .shooter
set TEMPSUB = LoadInteger( HASH, this, i )
call TEMPSUB.destroy()
set i = i + 1
endloop
call FlushChildHashtable( HASH, this )
set .caster = null
call ReleaseTimer( .t )
set .t = null
endmethod
static method create takes unit caster, real x, real y returns thistype
local thistype this = thistype.allocate()
local real distance = DistanceBetweenCoordinates( GetUnitX( caster ), x, GetUnitY( caster ), y )
local real bogen = 2 * bj_PI * distance * ( SHOOTER_ANGLE * 2.00 ) / 360.00
local integer count = R2I( bogen / SHOOTER_COL + 0.5 )
local real angle = AngleBetweenCoordinates( GetUnitX( caster ), x, GetUnitY( caster ), y )
local real r = 0.00
local integer i = 0
set bogen = SHOOTER_ANGLE * 2 / count
set .caster = caster
set .shooter = count
set .level = GetUnitAbilityLevel( caster, SPELL_ID )
set .time = SHOW_TIME
set .alpha = 0
set .x = x
set .y = y
set .t = NewTimer()
set .distance = distance
call SetTimerData( .t, this )
set r = ( angle + 180.00 ) - SHOOTER_ANGLE
loop
exitwhen i > count
set TEMPSUB = Sub.create( this, r )
call SaveInteger( HASH, this, i, TEMPSUB )
set r = r + bogen
set i = i + 1
endloop
call TimerStart( .t, TIMER_INTERVAL, true, function OuterControl )
return this
endmethod
endstruct
private function IsSpell takes nothing returns nothing
if GetSpellAbilityId() == SPELL_ID then
call Main.create( GetTriggerUnit(), GetSpellTargetX(), GetSpellTargetY() )
endif
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( t, function IsSpell )
set t = null
endfunction
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Revive_Units_Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false
endfunction
function Trig_Revive_Units_Actions takes nothing returns nothing
if GetUnitTypeId( GetTriggerUnit() ) == 'h000' then
return
endif
call TriggerSleepAction( 10.00 )
call CreateUnit( GetOwningPlayer( GetTriggerUnit() ), GetUnitTypeId( GetTriggerUnit() ), GetUnitX( GetTriggerUnit() ), GetUnitY( GetTriggerUnit() ), GetUnitFacing( GetTriggerUnit() ) )
endfunction
//===========================================================================
function InitTrig_Revive_Units takes nothing returns nothing
set gg_trg_Revive_Units = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Revive_Units, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Revive_Units, Condition( function Trig_Revive_Units_Conditions ) )
call TriggerAddAction( gg_trg_Revive_Units, function Trig_Revive_Units_Actions )
endfunction