Unit Spawn Problem

Kilgam

New Member
Reaction score
2
I spawn sometimes in my map units at certain set locations, i destroy the leaks and all but for some reason they respawn in middle of map one minute after i killed them. I think the respawn system is the cause of this, maybe somebody could take a look at it? I'm not very good with jass.

//==========================================
// CREEP RESPAWN SYSTEM
// by paskovich
//
// To implement this system,
// - create a gamecache variable called "CR"
// - copy this trigger to your map, and
// - set the options.
//==========================================


//---Options---

constant function CreepRespawn_Delay takes nothing returns real
return 90.00 //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 false //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(udg_CR,s,"RespawnX",GetUnitX(u))
call StoreReal(udg_CR,s,"RespawnY",GetUnitY(u))
call StoreReal(udg_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(udg_CR,s,"RespawnX")
local real y = GetStoredReal(udg_CR,s,"RespawnY")
local real f = GetStoredReal(udg_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 = GetUnitLevel(u)
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(udg_CR,s,"RespawnX",x)
call StoreReal(udg_CR,s,"RespawnY",y)
call StoreReal(udg_CR,s,"RespawnFacing",f)
set a = a + 1
endloop
set u = null
endfunction

//===========================================================================
function InitTrig_CreepRespawn takes nothing returns nothing
set udg_CR = InitGameCache("CR")
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
 

Samael88

Evil always finds a way
Reaction score
181
First of all, this goes into the JASS help forum.
Second, use the JASS tag instead of the quote it makes it a whole lot easier to read:)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top