Rheiko
Spell Reviewer
- Joined
- Aug 27, 2013
- Messages
- 4,243
RFS_OnFinishEvent Equals to 1.00
event.//===========================================================================
//=
//= Rheiko Fear System / RFS
//= version 1.0.2
//=
//= Description:
//= A very lightweight system that allows you to inflict and remove fear effect on a unit
//=
//= GUI user, please scroll down and check configuration right away!
//=
//= These are APIs for JASS users:
//=
//= function Trig_RFS_ApplyFear takes unit whichUnit, real duration, boolean stackable, string sfxModel, string attachPoint returns nothing
//= - Inflict fear on a unit
//=
//= function Trig_RFS_RemoveFear takes unit u returns nothing
//= - Remove fear from a unit
//=
//= function Trig_RFS_IsUnitInFear takes unit u returns boolean
//= - Check if a unit is in fear
//=
//===========================================================================
function Trig_RFS_Configurations takes nothing returns nothing
//===========================================================================
// CONFIGURATION
//===========================================================================
//-----------------------------------------------------------------------
//-- This will show debug messages if you set it to true
//-----------------------------------------------------------------------
set udg_RFS_Debug = false
//-----------------------------------------------------------------------
//-- This is the maximum distance offset
//-- the unit will be ordered to move to
//-- periodically
//-----------------------------------------------------------------------
set udg_RFS_MaxDistance = 200.0
//-----------------------------------------------------------------------
//-- This is the special effect attached on the affected unit
//-- Since this is written in JASS, the file path must use double "\"
//-- So please do not forget that
//-----------------------------------------------------------------------
set udg_RFS_SfxModelDefault = "Abilities\\Spells\\Other\\HowlOfTerror\\HowlTarget.mdl"
//-----------------------------------------------------------------------
//-- This is the attachment point for the special effect
//-- For example: chest, hand right, hand left, origin, etc
//-----------------------------------------------------------------------
set udg_RFS_AttachPointDefault = "chest"
//-----------------------------------------------------------------------
//-- This is how often the unit will be
//-- ordered to move around when affected
//-----------------------------------------------------------------------
set udg_RFS_Timeout = 0.4
//===========================================================================
// END OF CONFIG
//===========================================================================
endfunction
function Trig_RFS_IsUnitInFear takes unit u returns boolean
local integer uId = GetHandleId(u)
//-- Load unit's current flag (IsUnitFeared)
local integer flag = LoadInteger(udg_RFS_Table, uId, 0)
if flag == 1 then
return true
else
return false
endif
endfunction
function Trig_RFS_CheckFear_Actions takes nothing returns boolean
set udg_RFS_IsUnitInFear = Trig_RFS_IsUnitInFear(udg_RFS_Param_Unit)
return false
endfunction
function Trig_RFS_RemoveFear takes unit u returns nothing
//-- Get unit's handle id
local integer uId = GetHandleId(u)
//-- Get the special effect
local effect e = LoadEffectHandle(udg_RFS_Table, uId, 2)
//-- Destroy the special effect
call DestroyEffect(e)
//-- CLean up hashtable
call FlushChildHashtable(udg_RFS_Table, uId)
//-- Order the affected unit to stop
call IssueImmediateOrderById(u, 851972)
//-- Debug
if udg_RFS_Debug == true then
call BJDebugMsg("[|cffffcc00System|r] - " + "Fear is successfully removed")
endif
set e = null
endfunction
function Trig_RFS_Death_Actions takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer uId = GetHandleId(u)
//-- Load unit's current flag (IsUnitFeared)
local integer flag = LoadInteger(udg_RFS_Table, uId, 0)
if flag == 0 then
set u = null
return false
endif
set udg_RFS_LastFinishedUnit = u
set udg_RFS_OnFinishEvent = 1.00
set udg_RFS_OnFinishEvent = 0.00
call Trig_RFS_RemoveFear(u)
set u = null
return false
endfunction
function Trig_RFS_Order_Actions takes nothing returns boolean
//-- Local variables
local real x
local real y
//-- GetIssuedOrderId
local integer oId
//-- Get the unit and its id
local unit u = GetOrderedUnit()
local integer uId = GetHandleId(u)
//-- Load unit's current flag (IsTerrified)
local integer isTerrified = LoadInteger(udg_RFS_Table, uId, 0)
if isTerrified == 0 then
set u = null
return false
endif
set oId = GetIssuedOrderId()
if oId == 851973 then
set u = null
return false
endif
call DisableTrigger(GetTriggeringTrigger())
//-- Load coordinates
set x = LoadReal(udg_RFS_Table, uId, 3)
set y = LoadReal(udg_RFS_Table, uId, 4)
//-- Order unit to move
call IssuePointOrderById(u, 851986, x, y)
call EnableTrigger(GetTriggeringTrigger())
//-- Debug
if udg_RFS_Debug == true then
call BJDebugMsg("[|cffffcc00System|r] - " + "Order is successfully prevented")
endif
set u = null
return false
endfunction
function Trig_RFS_Timer_Actions takes nothing returns nothing
//-- Local variables
local real x1
local real y1
local real x2
local real y2
//-- Get expired timer
local timer t = GetExpiredTimer()
//-- Get its handle id
local integer tId = GetHandleId(t)
//-- Load unit
local unit u = LoadUnitHandle(udg_RFS_Table, tId, 0)
//-- Get unit's handle id
local integer uId = GetHandleId(u)
//-- Load unit's current flag (IsUnitFeared)
local integer flag = LoadInteger(udg_RFS_Table, uId, 0)
//-- Get unit's fear duration
local real duration = LoadReal(udg_RFS_Table, uId, 1)
if duration > 0 and flag == 1 then
//-- Decrease duration
set duration = duration - udg_RFS_Timeout
//-- Get unit's coor
set x1 = GetUnitX(u)
set y1 = GetUnitY(u)
//-- Give new order
set x2 = GetRandomReal(x1 - udg_RFS_MaxDistance, x1 + udg_RFS_MaxDistance)
set y2 = GetRandomReal(y1 - udg_RFS_MaxDistance, y1 + udg_RFS_MaxDistance)
call IssuePointOrderById(u, 851986, x2, y2)
//-- Update coordinates
call SaveReal(udg_RFS_Table, uId, 3, x2)
call SaveReal(udg_RFS_Table, uId, 4, y2)
//-- Update duration
call SaveReal(udg_RFS_Table, uId, 1, duration)
else
//-- Remove the fear effect
if duration <= 0 and flag == 1 then
set udg_RFS_LastFinishedUnit = u
set udg_RFS_OnFinishEvent = 1.00
set udg_RFS_OnFinishEvent = 0.00
call Trig_RFS_RemoveFear(u)
endif
//-- Clean up hashtable
call FlushChildHashtable(udg_RFS_Table, tId)
//-- Destroy the timer
call DestroyTimer(t)
//-- Debug
if udg_RFS_Debug == true then
call BJDebugMsg("[|cffffcc00System|r] - " + "Timer is successfully destroyed")
endif
endif
set u = null
set t = null
endfunction
function Trig_RFS_RemoveFear_Actions takes nothing returns boolean
local unit u = udg_RFS_Param_Unit
call Trig_RFS_RemoveFear(u)
set u = null
return false
endfunction
function Trig_RFS_ApplyFear takes unit whichUnit, real duration, boolean stackable, string sfxModel, string attachPoint returns nothing
//-- Local variables
local real x1
local real y1
local real x2
local real y2
local timer t
local integer tId
//-- Get target's handle id
local integer uId = GetHandleId(whichUnit)
//-- Load unit's current flag (IsUnitFeared)
local integer flag = LoadInteger(udg_RFS_Table, uId, 0)
//-- Load unit's current duration
local real d = LoadReal(udg_RFS_Table, uId, 1)
//-- Load effect handle
local effect e = LoadEffectHandle(udg_RFS_Table, uId, 2)
//-- Check if stackable
if stackable == true then
set d = d + duration
else
if duration > d then
set d = duration
endif
endif
//-- Update duration
call SaveReal(udg_RFS_Table, uId, 1, d)
//-- Make sure to destroy previous effect if it exists
call DestroyEffect(e)
//-- Create a new special effect on the unit
if sfxModel == "" then
set sfxModel = udg_RFS_SfxModelDefault
endif
if attachPoint == "" then
set attachPoint = udg_RFS_AttachPointDefault
endif
set e = AddSpecialEffectTarget(sfxModel, whichUnit, attachPoint)
//-- Save the effect handle
call SaveEffectHandle(udg_RFS_Table, uId, 2, e)
//-- Check if unit is already in fear
if flag == 1 then
if udg_RFS_Debug == true then
call BJDebugMsg("[|cffffcc00System|r] - " + "Fear is reapplied")
endif
set t = null
set e = null
return
endif
//-- Get unit's coor
set x1 = GetUnitX(whichUnit)
set y1 = GetUnitY(whichUnit)
//-- Order them to move around
set x2 = GetRandomReal(x1 - udg_RFS_MaxDistance, x1 + udg_RFS_MaxDistance)
set y2 = GetRandomReal(y1 - udg_RFS_MaxDistance, y1 + udg_RFS_MaxDistance)
call IssuePointOrderById(whichUnit, 851986, x2, y2)
//-- Save coordinates
call SaveReal(udg_RFS_Table, uId, 3, x2)
call SaveReal(udg_RFS_Table, uId, 4, y2)
//-- Update unit's flag to mark them feared
call SaveInteger(udg_RFS_Table, uId, 0, 1)
//-- Create and start a timer
set t = CreateTimer()
call TimerStart(t, udg_RFS_Timeout, true, function Trig_RFS_Timer_Actions)
//-- Save the timer and attach unit's id to it
set tId = GetHandleId(t)
call SaveUnitHandle(udg_RFS_Table, tId, 0, whichUnit)
//-- Debug
if udg_RFS_Debug == true then
call BJDebugMsg("[|cffffcc00System|r] - " + "Fear is applied")
endif
set t = null
set e = null
endfunction
function Trig_RFS_ApplyFear_Actions takes nothing returns boolean
//-- Assign locals for easy function call
local unit u = udg_RFS_Param_Unit
local real d = udg_RFS_Param_Duration
local boolean b = udg_RFS_Param_Stackable
local string m = udg_RFS_Param_SfxModel
local string a = udg_RFS_Param_AttachPoint
//-- Apply fear
call Trig_RFS_ApplyFear(u, d, b, m, a)
//-- Reset the parameters
set udg_RFS_Param_Unit = null
set udg_RFS_Param_Duration = 0.0
set udg_RFS_Param_Stackable = false
set udg_RFS_Param_SfxModel = ""
set udg_RFS_Param_AttachPoint = ""
set u = null
return false
endfunction
//===========================================================================
function InitTrig_RFS takes nothing returns nothing
local integer i = 0
//-- Create triggers to handle unit's order and death
local trigger orderTrg = CreateTrigger()
local trigger deathTrg = CreateTrigger()
//-- Create triggers to apply and remove fear effect
set udg_RFS_ApplyFear = CreateTrigger()
set udg_RFS_RemoveFear = CreateTrigger()
set udg_RFS_CheckFear = CreateTrigger()
//-- Attach functions to each trigger
call TriggerAddCondition(orderTrg, Condition(function Trig_RFS_Order_Actions))
call TriggerAddCondition(deathTrg, Condition(function Trig_RFS_Death_Actions))
call TriggerAddCondition(udg_RFS_ApplyFear, Condition(function Trig_RFS_ApplyFear_Actions))
call TriggerAddCondition(udg_RFS_RemoveFear, Condition(function Trig_RFS_RemoveFear_Actions))
call TriggerAddCondition(udg_RFS_CheckFear, Condition(function Trig_RFS_CheckFear_Actions))
loop
//-- Order events
call TriggerRegisterPlayerUnitEvent(orderTrg, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
call TriggerRegisterPlayerUnitEvent(orderTrg, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
call TriggerRegisterPlayerUnitEvent(orderTrg, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
//-- Death event
call TriggerRegisterPlayerUnitEvent(deathTrg, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
//-- Initialize a hashtable
//-- Map:
//-- 0 = Fear Flag
//-- 1 = Fear Duration
//-- 2 = Special Effect
//-- 3 = CoorX
//-- 4 = CoorY
//-- TimerId = UnitId
set udg_RFS_Table = InitHashtable()
//-- Run Config
call Trig_RFS_Configurations()
set orderTrg = null
set deathTrg = null
endfunction