- Joined
- Jul 26, 2008
- Messages
- 1,009
Hi.
I'm currently having an issue with my map and timer utils. (Or so I think it's Timer Utils, could just be Timers in general.)
It may be that I'm setting them up wrong, or it could be a script or system in my map. It may just be I don't have a necessary mechanic set up proper. I'm not sure at this point. I have the same systems in another map and have not had issues. The systems are: AutoIndex, Knockback by RisingDusk, GroupUtils, TerrainPathability, Table, BoundSentinel, LastOrder, XE 8.0, UnitProperties (Came after problem). Previously had CS16.0 but removed it.
There are a few of my spells that just bug up immediately and then it's all downhill from there. Sometimes it's random if the timer will work or not.
Anyone know why Timers or TimerUtils isn't working? I mean flat out not working, the Timer doesn't process past the create method. I figure there are people on this bored who know a lot more about TimerUtil bugs than I do.
I'll provide one of the spells that bugs often, and my Respawn system that bugs all the time.
I'll also attach my map for anyone who wishes to look through the systems to see if there's one that would conflict.
Help is always appreciated in these matters, thank you
Seems the problem is beyond me, as nothing I do fixes it.
Map wont' attach because it's already attached to this thread.
I'm currently having an issue with my map and timer utils. (Or so I think it's Timer Utils, could just be Timers in general.)
It may be that I'm setting them up wrong, or it could be a script or system in my map. It may just be I don't have a necessary mechanic set up proper. I'm not sure at this point. I have the same systems in another map and have not had issues. The systems are: AutoIndex, Knockback by RisingDusk, GroupUtils, TerrainPathability, Table, BoundSentinel, LastOrder, XE 8.0, UnitProperties (Came after problem). Previously had CS16.0 but removed it.
There are a few of my spells that just bug up immediately and then it's all downhill from there. Sometimes it's random if the timer will work or not.
Anyone know why Timers or TimerUtils isn't working? I mean flat out not working, the Timer doesn't process past the create method. I figure there are people on this bored who know a lot more about TimerUtil bugs than I do.
I'll provide one of the spells that bugs often, and my Respawn system that bugs all the time.
I'll also attach my map for anyone who wishes to look through the systems to see if there's one that would conflict.
Help is always appreciated in these matters, thank you
JASS:
scope Auspice initializer Init
globals
private constant integer SPELLID = 'refl'
endglobals
private struct Data
unit c
integer lvl
static method onLoop takes nothing returns nothing
local timer tim = GetExpiredTimer()
local thistype this = GetTimerData(tim)
call UnitModifyDamage(.c, -(2+R2I(0.5*.lvl)))
call ReleaseTimer(tim)
set .c = null
call this.destroy()
endmethod
static method create takes unit caster, integer level returns thistype
local thistype this = thistype.allocate()
local real tick = 2+1*level
local real dmg = 1.5+0.5*level
local timer tim = NewTimer()
set .c = caster
set .lvl = level
call UnitModifyDamage(.c, dmg)
call SetTimerData(tim, this)
call TimerStart(tim, tick, false, function thistype.onLoop)
return this
endmethod
endstruct
private function Conditions takes nothing returns boolean
if GetUnitAbilityLevel(GetAttacker(), SPELLID) > 0 then
call Data.create(GetAttacker(), GetUnitAbilityLevel(GetAttacker(), SPELLID))
endif
return false
endfunction
//===========================================================================
public function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( t, Condition( function Conditions ) )
endfunction
endscope
JASS:
scope DyingHeroWindowTimer initializer Init
globals
private real array X1
private real array Y1
private real array X2
private real array Y2
private constant string Title = "Respawn"
private constant integer NumbersRed = 255 //The Red amount in the Timer's Countdown numbers
private constant integer NumbersGreen = 0 //The Green
private constant integer NumbersBlue = 0 //The Blue
private constant integer NumbersTransparency = 255 //The Transparency (0 for invisible, 255 for solid)
private constant integer TitleRed = 150 //The Red amount in the Timer's Title
private constant integer TitleGreen = 75 //The Green
private constant integer TitleBlue = 25 //The Blue
private constant integer TitleTransparency = 200 //The Transparency
endglobals
private struct Data
unit d
timer tim
timerdialog timdia
static method Timer takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local string lol
local integer i = GetRandomInt(1,5)
local integer i2 = 0
local unit Bat
local real X
local real Y
if IsUnitInGroup(.d, udg_BloodPack) then
set X = X1[i]
set Y = Y1[i]
elseif IsUnitInGroup(.d, udg_FangSquad) then
set X = X2[i]
set Y = Y2[i]
else
set X = -11102
set Y = -7637
endif
if lives[GetPlayerId(GetOwningPlayer(.d))] <= 0 then
call DisplayTextToPlayer(GetOwningPlayer(.d), 0, 0, "Your last life has been wasted, and your vampire soul damned to hell for all eternity. However, feel free to stay and watch the game.")
call TimerDialogDisplay(.timdia, false)
set Bat = CreateUnit(GetOwningPlayer(.d), 'nshf', GetUnitX(.d), GetUnitY(.d), 270)
call SetUnitInvulnerable(Bat, true)
loop
exitwhen i2 == 13
if Player(i2) != GetOwningPlayer(.d) then
call UnitShareVision(Bat, Player(i2), false)
endif
set i2 = i2 + 1
endloop
else
call ReviveHero(.d, X, Y, false)
if GetUnitTypeId(.d) == 'GBaF' or GetUnitTypeId(.d) == 'OC91' then
if GetUnitAbilityLevel(.d, 'fbfl') > 0 then
call UnitAddAbility(.d, 'hunt')
call SetUnitAbilityLevel(.d, 'hunt', GetUnitAbilityLevel(.d, 'fbfl'))
endif
if GetUnitAbilityLevel(.d, 'frdr') > 0 then
call UnitAddAbility(.d, 'rend')
call SetUnitAbilityLevel(.d, 'rend', GetUnitAbilityLevel(.d, 'frdr'))
endif
endif
if (GetLocalPlayer() == GetOwningPlayer(.d)) then
call PanCameraTo( X, Y)
call TimerDialogDisplay(.timdia, false)
set lol = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"
call ClearSelection()
call SelectUnit(.d, true)
else
set lol = "Abilities\\Spells\\Human\\ReviveHuman\\ReviveHuman.mdl"
endif
call DestroyEffect(AddSpecialEffectTarget(lol, .d, "origin"))
endif
call DestroyTimerDialog(.timdia)
set lol = null
set Bat = null
call ReleaseTimer(.tim)
call .destroy()
endmethod
static method create takes unit died returns thistype
local real curLevel = GetHeroLevel(died)
local real dur = 3.8 + 1.2*curLevel
local integer i = 0
local string team
local thistype this = thistype.allocate()
set .tim = NewTimer()
set .d = died
set .timdia = CreateTimerDialog(.tim)
call TimerDialogSetTimeColor(.timdia, NumbersRed, NumbersGreen, NumbersBlue, NumbersTransparency)
call TimerDialogSetTitle(.timdia, Title)
call TimerDialogSetTitleColor(.timdia, TitleRed, TitleGreen, TitleBlue, TitleTransparency)
set lives[GetPlayerId(GetOwningPlayer(.d))] = lives[GetPlayerId(GetOwningPlayer(.d))] - 1
if IsUnitInGroup(.d, udg_BloodPack) then
set team = "Blood Pack"
elseif IsUnitInGroup(.d, udg_FangSquad) then
set team = "Fang Squad"
else
set team = "Rogue Vampires"
endif
loop
exitwhen i == 11
call DisplayTextToPlayer( Player(i), 0, 0, GetPlayerName(GetOwningPlayer(.d)) + " of the " + team + " has perished. It has " + I2S(lives[GetPlayerId(GetOwningPlayer(.d))]) + " lives left." )
set i = i + 1
endloop
if (GetLocalPlayer() == GetOwningPlayer(.d)) then
call TimerDialogDisplay(.timdia, true)
endif
call SetTimerData(.tim,this)
call TimerStart(.tim, dur, false, function thistype.Timer)
set team = null
return this
endmethod
static method Conditions takes nothing returns nothing
if IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true and IsUnitType(GetDyingUnit(), UNIT_TYPE_UNDEAD) == true and GetPlayerController(GetOwningPlayer(GetDyingUnit())) == MAP_CONTROL_USER and GetUnitTypeId(GetDyingUnit()) != 'UC63' then
call thistype.create(GetDyingUnit())
endif
endmethod
endstruct
//===========================================================================
public function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddAction(t, function Data.Conditions )
set X1[1] = -11072.
set X1[2] = -4500.
set X1[3] = -11114.
set X1[4] = -5350.
set X1[5] = -7950.
set Y1[1] = 9200.
set Y1[2] = 10500.
set Y1[3] = -975.
set Y1[4] = 2200.
set Y1[5] = -1150.
set X2[1] = -3856.
set Y2[1] = -11561.
set X2[2] = 0.
set Y2[2] = -11400.
set X2[3] = 8675.
set Y2[3] = -8750.
set X2[4] = -2750.
set Y2[4] = -7350.
set X2[5] = -11111.
set Y2[5] = -10000.
set t = null
endfunction
endscope
JASS:
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+)
//* ----------
//*
//* 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.wc3c.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.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = true
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
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, make sure all timers are getting recycled correctly")
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
set tT[0]=CreateTimer()
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
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==ARRAY_SIZE) 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 init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
Map wont' attach because it's already attached to this thread.
Last edited: