- Joined
- May 25, 2009
- Messages
- 100
I created a Cone-of-Vision-system and used hashtables for everything, but because it looked ugly and i didn't want to look up every time, which Childkey stores which Variable, i created some structs and used the Tipp PurgeandFire gave me. LINK
My Problem is now, that some Timers just don't start.
The Problem is, that the timer "newt" doesn't start in the function "lis_isinsight". I get both DebugMsg (The HandleIDs are the same).
It doesn't matter whats in function "lis_collisioncheck"...Even if it's just one "call BJDebugMsg("test")" i don't get it.
And the strange thing is, that the timer "t" in "Trig_stealthini_Actions" starts the function "lis_isinsight" without problems...and there is not a big difference between these two timers, is there?
Maybe i just missed something really obvious and my brain is just to tired.
I hope you can help me
thx in advance!
PS: I don't have to create a new globalunitstruct in "Trig_stealthini_Actions" 'cause they are already created before for every unit ...but i think that the whole globalunitstruct is not the problem anyway, but the globaltimerstruct.
PSS: I know that the code is not 100% optimized
My Problem is now, that some Timers just don't start.
JASS:
function lis_isinsight takes nothing returns nothing
local globaltimerstruct timerstruct = globaltimerstruct[GetExpiredTimer()] // Get Expired Timer for the HandleId
local globaltimerstruct newtimerstruct = globaltimerstruct.create(CreateTimer())
local globalunitstruct unitstruct=globalunitstruct[timerstruct.COV_THISUNIT] // Create a New Timer for the Collisioncheck
local unit stunit = timerstruct.COV_THISUNIT
local timer t = timerstruct.THISTIMER
local timer newt = newtimerstruct.THISTIMER
local unit dummy // Dummy which will check the collision
local real heroposx = GetUnitX(hero) //X-Coordinate of Hero
local real heroposy = GetUnitY(hero) //Y-Coordinate of Hero
local real stunitposx = GetUnitX(stunit) //X-Coordinate of unit
local real stunitposy = GetUnitY(stunit) //Y-Coordinate of unit
// Distance between Hero and unit
local real distance = SquareRoot(((stunitposx-heroposx)*(stunitposx-heroposx))+((stunitposy-heroposy)*(stunitposy-heroposy)))
//call BJDebugMsg(I2S(GetHandleId(newt)))
// If Distance between Hero and Unit is over 735 then destroy the Effect (if created) and end check
if distance > 735 then
call BJDebugMsg("distance to high")
call PauseTimer(t)
call DestroyTimer(t)
set unitstruct.COV_TICK=0.00
if unitstruct.COV_SPECIALEFFECTBOOL then
call DestroyEffect(unitstruct.COV_EFFECT)
set unitstruct.COV_SPECIALEFFECTBOOL=false
endif
endif
//If Hero is in cone of Vision and Unit is alive
if lis_isincone(stunit) and IsUnitAlive.evaluate(stunit) then
// Stop current Timer and flushChild
call PauseTimer(t)
call DestroyTimer(t)
// Create Dummy
set dummy = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),'e000',stunitposx,stunitposy,0)
set unitstruct.COV_CROUCHBOOL=FALSE //Set Hero doesn't have to duck
//Save the unit, dummy and range to new HandleID
set newtimerstruct.COV_THISUNIT=stunit
set newtimerstruct.COV_DUMMYUNIT=dummy
set unitstruct.COV_RANGE=0
call newtimerstruct.save()
// Start Timer
call BJDebugMsg(I2S(GetHandleId(newtimerstruct.THISTIMER)))
call TimerStart(newtimerstruct.THISTIMER, 0.01, true, function lis_collisioncheck)
call BJDebugMsg(I2S(GetHandleId(newt)))
// If not in Cone of Vision Destroy Effect (If created)
else
call DestroyTimer(newt)
set unitstruct.COV_TICK=0.0
if unitstruct.COV_SPECIALEFFECTBOOL then
call DestroyEffect(unitstruct.COV_EFFECT)
set unitstruct.COV_SPECIALEFFECTBOOL=false
endif
endif
//Save Struct
call unitstruct.save()
//Remove Leaks
call unitstruct.destroy()
call timerstruct.destroy()
call newtimerstruct.destroy()
set t=null
set stunit=null
set newt=null
set dummy=null
endfunction
//Start Timer and ini the booleans, units etc.
function Trig_stealthini_Actions takes nothing returns nothing
local globaltimerstruct timerstruct = globaltimerstruct.create(CreateTimer())
local globalunitstruct unitstruct=globalunitstruct[GetEnteringUnit()]
set unitstruct.COV_SPOTTEDBOOL=FALSE
set unitstruct.COV_SPECIALEFFECTBOOL=FALSE
set unitstruct.COV_TICK=0.00
set timerstruct.COV_THISUNIT=GetEnteringUnit()
call unitstruct.save()
call timerstruct.save()
call TimerStart(timerstruct.THISTIMER, 0.1, true, function lis_isinsight)
call timerstruct.destroy()
call unitstruct.destroy()
endfunction
//===========================================================================
function InitTrig_Lineinsight takes nothing returns nothing
set hero = gg_unit_h000_0000 //Ini the local Herovariable
set gg_trg_Lineinsight = CreateTrigger( )
call TriggerRegisterUnitInRange( gg_trg_Lineinsight, hero, 700.00,null )
call TriggerAddAction( gg_trg_Lineinsight, function Trig_stealthini_Actions )
endfunction
The Problem is, that the timer "newt" doesn't start in the function "lis_isinsight". I get both DebugMsg (The HandleIDs are the same).
It doesn't matter whats in function "lis_collisioncheck"...Even if it's just one "call BJDebugMsg("test")" i don't get it.
And the strange thing is, that the timer "t" in "Trig_stealthini_Actions" starts the function "lis_isinsight" without problems...and there is not a big difference between these two timers, is there?
JASS:
///////////////////////////////////////////////////////////////////////////////////
//////////Unit Struct for the COV-System //////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
struct globalunitstruct
unit THISUNIT //Unit the Structs belongs to
unit PARTNERUNIT //The Partnerunit
unit CONTROLDUMMY //Controldummy for Player 2 Units only
real COV_TICK=0 //Tick for the ConeOfVision-system (Player 2 Units only)
real COV_RANGE=0 //Range for Dummymove in the COV-system (Player 2 Units only)
boolean COV_SPOTTEDBOOL=false //Bool if Unit spotted Hero (Player 2 Units only)
boolean COV_SPECIALEFFECTBOOL=false //Bool if overhead Unit is a Effect (Player 2 Units only)
boolean COV_CROUCHBOOL=false //Bool if Hero has to Duck (Player 2 Units only)
effect COV_EFFECT //Overhead Effect for Thisunit (Player 2 Units only)
//Create-method which saves directly the THISUNIT
static method create takes unit u returns thistype
local globalunitstruct newstruct = globalunitstruct.allocate()
set newstruct.THISUNIT = u
return newstruct
endmethod
//Method to Save Struct to THISUNIT in hashtable
method save takes nothing returns nothing
call SaveInteger(udg_hashtable,GetHandleId(this.THISUNIT),0,this)
endmethod
//Method to Load Struct of THISUNIT in hashtable
static method operator [] takes unit u returns thistype
return LoadInteger(udg_hashtable,GetHandleId(u), 0 )
endmethod
endstruct
//---------------------------------------------------------------------------------
JASS:
///////////////////////////////////////////////////////////////////////////////////
//////////Timer Struct for the COV-System and the Clickables-system////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
struct globaltimerstruct
timer THISTIMER //Timer the struct belongs to
unit COV_THISUNIT //Unit for the COV-System which schould be passed to timerfunction
unit COV_DUMMYUNIT //Dummyunit for the COV-System which schould be passed to timerfunction
//Create and set THISTIMER to the timer
static method create takes timer t returns thistype
local globaltimerstruct newstruct = globaltimerstruct.allocate()
set newstruct.THISTIMER=t
return newstruct
endmethod
//Method to Save Struct to THISTIMER in hashtable
method save takes nothing returns nothing
call SaveInteger(udg_hashtable,GetHandleId(this.THISTIMER),0,this)
endmethod
//Method to Load Struct of THISTIMER in hashtable
static method operator [] takes timer t returns thistype
return LoadInteger(udg_hashtable, GetHandleId(t), 0)
endmethod
endstruct
//---------------------------------------------------------------------------------
Maybe i just missed something really obvious and my brain is just to tired.
I hope you can help me
thx in advance!
PS: I don't have to create a new globalunitstruct in "Trig_stealthini_Actions" 'cause they are already created before for every unit ...but i think that the whole globalunitstruct is not the problem anyway, but the globaltimerstruct.
PSS: I know that the code is not 100% optimized