• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Respawning creeps problems (Not retarted)

Status
Not open for further replies.
Level 3
Joined
Jan 24, 2011
Messages
26
Ok so lets state what happens first.
I have a ORPG map with a friend of mine, and since the very start we had a VERY basic script to re-spawn the creeps.
it basicly does this:

Map init:
Create a custom number for every unit (for later use) on the WHOLE map.
Saving there unit type in a variable array, and there position of creation (We do not want creeps re-spawning where they die right?)

If creepy dies:
Wait 60seconds (just example time)
Unit - Create 1 UnitType_Mob[(Custom value of (Triggering unit))] for (Triggering player) at Position_Mob[(Custom value of (Triggering unit))] facing (Random angle) degrees

Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))

This works perfectly! BUT If one was to remove the units corpse. The ''triggering unit'' (or dieing unit for that matter, shouldn't matter at all.) Gets removed after the ''wait'' command, and the game forgets what mob and for what player it should be created.

So i tried to work AROUND that problem.. by saving the owning player and the triggering unit into 2 array's then wait 60 seconds, and then recalling the correct array number (meaning i would be limited to a certain amount of dead units at the same time before this goes wrong. But it should work at the least)

However. once again, if the units CORPSE gets removed before the waiting time the unit TYPE and the owning player are saved to the variable array. but after the 60second wait, the game once more forgets what is in those variables (though the same system i scripted without removing the corpse works just fine, so the variable saving works!)

Ill post the text version here, and hope you get what i am doing wrong (or the game is):

MAP INI:
Code:
Mob Position
    Events
        Time - Elapsed game time is 1.00 seconds
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Entire map)) and do (Actions)
            Loop - Actions
                Set RespawnInteger = (RespawnInteger + 1)
                Unit - Set the custom value of (Picked unit) to RespawnInteger
                Set Point_Mob[RespawnInteger] = (Position of (Picked unit))
                Set UnitType_Mob[RespawnInteger] = (Unit-type of (Picked unit))
(saving unit type might be a bit overkill but i was testing around)


WHEN UNIT DIES:
Code:
Mob Respawn Copy
    Events
        Unit - A unit owned by Player 4 (Purple) Dies
        Unit - A unit owned by Player 8 (Pink) Dies
        Unit - A unit owned by Neutral Hostile Dies
    Conditions
        ((Triggering unit) is Summoned) Equal to False
        (Unit-type of (Triggering unit)) Not equal to Town Hall
    Actions
        Set DeathMemoryNumber = (DeathMemoryNumber + 1)
        Game - Display to (All players) the text: (String(DeathMemoryNumber))
        If (DeathMemoryNumber Equal to 4) then do (Set DeathMemoryNumber = 0) else do (Do nothing)
        Set DeathMemoryPlayer[DeathMemoryNumber] = (Owner of (Triggering unit))
        Set DeathMemoryUnit[DeathMemoryNumber] = (Triggering unit)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                DeathMemoryNumber Equal to 0
            Then - Actions
                Wait 30.00 seconds
                Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[0])] for DeathMemoryPlayer[0] at Point_Mob[(Custom value of DeathMemoryUnit[0])] facing (Random angle) degrees
                Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[0])
                Unit - Set (Last created unit) acquisition range to 200.00
                Set DeathMemoryPlayer[0] = Emptyplayer
                Set DeathMemoryUnit[0] = EmptyUnit
            Else - Actions
                Do nothing
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                DeathMemoryNumber Equal to 1
            Then - Actions
                Wait 30.00 seconds
                Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[1])] for DeathMemoryPlayer[1] at Point_Mob[(Custom value of DeathMemoryUnit[1])] facing (Random angle) degrees
                Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[1])
                Unit - Set (Last created unit) acquisition range to 200.00
                Set DeathMemoryPlayer[1] = Emptyplayer
                Set DeathMemoryUnit[1] = EmptyUnit
            Else - Actions
                Do nothing
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                DeathMemoryNumber Equal to 2
            Then - Actions
                Wait 30.00 seconds
                Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[2])] for DeathMemoryPlayer[2] at Point_Mob[(Custom value of DeathMemoryUnit[2])] facing (Random angle) degrees
                Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[2])
                Unit - Set (Last created unit) acquisition range to 200.00
                Set DeathMemoryPlayer[2] = Emptyplayer
                Set DeathMemoryUnit[2] = EmptyUnit
            Else - Actions
                Do nothing
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                DeathMemoryNumber Equal to 3
            Then - Actions
                Wait 30.00 seconds
                Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[3])] for DeathMemoryPlayer[3] at Point_Mob[(Custom value of DeathMemoryUnit[3])] facing (Random angle) degrees
                Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[3])
                Unit - Set (Last created unit) acquisition range to 200.00
                Set DeathMemoryPlayer[3] = Emptyplayer
                Set DeathMemoryUnit[3] = EmptyUnit
            Else - Actions
                Do nothing

