-
Are you planning to upload your awesome spell or system to Hive? Please review the rules here.Dismiss Notice
-
Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.Dismiss Notice
-
A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!Dismiss Notice
-
Check out the Staff job openings thread.Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.
Respawn System - v1.0b
Submitted by
Mr_Bean
- Tags:
- System, GUI / Triggers, vJASS
- Filesize:
- 31.47 KB
- Rating:
-
(2 votes)
- Downloads:
- 321
- Uploaded:
- Jun 22, 2012
- Updated:
- Dec 12, 2015
- Resources:
- 1
- Author(s):
- Mr_Bean
- State:
- Substandard

This bundle is marked as substandard. It may contain bugs, not perform optimally or otherwise be in violation of the submission rules.
Respawn System - v1.0b
By Mr_Bean
Introduction
This system was originally requested by Peacehagen for his map Rise of the Corruptor ORPG.
He recommended that I upload it because it would help people, which I hope it does!
I added some new features to it and made it as user-friendly as possible.
Features
- Respawn all dead creeps every X seconds, or individual creeps X seconds after they die.
- Specify which players to respawn creeps for.
- Functions which allow the following:
- Respawn all dead creeps immediately.
- Respawn all dead creeps owned by a specific player immediately.
- Pause and resume the system.
- Reset and restart the system.
- Count how many creeps there are in total, alive and dead.
- Can choose to respawn heroes or not.
- Written in vJASS, can be used in GUI.
Requirements
- JASS NewGen Pack [LINK]
- Latest JASSHelper [LINK]
- TimerUtils by Vexorian (included in demo map)
Available Functions
JASS Version
Code (vJASS):
function RespawnAllCreeps takes nothing returns nothing
function RespawnAllCreepsForPlayer takes player whichPlayer returns nothing
function PauseRespawnSystem takes integer howLong returns nothing
function ResumeRespawnSystem takes nothing returns nothing
function ResetRespawnSystem takes nothing returns nothing
function RestartRespawnSystem takes nothing returns nothing
function GetAliveCreeps takes nothing returns integer
function GetDeadCreeps takes nothing returns integer
function GetTotalCreeps takes nothing returns integer
function RespawnAllCreepsForPlayer takes player whichPlayer returns nothing
function PauseRespawnSystem takes integer howLong returns nothing
function ResumeRespawnSystem takes nothing returns nothing
function ResetRespawnSystem takes nothing returns nothing
function RestartRespawnSystem takes nothing returns nothing
function GetAliveCreeps takes nothing returns integer
function GetDeadCreeps takes nothing returns integer
function GetTotalCreeps takes nothing returns integer
GUI Version
-
Custom script: call RespawnAllCreeps()
-
Custom script: call RespawnAllCreepsForPlayer(player whichPlayer)
-
Custom script: call PauseRespawnSystem(integer howLong)
-
Custom script: call ResumeRespawnSystem()
-
Custom script: call ResetRespawnSystem()
-
Custom script: call RestartRespawnSystem()
-
Custom script: call GetAliveCreeps()
-
Custom script: call GetDeadCreeps()
-
Custom script: call GetTotalCreeps()
Code
vJASS Code
Code (vJASS):
library RespawnSystem initializer OnInit requires TimerUtils
//**************************************************\\
//*** START OF CONFIGURABLES ***\\
//**************************************************\\
globals
// Delay between unit dying and respawning:
private constant real RESPAWN_DELAY = 30.0
// Respawn all dead units at once? If set to false, units will respawn individually.
private constant boolean RESPAWN_TOGETHER = true
// Show a countdown window to all players:
private constant boolean SHOW_TIMER_WINDOW = false
// Countdown window text (only applicable if SHOW_TIMER_WINDOW = true):
private constant string TIMER_WINDOW_TEXT = "Creeps respawn in:"
// Respawn heroes:
private constant boolean RESPAWN_HEROES = false
// Effect created on respawning units (set to "" to have no effect):
private constant string RESPAWN_EFFECT = "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl"
// Attachment point of effect on unit:
private constant string EFFECT_ATTACHMENT = "origin"
endglobals
private function CheckOwner takes nothing returns boolean
local integer playerId = GetPlayerId(GetOwningPlayer(GetFilterUnit()))
if /*
//------------------------------------------------------\\
// Add the players that the system respawns creeps for: \\
// Remember to subtract 1 from GUI player indexes! \\
*/ playerId == 10 or /* // Player 11 in GUI. \*
*/ playerId == 11 or /* // Player 12 in GUI. \*
*/ playerId == 12 /* // Neutral Hostile in GUI. \*
//------------------------------------------------------\\
*/ then
return true
endif
return false
endfunction
//**************************************************\\
//*** END OF CONFIGURABLES ***\\
//**************************************************\\
globals
private group deadCreeps = CreateGroup()
private group creeps = CreateGroup()
private group enumG = CreateGroup()
private hashtable ht = InitHashtable()
private timer respawnTimer
private timerdialog timerWindow
private integer tempInt = 0
endglobals
private function Increment takes nothing returns nothing
set tempInt = tempInt + 1
endfunction
private function EnumerateGroup takes group g returns integer
set tempInt = 0
call ForGroup(g, function Increment)
return tempInt
endfunction
//**************************************************\\
//*** GetTotalCreeps ***\\
//**************************************************\\
function GetTotalCreeps takes nothing returns integer
return EnumerateGroup(creeps) + EnumerateGroup(deadCreeps)
endfunction
//**************************************************\\
//*** GetAliveCreeps ***\\
//**************************************************\\
function GetDeadCreeps takes nothing returns integer
return EnumerateGroup(deadCreeps)
endfunction
//**************************************************\\
//*** GetDeadCreeps ***\\
//**************************************************\\
function GetAliveCreeps takes nothing returns integer
return EnumerateGroup(creeps)
endfunction
//**************************************************\\
private function RespawnCreepX takes integer handleId returns nothing
local real x = LoadReal(ht, handleId, StringHash("x"))
local real y = LoadReal(ht, handleId, StringHash("y"))
local real angle = LoadReal(ht, handleId, StringHash("facing"))
local integer owner = LoadInteger(ht, handleId, StringHash("owner"))
local integer unitType = LoadInteger(ht, handleId, StringHash("type"))
local unit creep
set creep = CreateUnit(Player(owner), unitType, x, y, angle)
call FlushChildHashtable(ht, handleId)
call DestroyEffect(AddSpecialEffectTarget(RESPAWN_EFFECT, creep, EFFECT_ATTACHMENT))
set handleId = GetHandleId(creep)
call SaveReal(ht, handleId, StringHash("x"), GetUnitX(creep))
call SaveReal(ht, handleId, StringHash("y"), GetUnitY(creep))
call SaveReal(ht, handleId, StringHash("facing"), GetUnitFacing(creep))
call SaveInteger(ht, handleId, StringHash("owner"), GetPlayerId(GetOwningPlayer(creep)))
call SaveInteger(ht, handleId, StringHash("type"), GetUnitTypeId(creep))
call GroupRemoveUnit(deadCreeps, creep)
call GroupAddUnit(creeps, creep)
set creep = null
endfunction
//**************************************************\\
//*** ResumeRespawnSystem ***\\
//**************************************************\\
function ResumeRespawnSystem takes nothing returns nothing
static if RESPAWN_TOGETHER then
call ResumeTimer(respawnTimer)
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use ResumeRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
//*** PauseRespawnSystem ***\\
//**************************************************\\
function PauseRespawnSystem takes real duration returns nothing
static if RESPAWN_TOGETHER then
if duration < 0 then
call PauseTimer(respawnTimer)
elseif duration > 0 then
call PauseTimer(respawnTimer)
call TimerStart(NewTimer(), duration, false, function ResumeRespawnSystem)
endif
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use PauseRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
//*** RespawnAllCreepsForPlayer ***\\
//**************************************************\\
function RespawnAllCreepsForPlayer takes player whichPlayer returns nothing
local unit temp
set enumG = deadCreeps
loop
set temp = FirstOfGroup(enumG)
exitwhen temp == null
if GetOwningPlayer(temp) == whichPlayer then
call RespawnCreepX(GetHandleId(temp))
endif
call GroupRemoveUnit(enumG, temp)
endloop
endfunction
private function GroupEnumeration takes nothing returns nothing
call RespawnCreepX(GetHandleId(GetEnumUnit()))
endfunction
//**************************************************\\
//*** RespawnAllCreeps ***\\
//**************************************************\\
function RespawnAllCreeps takes nothing returns nothing
call ForGroup(deadCreeps, function GroupEnumeration)
endfunction
//**************************************************\\
//*** ResetRespawnSystem ***\\
//**************************************************\\
function ResetRespawnSystem takes nothing returns nothing
static if RESPAWN_TOGETHER then
call TimerStart(respawnTimer, RESPAWN_DELAY, true, function RespawnAllCreeps)
call PauseTimer(respawnTimer)
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use ResetRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
//*** RestartRespawnSystem ***\\
//**************************************************\\
function RestartRespawnSystem takes nothing returns nothing
static if RESPAWN_TOGETHER then
call TimerStart(respawnTimer, RESPAWN_DELAY, true, function RespawnAllCreeps)
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use RestartRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
private function TimerExpiration takes nothing returns nothing
call RespawnCreepX(GetTimerData(GetExpiredTimer()))
call ReleaseTimer(GetExpiredTimer())
endfunction
private function CreepDeath takes nothing returns boolean
local unit u = GetTriggerUnit()
if IsUnitInGroup(u, creeps) then
call GroupRemoveUnit(creeps, u)
call GroupAddUnit(deadCreeps, u)
static if not RESPAWN_TOGETHER then
call TimerStart(NewTimerEx(GetHandleId(u)), RESPAWN_DELAY, false, function TimerExpiration)
endif
endif
set u = null
return false
endfunction
private function GroupCreeps takes nothing returns nothing
local unit temp
local integer handleId
call GroupEnumUnitsInRect(enumG, bj_mapInitialPlayableArea, Condition(function CheckOwner))
loop
set temp = FirstOfGroup(enumG)
exitwhen temp == null
if not IsUnitType(temp, UNIT_TYPE_DEAD) then
set handleId = GetHandleId(temp)
call SaveReal(ht, handleId, StringHash("x"), GetUnitX(temp))
call SaveReal(ht, handleId, StringHash("y"), GetUnitY(temp))
call SaveReal(ht, handleId, StringHash("facing"), GetUnitFacing(temp))
call SaveInteger(ht, handleId, StringHash("owner"), GetPlayerId(GetOwningPlayer(temp)))
call SaveInteger(ht, handleId, StringHash("type"), GetUnitTypeId(temp))
call GroupAddUnit(creeps, temp)
endif
call GroupRemoveUnit(enumG, temp)
endloop
endfunction
private function CreateDialog takes nothing returns nothing
set timerWindow = CreateTimerDialog(respawnTimer)
call TimerDialogSetTitle(timerWindow, TIMER_WINDOW_TEXT)
call TimerDialogDisplay(timerWindow, true)
endfunction
private function OnInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddCondition(t, Condition(function CreepDeath))
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
set t = null
call GroupCreeps()
static if RESPAWN_TOGETHER then
set respawnTimer = CreateTimer()
call TimerStart(respawnTimer, RESPAWN_DELAY, true, function RespawnAllCreeps)
static if SHOW_TIMER_WINDOW then
call TimerStart(NewTimer(), 0.01, false, function CreateDialog)
endif
endif
endfunction
endlibrary
//**************************************************\\
//*** START OF CONFIGURABLES ***\\
//**************************************************\\
globals
// Delay between unit dying and respawning:
private constant real RESPAWN_DELAY = 30.0
// Respawn all dead units at once? If set to false, units will respawn individually.
private constant boolean RESPAWN_TOGETHER = true
// Show a countdown window to all players:
private constant boolean SHOW_TIMER_WINDOW = false
// Countdown window text (only applicable if SHOW_TIMER_WINDOW = true):
private constant string TIMER_WINDOW_TEXT = "Creeps respawn in:"
// Respawn heroes:
private constant boolean RESPAWN_HEROES = false
// Effect created on respawning units (set to "" to have no effect):
private constant string RESPAWN_EFFECT = "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl"
// Attachment point of effect on unit:
private constant string EFFECT_ATTACHMENT = "origin"
endglobals
private function CheckOwner takes nothing returns boolean
local integer playerId = GetPlayerId(GetOwningPlayer(GetFilterUnit()))
if /*
//------------------------------------------------------\\
// Add the players that the system respawns creeps for: \\
// Remember to subtract 1 from GUI player indexes! \\
*/ playerId == 10 or /* // Player 11 in GUI. \*
*/ playerId == 11 or /* // Player 12 in GUI. \*
*/ playerId == 12 /* // Neutral Hostile in GUI. \*
//------------------------------------------------------\\
*/ then
return true
endif
return false
endfunction
//**************************************************\\
//*** END OF CONFIGURABLES ***\\
//**************************************************\\
globals
private group deadCreeps = CreateGroup()
private group creeps = CreateGroup()
private group enumG = CreateGroup()
private hashtable ht = InitHashtable()
private timer respawnTimer
private timerdialog timerWindow
private integer tempInt = 0
endglobals
private function Increment takes nothing returns nothing
set tempInt = tempInt + 1
endfunction
private function EnumerateGroup takes group g returns integer
set tempInt = 0
call ForGroup(g, function Increment)
return tempInt
endfunction
//**************************************************\\
//*** GetTotalCreeps ***\\
//**************************************************\\
function GetTotalCreeps takes nothing returns integer
return EnumerateGroup(creeps) + EnumerateGroup(deadCreeps)
endfunction
//**************************************************\\
//*** GetAliveCreeps ***\\
//**************************************************\\
function GetDeadCreeps takes nothing returns integer
return EnumerateGroup(deadCreeps)
endfunction
//**************************************************\\
//*** GetDeadCreeps ***\\
//**************************************************\\
function GetAliveCreeps takes nothing returns integer
return EnumerateGroup(creeps)
endfunction
//**************************************************\\
private function RespawnCreepX takes integer handleId returns nothing
local real x = LoadReal(ht, handleId, StringHash("x"))
local real y = LoadReal(ht, handleId, StringHash("y"))
local real angle = LoadReal(ht, handleId, StringHash("facing"))
local integer owner = LoadInteger(ht, handleId, StringHash("owner"))
local integer unitType = LoadInteger(ht, handleId, StringHash("type"))
local unit creep
set creep = CreateUnit(Player(owner), unitType, x, y, angle)
call FlushChildHashtable(ht, handleId)
call DestroyEffect(AddSpecialEffectTarget(RESPAWN_EFFECT, creep, EFFECT_ATTACHMENT))
set handleId = GetHandleId(creep)
call SaveReal(ht, handleId, StringHash("x"), GetUnitX(creep))
call SaveReal(ht, handleId, StringHash("y"), GetUnitY(creep))
call SaveReal(ht, handleId, StringHash("facing"), GetUnitFacing(creep))
call SaveInteger(ht, handleId, StringHash("owner"), GetPlayerId(GetOwningPlayer(creep)))
call SaveInteger(ht, handleId, StringHash("type"), GetUnitTypeId(creep))
call GroupRemoveUnit(deadCreeps, creep)
call GroupAddUnit(creeps, creep)
set creep = null
endfunction
//**************************************************\\
//*** ResumeRespawnSystem ***\\
//**************************************************\\
function ResumeRespawnSystem takes nothing returns nothing
static if RESPAWN_TOGETHER then
call ResumeTimer(respawnTimer)
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use ResumeRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
//*** PauseRespawnSystem ***\\
//**************************************************\\
function PauseRespawnSystem takes real duration returns nothing
static if RESPAWN_TOGETHER then
if duration < 0 then
call PauseTimer(respawnTimer)
elseif duration > 0 then
call PauseTimer(respawnTimer)
call TimerStart(NewTimer(), duration, false, function ResumeRespawnSystem)
endif
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use PauseRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
//*** RespawnAllCreepsForPlayer ***\\
//**************************************************\\
function RespawnAllCreepsForPlayer takes player whichPlayer returns nothing
local unit temp
set enumG = deadCreeps
loop
set temp = FirstOfGroup(enumG)
exitwhen temp == null
if GetOwningPlayer(temp) == whichPlayer then
call RespawnCreepX(GetHandleId(temp))
endif
call GroupRemoveUnit(enumG, temp)
endloop
endfunction
private function GroupEnumeration takes nothing returns nothing
call RespawnCreepX(GetHandleId(GetEnumUnit()))
endfunction
//**************************************************\\
//*** RespawnAllCreeps ***\\
//**************************************************\\
function RespawnAllCreeps takes nothing returns nothing
call ForGroup(deadCreeps, function GroupEnumeration)
endfunction
//**************************************************\\
//*** ResetRespawnSystem ***\\
//**************************************************\\
function ResetRespawnSystem takes nothing returns nothing
static if RESPAWN_TOGETHER then
call TimerStart(respawnTimer, RESPAWN_DELAY, true, function RespawnAllCreeps)
call PauseTimer(respawnTimer)
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use ResetRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
//*** RestartRespawnSystem ***\\
//**************************************************\\
function RestartRespawnSystem takes nothing returns nothing
static if RESPAWN_TOGETHER then
call TimerStart(respawnTimer, RESPAWN_DELAY, true, function RespawnAllCreeps)
else
call BJDebugMsg("|cffff0000Respawn System|r: Cannot use RestartRespawnSystem when RESPAWN_TOGETHER = false.")
endif
endfunction
//**************************************************\\
private function TimerExpiration takes nothing returns nothing
call RespawnCreepX(GetTimerData(GetExpiredTimer()))
call ReleaseTimer(GetExpiredTimer())
endfunction
private function CreepDeath takes nothing returns boolean
local unit u = GetTriggerUnit()
if IsUnitInGroup(u, creeps) then
call GroupRemoveUnit(creeps, u)
call GroupAddUnit(deadCreeps, u)
static if not RESPAWN_TOGETHER then
call TimerStart(NewTimerEx(GetHandleId(u)), RESPAWN_DELAY, false, function TimerExpiration)
endif
endif
set u = null
return false
endfunction
private function GroupCreeps takes nothing returns nothing
local unit temp
local integer handleId
call GroupEnumUnitsInRect(enumG, bj_mapInitialPlayableArea, Condition(function CheckOwner))
loop
set temp = FirstOfGroup(enumG)
exitwhen temp == null
if not IsUnitType(temp, UNIT_TYPE_DEAD) then
set handleId = GetHandleId(temp)
call SaveReal(ht, handleId, StringHash("x"), GetUnitX(temp))
call SaveReal(ht, handleId, StringHash("y"), GetUnitY(temp))
call SaveReal(ht, handleId, StringHash("facing"), GetUnitFacing(temp))
call SaveInteger(ht, handleId, StringHash("owner"), GetPlayerId(GetOwningPlayer(temp)))
call SaveInteger(ht, handleId, StringHash("type"), GetUnitTypeId(temp))
call GroupAddUnit(creeps, temp)
endif
call GroupRemoveUnit(enumG, temp)
endloop
endfunction
private function CreateDialog takes nothing returns nothing
set timerWindow = CreateTimerDialog(respawnTimer)
call TimerDialogSetTitle(timerWindow, TIMER_WINDOW_TEXT)
call TimerDialogDisplay(timerWindow, true)
endfunction
private function OnInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddCondition(t, Condition(function CreepDeath))
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
set t = null
call GroupCreeps()
static if RESPAWN_TOGETHER then
set respawnTimer = CreateTimer()
call TimerStart(respawnTimer, RESPAWN_DELAY, true, function RespawnAllCreeps)
static if SHOW_TIMER_WINDOW then
call TimerStart(NewTimer(), 0.01, false, function CreateDialog)
endif
endif
endfunction
endlibrary
Changelogs
v1.0b (33 June 2012)
- Improved creep counting as per KnnO's suggestion.
- Added map name, description and author for demo map.
- Added map name, description and author for demo map.
v1.0 (22 June 2012)
- Initial release.
Credits
- Peacehagen for requesting the system and encouraging me to upload it.
- Vexorian for TimerUtils.
Contact
If you find any bugs in the system or if something is unclear in the documentation, please let me know!
- Private Message
Keywords:
respawn, system, respawn system, creep, mr_bean, peacehagen
Contents
Page 1 of 2