HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help :)

07-06-2008, 02:04 PM#1
sas_Skorpion
Hi everybody i have this creep respawn code made by paskovich and i think there is a problem inside that causes big numbers of creeps spawning in places they shouldn't be spawning could somebody check pls if you find any errors (any kind that could cause the thing said above)?

Collapse JASS:
//---Options---

constant function CreepRespawn_Delay takes nothing returns real
    return udg_Respawn   //The duration (in seconds) after dying creeps respawn.
endfunction

constant function CreepRespawn_VisibilityBlock takes nothing returns boolean
    return false   //If this is set to true, creep respawn will be delayed until
                  //none of the players observe the spawning point.
                  //(So none of the players can see the creeps spawning.)
endfunction

constant function CreepRespawn_NumberOfSpawns takes nothing returns integer
    return 1      //This defines the number of creeps that will spawn after one died.
endfunction

constant function CreepRespawn_SpawnRandomFromLevel takes nothing returns boolean
    return true  //If set to true, a same-level random creep will spawn.
endfunction



//---Creep Respawn System---

function CR_H2I takes handle h returns integer
    return h
    return 0
endfunction

function SetCreepRespawnPoints takes nothing returns nothing
    local group g = CreateGroup()
    local unit u = null
    local string s = ""
    call GroupEnumUnitsOfPlayer(g,Player(12),null)
    loop
        set u = FirstOfGroup(g)
        call GroupRemoveUnit(g,u)
        exitwhen u == null
        set s = I2S(CR_H2I(u))
        call StoreReal(InitGameCache("CR"),s,"RespawnX",GetUnitX(u))
        call StoreReal(InitGameCache("CR"),s,"RespawnY",GetUnitY(u))
        call StoreReal(InitGameCache("CR"),s,"RespawnFacing",GetUnitFacing(u))
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

function RespawnCreeps takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local string s = I2S(CR_H2I(u))
    local real x = GetStoredReal(InitGameCache("CR"),s,"RespawnX")
    local real y = GetStoredReal(InitGameCache("CR"),s,"RespawnY")
    local real f = GetStoredReal(InitGameCache("CR"),s,"RespawnFacing")
    local integer a = 0
    local integer b = 0
    local integer c = 0
    call TriggerSleepAction(CreepRespawn_Delay())
    if CreepRespawn_VisibilityBlock() then
        loop
            loop
                exitwhen a > 11
                if not IsVisibleToPlayer(x,y,Player(a)) then
                    set c = c + 1
                endif
                set a = a + 1
            endloop
            exitwhen c > 11
            set a = 0
            set c = 0
            call TriggerSleepAction(10)
        endloop
        set a = 0
    endif
    set c = udg_CreepsLevel
    set b = GetUnitTypeId(u)
    call RemoveUnit(u)
    loop
        exitwhen a >= CreepRespawn_NumberOfSpawns()
        if CreepRespawn_SpawnRandomFromLevel() then
            set u = CreateUnit(Player(12),ChooseRandomCreep(c),x,y,f)
        else
            set u = CreateUnit(Player(12),b,x,y,f)
        endif
        set s = I2S(CR_H2I(u))
        call StoreReal(InitGameCache("CR"),s,"RespawnX",x)
        call StoreReal(InitGameCache("CR"),s,"RespawnY",y)
        call StoreReal(InitGameCache("CR"),s,"RespawnFacing",f)
        set a = a + 1
    endloop
    set u = null
endfunction

//===========================================================================
function InitTrig_CreepRespawn takes nothing returns nothing
    call SetCreepRespawnPoints()
    set gg_trg_CreepRespawn = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_CreepRespawn, Player(12), EVENT_PLAYER_UNIT_DEATH, null)
    call TriggerAddAction(gg_trg_CreepRespawn, function RespawnCreeps)
endfunction
07-06-2008, 02:25 PM#2
Anitarf
Why don't you ask paskovich?
07-06-2008, 02:34 PM#3
Fireeye
and i'm just thinking "What the fuck?!"
Why are there 9 InitGameCache calls?!
Why not using 1 globals variable instead of 9 function calls?
07-06-2008, 10:58 PM#4
sas_Skorpion
Quote:
and i'm just thinking "What the fuck?!"
Why are there 9 InitGameCache calls?!
Why not using 1 globals variable instead of 9 function calls?

heh :) im not good with jass so i actually dont understand you well xD but thanks for checking out :)

Quote:
Why don't you ask paskovich?
actualy im not sure if it is a code's fault :/ dont want to bother the guy for something that might not be linked to this code (at least untill im 100% sure the bug is in the code) thats why i asked for somebody who understands well jass to tell me if there is a possible bug here :) thx anyways for reviewing it