Variables i used:
DeathMemoryPlayer[array] (saves owning player)
DeathMemoryUnit[Array] (Saves unit.)
DeathMemoryNumber (Saves the number were on, to make each time the code runs direct to one of the IF THEN ELSE parts in attempt to make it not confusd with the wait time)

If someone gets that When a unit is killed and the corpse STAYS this program works. And if the unit dies and there is NO corpse (turned skeleton or exploded units for example) This fails and the DeathMemoryUnit simply goes BLANK after the waiting period. Id be VERY happy.

Keep in mind:
All variables were created, and not used in ANY other part of my codes.
While testing the script i made sure NEVER to kill more then 2 or 3 mobs (to avoid the overwriting of number 1 when a 5th unit is dead at the same time.)

I might write something confusing, if you got questions ask, ill be monitoring this thread.
 
Level 13
Joined
Oct 27, 2008
Messages
1,176
this would be a trigger issue and should be posted in the trigger section
BTW changeing it over to the
also lets everyone see the trigger the way it should be so can you change it please?
 
Level 37
Joined
Mar 6, 2006
Messages
9,240



  • Mob Position
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Entire map)) and do (Actions)
        • Loop - Actions
          • Set RespawnInteger = (RespawnInteger + 1)
          • Unit - Set the custom value of (Picked unit) to RespawnInteger
          • Set Point_Mob[RespawnInteger] = (Position of (Picked unit))
          • Set UnitType_Mob[RespawnInteger] = (Unit-type of (Picked unit))
(saving unit type might be a bit overkill but i was testing around)



  • Mob Respawn Copy
    • Events
      • Unit - A unit owned by Player 4 (Purple) Dies
      • Unit - A unit owned by Player 8 (Pink) Dies
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
      • ((Triggering unit) is Summoned) Equal to False
      • (Unit-type of (Triggering unit)) Not equal to Town Hall
    • Actions
      • Set DeathMemoryNumber = (DeathMemoryNumber + 1)
      • Game - Display to (All players) the text: (String(DeathMemoryNumber))
      • If (DeathMemoryNumber Equal to 4) then do (Set DeathMemoryNumber = 0) else do (Do nothing)
      • Set DeathMemoryPlayer[DeathMemoryNumber] = (Owner of (Triggering unit))
      • Set DeathMemoryUnit[DeathMemoryNumber] = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DeathMemoryNumber Equal to 0
        • Then - Actions
          • Wait 30.00 seconds
          • Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[0])] for DeathMemoryPlayer[0] at Point_Mob[(Custom value of DeathMemoryUnit[0])] facing (Random angle) degrees
          • Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[0])
          • Unit - Set (Last created unit) acquisition range to 200.00
          • Set DeathMemoryPlayer[0] = Emptyplayer
          • Set DeathMemoryUnit[0] = EmptyUnit
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DeathMemoryNumber Equal to 1
        • Then - Actions
          • Wait 30.00 seconds
          • Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[1])] for DeathMemoryPlayer[1] at Point_Mob[(Custom value of DeathMemoryUnit[1])] facing (Random angle) degrees
          • Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[1])
          • Unit - Set (Last created unit) acquisition range to 200.00
          • Set DeathMemoryPlayer[1] = Emptyplayer
          • Set DeathMemoryUnit[1] = EmptyUnit
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DeathMemoryNumber Equal to 2
        • Then - Actions
          • Wait 30.00 seconds
          • Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[2])] for DeathMemoryPlayer[2] at Point_Mob[(Custom value of DeathMemoryUnit[2])] facing (Random angle) degrees
          • Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[2])
          • Unit - Set (Last created unit) acquisition range to 200.00
          • Set DeathMemoryPlayer[2] = Emptyplayer
          • Set DeathMemoryUnit[2] = EmptyUnit
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • DeathMemoryNumber Equal to 3
        • Then - Actions
          • Wait 30.00 seconds
          • Unit - Create 1 UnitType_Mob[(Custom value of DeathMemoryUnit[3])] for DeathMemoryPlayer[3] at Point_Mob[(Custom value of DeathMemoryUnit[3])] facing (Random angle) degrees
          • Unit - Set the custom value of (Last created unit) to (Custom value of DeathMemoryUnit[3])
          • Unit - Set (Last created unit) acquisition range to 200.00
          • Set DeathMemoryPlayer[3] = Emptyplayer
          • Set DeathMemoryUnit[3] = EmptyUnit
        • Else - Actions
          • Do nothing


