[System] New Creep Revival System

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Yes, there are dozens in the website, however I found a problem with them all. They all revive the unit where it died. This system will revive the creeps in their original location. MUI? Indeed. Easy? Yes. GUI? No. Comments? Lots.

I use KaTTaNa's handle variable system (just to ease things) you need only 5 functions of it. Copy them to the header of the map. After that copy the three triggers to your map as well and you are done.

Note: I could have used 1 global trigger, but just to ease things I used 3.

This is a few minutes work to help whoever needs it, feedbacks always welcomed. ;)

KaTTaNa's handle system:

JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function LocalVars takes nothing returns gamecache
    // Replace InitGameCache("jasslocalvars.w3v") with a global variable!!
    return InitGameCache("jasslocalvars.w3v")
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction


Trigger 1:

JASS:
// Init event (check the box above)
// This will pick in the game at the start

function Set_Creeps_Group_Condition takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(12) // Checks that the owning player is player 13 (JASS starts from 0, thus 12 + 1 = 13)
endfunction

function Set_Creeps_Group_Actions takes nothing returns nothing
    call SetHandleReal(GetEnumUnit(),"x",GetUnitX(GetEnumUnit())) // Gets the creeps' loc's X
    call SetHandleReal(GetEnumUnit(),"y",GetUnitY(GetEnumUnit())) // Gets the creeps' loc's Y
    call SetHandleReal(GetEnumUnit(),"f",GetUnitFacing(GetEnumUnit())) // Gets creep facing
endfunction

function Set_Creeps_Actions takes nothing returns nothing
    local group creeps = CreateGroup() // Local group, we'll store here the creeps.

    call GroupEnumUnitsInRect(creeps,GetWorldBounds(),Condition(function Set_Creeps_Group_Condition)) // Puts inside creeps all units owned by player 13.
    call ForGroup(creeps,function Set_Creeps_Group_Actions) // Loops through the creeps, getting their facing angle and location

    call DestroyGroup(creeps) // Destroys group
    set creeps = null // Nulls it
endfunction

//Creates the trigger

function InitTrig_Set_Creeps takes nothing returns nothing
    set gg_trg_Set_Creeps = CreateTrigger()
    call TriggerAddAction(gg_trg_Set_Creeps,function Set_Creeps_Actions)
endfunction


Trigger 2:

JASS:
// This will run when a creep enters map

function Set_Creeps_Mid_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit()) == Player(12) // Checks that the creeps is owned by player 13
endfunction

function Set_Creeps_Mid_Actions takes nothing returns nothing
    call SetHandleReal(GetTriggerUnit(),"x",GetUnitX(GetTriggerUnit())) // Gets creep's loc's X
    call SetHandleReal(GetTriggerUnit(),"y",GetUnitY(GetTriggerUnit())) // Gets creep's loc's Y
    call SetHandleReal(GetTriggerUnit(),"f",GetUnitFacing(GetTriggerUnit())) // Gets creep's facing    
endfunction

// Creates the trigger

function InitTrig_Set_Creeps_Mid takes nothing returns nothing
    set gg_trg_Set_Creeps_Mid = CreateTrigger()
    call TriggerRegisterEnterRectSimple(gg_trg_Set_Creeps_Mid,GetWorldBounds())
    call TriggerAddCondition(gg_trg_Set_Creeps_Mid,Condition(function Set_Creeps_Mid_Conditions))
    call TriggerAddAction(gg_trg_Set_Creeps_Mid,function Set_Creeps_Mid_Actions)
endfunction


Trigger 3:

JASS:
// This is the core of the system, when a unit dies it will revive it.

constant function Revive_Creeps_Wait_Time takes integer lvl returns real
    // Returns the waiting time. Creep's level * 3 + 5
    return lvl * 3.00 + 5.00
endfunction

function Revive_Creeps_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit()) == Player(12) // Checks that the creep's owner is player 13
endfunction

function Revive_Creeps_Actions takes nothing returns nothing
    local unit creep = GetTriggerUnit() // Gets the creep in a var
    local integer id = GetUnitTypeId(creep) // Gets it's type in a var
    local player owner = GetOwningPlayer(creep) // It's owner (in case you change conditions)
    local real x = GetHandleReal(creep,"x") // Gets the X
    local real y = GetHandleReal(creep,"y") // Gets the Y
    local real f = GetHandleReal(creep,"f") // Gets the creep's facing
    local integer lvl = GetUnitLevel(creep)

    call PolledWait(Revive_Creeps_Wait_Time(lvl)) // Wait the time written above

    call CreateUnit(owner,id,x,y,f) // Creates the unit
    call RemoveUnit(creep) // Removes original creep to hide body.

    set creep = null // Null creep
    set owner = null // Null Owner
endfunction

//Creates the trigger

function InitTrig_Revive_Creeps takes nothing returns nothing
    set gg_trg_Revive_Creeps = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Revive_Creeps, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(gg_trg_Revive_Creeps,Condition(function Revive_Creeps_Conditions))
    call TriggerAddAction(gg_trg_Revive_Creeps,function Revive_Creeps_Actions)
endfunction


And finally demo map:

Enjoy.
 

Attachments

  • Revive Creeps System.w3x
    24.3 KB · Views: 152
C

Cookie

Guest
Sweet! just what I was looking for, for my RPG :D

Quick Question: is it easy to edit the time that the creeps will revive in? Sorry, i dont understand JASS... hoping to learn though :D
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Yes it is. At the moment this function decides the time it will take the creeps to be revived.

JASS:

constant function Revive_Creeps_Wait_Time takes integer lvl returns real
    // Returns the waiting time. Creep\'s level * 3 + 5
    return lvl * 3.00 + 5.00
