• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Create unit function followed by RemoveUnit() is causing weird bug

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
These shops have stock timers on items. I have a mode selection system that I made using frames and that delays the game while the host chooses the modes and the players vote on those modes. So when the game finally start all the stock timers are out of whack. So what I did (at least 7 months ago) was make a new unit in it's place and then remove the old unit. It worked but now all of a sudden the replaced structures are being put in middle and the removeunit script seems to not be working at all. Any ideas?
So this is my code:

Code:
unit uNew;
        uNew = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), ID_SHOP_RECIPE, GetUnitX(gg_unit_n00B_0047), GetUnitY(gg_unit_n00B_0047), GetUnitFacing(gg_unit_n00B_0047));
        RemoveUnit(gg_unit_n00B_0047);
        uNew = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'n000', GetUnitX(gg_unit_n000_0017), GetUnitY(gg_unit_n000_0017), GetUnitFacing(gg_unit_n000_0017));
        RemoveUnit(gg_unit_n000_0017);  
        uNew = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'n007', GetUnitX(gg_unit_n007_0041), GetUnitY(gg_unit_n007_0041), GetUnitFacing(gg_unit_n007_0041));
        RemoveUnit(gg_unit_n007_0041);
        uNew = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'n002', GetUnitX(gg_unit_n002_0040), GetUnitY(gg_unit_n002_0040), GetUnitFacing(gg_unit_n002_0040));
        RemoveUnit(gg_unit_n002_0040);  
        uNew = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'n004', GetUnitX(gg_unit_n004_0014), GetUnitY(gg_unit_n004_0014), GetUnitFacing(gg_unit_n004_0014));
        RemoveUnit(gg_unit_n004_0014);
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
Hmm, I remember that working. Anyway, have you tried using the Replace unit function?
  • Unit - Replace YourBuilding with a YourBuilding using The old unit's relative life and mana
You can also do something like this...

Store the positions of your buildings:
  • Set Variable Point[1] = Position of building 1
  • Set Variable Point[2] = Position of building 2
  • Set Variable Point[3] = Position of building 3
  • Unit - Remove building 1 from the game
  • Unit - Remove building 2 from the game
  • Unit - Remove building 3 from the game

Then create the buildings at these points later on:
  • Unit - Create 1 building 1 at Point[1]
  • Unit - Create 1 building 2 at Point[2]
  • Unit - Create 1 building 3 at Point[3]
  • etc...
 
Level 12
Joined
Dec 2, 2016
Messages
733
Hmm, I remember that working. Anyway, have you tried using the Replace unit function?
  • Unit - Replace YourBuilding with a YourBuilding using The old unit's relative life and mana
You can also do something like this...

Store the positions of your buildings:
  • Set Variable Point[1] = Position of building 1
  • Set Variable Point[2] = Position of building 2
  • Set Variable Point[3] = Position of building 3
  • Unit - Remove building 1 from the game
  • Unit - Remove building 2 from the game
  • Unit - Remove building 3 from the game

Then create the buildings at these points later on:
  • Unit - Create 1 building 1 at Point[1]
  • Unit - Create 1 building 2 at Point[2]
  • Unit - Create 1 building 3 at Point[3]
  • etc...
I tried both those methods and didn't work.
It seems like my RemoveUnit() is not working on these preplaced units. I'm gonna try creating the structures via trigger on rects and removing the preplaced units.
 
Level 12
Joined
Dec 2, 2016
Messages
733
Your code looks like C#, what are you doing exactly? I'm guessing you're not using GUI.

Why are you unable to create the buildings at pre-setup points?
I'm able to create the units but they spawn at the center of the map all stacked. I think it's because my RemoveUnit() function is not running, my guess is it's trying to remove a null unit. I've had a ton of bugs lately with the editor in recognizing pre-placed units. I think it's not recognizing my pre-placed units in the script.

It's Zinc language. Similar to C
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
I'm able to create the units but they spawn at the center of the map all stacked. I think it's because my RemoveUnit() function is not running, my guess is it's trying to remove a null unit. I've had a ton of bugs lately with the editor in recognizing pre-placed units. I think it's not recognizing my pre-placed units in the script.

It's Zinc language. Similar to C
Ah, okay. I'm not too familiar with it so I can't help there...

All I can recommend doing is not pre-placing the units and avoiding the use of the RemoveUnit() function. Instead, create the buildings for the first time at those Point variables (locations) after voting has finished.
 
Level 12
Joined
Dec 2, 2016
Messages
733
Ah, okay. I'm not too familiar with it so I can't help there...

All I can recommend doing is not pre-placing the units and avoiding the use of the RemoveUnit() function. Instead, create the buildings for the first time at those Point variables (locations) after voting has finished.
What I ended up doing was creating the structures at center of rects and it's working. Thanks
 
Status
Not open for further replies.
Top