You can use this:

  • Init Respawn
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set rhash = (Last created hashtable)
      • Set rtime = 5.00
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Actions)
        • Loop - Actions
          • Custom script: call SaveReal( udg_rhash , GetHandleId(GetEnumUnit()) , StringHash("x") , GetUnitX(GetEnumUnit()) )
          • Custom script: call SaveReal( udg_rhash , GetHandleId(GetEnumUnit()) , StringHash("y") , GetUnitY(GetEnumUnit()) )
          • Custom script: call SaveReal( udg_rhash , GetHandleId(GetEnumUnit()) , StringHash("facing") , GetUnitFacing(GetEnumUnit()) )
  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Custom script: local integer utype = GetUnitTypeId(GetTriggerUnit())
      • Custom script: local player p = GetOwningPlayer(GetTriggerUnit())
      • Custom script: local real x = LoadReal( udg_rhash , GetHandleId(GetTriggerUnit()) , StringHash("x") )
      • Custom script: local real y = LoadReal( udg_rhash , GetHandleId(GetTriggerUnit()) , StringHash("y") )
      • Custom script: local real facing = LoadReal( udg_rhash , GetHandleId(GetTriggerUnit()) , StringHash("facing") )
      • Custom script: call FlushChildHashtable( udg_rhash , GetHandleId(GetTriggerUnit()))
      • Wait rtime seconds
      • Custom script: set bj_lastCreatedUnit = CreateUnit( p , utype , x , y , facing )
      • Custom script: call SaveReal( udg_rhash , GetHandleId(bj_lastCreatedUnit) , StringHash("x") , x )
      • Custom script: call SaveReal( udg_rhash , GetHandleId(bj_lastCreatedUnit) , StringHash("y") , y )
      • Custom script: call SaveReal( udg_rhash , GetHandleId(bj_lastCreatedUnit) , StringHash("facing") , facing )
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering unit) Not equal to No unit
        • Then - Actions
          • Unit - Remove (Triggering unit) from the game
        • Else - Actions
      • Custom script: set p = null
I'd also delay the respawn if there is a hero nearby.

http://www.hiveworkshop.com/forums/pastebin.php?id=pl0ind
 
Level 3
Joined
Jan 24, 2011
Messages
26
*cough*Advanced*cough*
This will give me some time to figure out.
I downloaded the attached URL.
Lets see if i can make any sense of this.
You are positive that this would make mobs respawn even if there corpse would be removed?

(Also, Delay respawn when hero is nearby? Noway. they got 3minutes after the mobs respawn. You either press on, or pull back in due time. If you take longer, fighting the same mobs again is your own punishment. My custom resurrection script is not there for no reason.)

http://www.hiveworkshop.com/forums/maps-564/ashenvale-orpg-187968/

And thanks for the quick help :)
 
Level 3
Joined
Jan 24, 2011
Messages
26
@Maker,
I cannot thank you enough.
I just tested this out on that example map and even with all 4 mobs dead and a 3minute respawn this wasn't a problem. I do not fully understand WHAT you did besides store the data in hash. But it sure as hell works like a charm :) I will implement this in the next map release!
 
Status
Not open for further replies.
Top