endfunction


As you can see it's the level of the creep * 3 + 5. It can be modified, just tell me the time you want and I'll post the correct function.
 
C

Cookie

Guest
well... i kind of wanted the creeps to respawn in 2 minutes, 120 seconds :D If you could do that for me, it would be a great help? :p
 
Reaction score
456
>constant function Revive_Creeps_Wait_Time takes integer lvl returns real
// Returns the waiting time. Creep\\'s level * 3 + 5
return lvl * 3.00 + 5.00
endfunction

Just chance the "return lvl * 3.00 + 5.00" to bigger amount. Nice system, useful.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Cookie, you'll need to do the following changes.

JASS:
constant function Revive_Creeps_Wait_Time takes integer lvl returns real
    // Returns the waiting time. Creep\'s level * 3 + 5
    return lvl * 3.00 + 5.00
endfunction


change this to:

JASS:
constant function Revive_Creeps_Wait_Time takes nothing returns real
    return 120.00
endfunction


And then change this line (in the 3rd trigger):

JASS:
    PolledWait(Revive_Creeps_Wait_Time(lvl)) // Wait the time written above


to:

JASS:
    PolledWait(Revive_Creeps_Wait_Time())


and it will repawn dying creeps after 120 seconds.

"Nice system, useful."

Thanks, glad to hear you like it.
 

Chocobo

White-Flower
Reaction score
409
Why not all in a single trigger btw?

JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function LocalVars takes nothing returns gamecache
    // Replace InitGameCache("jasslocalvars.w3v") with a global variable!!
    return InitGameCache("jasslocalvars.w3v")
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction

//Trigger 1:

// Init event (check the box above)
// This will pick in the game at the start

function Set_Creeps_Group_Condition takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == Player(12) // Checks that the owning player is player 13 (JASS starts from 0, thus 12 + 1 = 13)
endfunction

function Set_Creeps_Group_Actions takes nothing returns nothing
    call SetHandleReal(GetEnumUnit(),"x",GetUnitX(GetEnumUnit())) // Gets the creeps' loc's X
    call SetHandleReal(GetEnumUnit(),"y",GetUnitY(GetEnumUnit())) // Gets the creeps' loc's Y
    call SetHandleReal(GetEnumUnit(),"f",GetUnitFacing(GetEnumUnit())) // Gets creep facing
endfunction

function Set_Creeps_Actions takes nothing returns nothing
    local group creeps = CreateGroup() // Local group, we'll store here the creeps.

    call GroupEnumUnitsInRect(creeps,GetWorldBounds(),Condition(function Set_Creeps_Group_Condition)) // Puts inside creeps all units owned by player 13.
    call ForGroup(creeps,function Set_Creeps_Group_Actions) // Loops through the creeps, getting their facing angle and location

    call DestroyGroup(creeps) // Destroys group
    set creeps = null // Nulls it
endfunction

//Trigger 2:

// This will run when a creep enters map

function Set_Creeps_Mid_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit()) == Player(12) // Checks that the creeps is owned by player 13
endfunction

function Set_Creeps_Mid_Actions takes nothing returns nothing
    call SetHandleReal(GetTriggerUnit(),"x",GetUnitX(GetTriggerUnit())) // Gets creep's loc's X
    call SetHandleReal(GetTriggerUnit(),"y",GetUnitY(GetTriggerUnit())) // Gets creep's loc's Y
    call SetHandleReal(GetTriggerUnit(),"f",GetUnitFacing(GetTriggerUnit())) // Gets creep's facing    
endfunction

//Trigger 3:

// This is the core of the system, when a unit dies it will revive it.

constant function Revive_Creeps_Wait_Time takes integer lvl returns real
    // Returns the waiting time. Creep's level * 3 + 5
    return lvl * 3.00 + 5.00
endfunction

function Revive_Creeps_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit()) == Player(12) // Checks that the creep's owner is player 13
endfunction

function Revive_Creeps_Actions takes nothing returns nothing
    local unit creep = GetTriggerUnit() // Gets the creep in a var
    local integer id = GetUnitTypeId(creep) // Gets it's type in a var
    local player owner = GetOwningPlayer(creep) // It's owner (in case you change conditions)
    local real x = GetHandleReal(creep,"x") // Gets the X
    local real y = GetHandleReal(creep,"y") // Gets the Y
    local real f = GetHandleReal(creep,"f") // Gets the creep's facing
    local integer lvl = GetUnitLevel(creep)

    call PolledWait(Revive_Creeps_Wait_Time(lvl)) // Wait the time written above

    call CreateUnit(owner,id,x,y,f) // Creates the unit
    call RemoveUnit(creep) // Removes original creep to hide body.

    set creep = null // Null creep
    set owner = null // Null Owner
endfunction

//Create all the triggers

function InitTrig_Set_Creeps takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerAddAction(t,function Set_Creeps_Actions)
    set t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t,Condition(function Revive_Creeps_Conditions))
    call TriggerAddAction(t,function Revive_Creeps_Actions)
    set t=CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,GetWorldBounds())
    call TriggerAddCondition(t,Condition(function Set_Creeps_Mid_Conditions))
    call TriggerAddAction(t,function Set_Creeps_Mid_Actions)
endfunction
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
" Why not all in a single trigger btw? "

" Chocobo, having separate triggers just makes it more organized. "

Exactly, "JASS masters" could have done this easily, however this system is ment for people which aren't familiared with JASS and just want to apply this kind of system to their map.
 

Steel

Software Engineer
Reaction score
109
1 trigger is better for people who don't know JASS. It is less for them to import, you should structure your functions to use constants and those should be the only things people should modify since your code should reference them. This is the best way to make open source code for new JASSers. Just a tip.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top