[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: 154
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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