How to create a finished building?

Started by kai, November 06, 2013, 02:44:38 AM

Previous topic - Next topic

kai

I can't figure out how to create a finished building friendly unit...
Using createUnit will create an unfinished building
and I can't set CONST_ISBUILDING to false because it is not a tower

Any idea ???

Grayzzur

The best I can come up with is make it cost 1 to build, but it's a lot of effort.

When a unit IsBuilding, its Health is used to determine how many packets it has received, so if the BuildCost is 20, health will rise up by 1 for each packet, and once it hits 20 and is built, Health resets to MaxHealth.

You can change the Health, and if you do this before it's built you can affect how many more packets it needs; however, if you set Health equal to BuildCost it will just sit there IsBuilding=TRUE and not request any more packets and be stuck in that state. The other catch is you can't set Health > MaxHealth.

A Collector has a BuildCost of 5 and a MaxHealth of 0.

We can set MaxHealth and Health to 4 right after CreateUnit, it will request 1 packet and finish building, but then it will also be a very healthy collector. You can go back and reset MaxHealth to 0, but you have to wait until after the Collector has been built or Health will also drop down and it will want 5 more build packets.

"COLLECTOR" x y CreateUnit ->unitID
<-unitID CONST_MAXHEALTH 4 SetUnitAttribute
<-unitID CONST_HEALTH 4 SetUnitAttribute


You could use something like this to scan for overly health built collectors and set them back to zero, though maybe you wouldn't want to do it every update cycle.

MapWidth 2 div ->cx
MapHeight 2 div ->cy
MapWidth MapHeight max 1 add ->range
# Loop through every unit on the map
<-cx <-cy <-range TRUE GetAllUnitsInRange 0 do
->unitID
<-unitID GetUnitType "COLLECTOR" eq if
#If not ISBUILDING and MAXHEALTH>0
<-unitID CONST_ISBUILDING GetUnitAttribute not <-unitID CONST_MAXHEALTH 0 gt and if
<-unitID CONST_MAXHEALTH 0 SetUnitAttribute
endif
endif
loop


Not exactly the answer you were looking for.

I'm not sure if what you want to do is possible with the current state of CRPL. Virgil or someone else may need to weigh in on that.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

kai

Quote from: Grayzzur on November 06, 2013, 09:29:15 AM
We can set MaxHealth and Health to 4 right after CreateUnit, it will request 1 packet and finish building, but then it will also be a very healthy collector. You can go back and reset MaxHealth to 0, but you have to wait until after the Collector has been built or Health will also drop down and it will want 5 more build packets.

It's a funny idea, and I observe that the health > maxhealth can only happen by sending packet to it, but not through SetUnitAttriable......
Also, setting the health to something like 4.9 is same as 4, having 20 of them will require 20 packet, not 20*0.1=2 packet

maybe a future patch include some function that can finish a building?

Annonymus

If you can find a way to move player buildings you could apparently create finished buildings by placing them on the map at a place the player will never be able to access but hide it and when you need to "build" it move it to where you want it.
If a topic started by me is in the wrong place feel free to move it at anytime.

eduran

You can move player units by setting their CONST_COORDX/Y attributes, but that does not reset their connections. So if you move a building from somewhere outside the map into range of the player it won't connect to his network until he builds a new unit in range of the moved one. Even worse, the moved building will stay connected to everything that was in range of it before it was moved until it is destroyed.

Relli

Quote from: eduran on November 22, 2013, 02:15:47 PM
You can move player units by setting their CONST_COORDX/Y attributes, but that does not reset their connections. So if you move a building from somewhere outside the map into range of the player it won't connect to his network until he builds a new unit in range of the moved one. Even worse, the moved building will stay connected to everything that was in range of it before it was moved until it is destroyed.
But toggling their Connectability should redo their connections. Doing so constantly would destroy incoming packets, but doing it only when first moved into range, it shouldn't make a difference.

eduran

That only works for CRPL cores, not player units.

MadMag

#7
Created a finished building in PS in just a couple of minuttes... I guess you want the tutorial now ::)

Clean0nion

Quote from: MadMag on November 22, 2013, 04:03:24 PM
Created a finished building in PS in just a couple of minuttes... I guess you want the tutorial now ::)
My working Ore Refinery uses 4 separate scripts. How many does this use?

Annonymus

previous connection s shouldn't be a problem if the building is somewhere the player has no access to, but if by ore refinery you don't mean an ore mine i can't see why you should need to build friendly units, since the refinery will have to be a CRPL tower anyways.
depending on what conditions the building has to be built maybe you could find a way around the connectivity bug.
If a topic started by me is in the wrong place feel free to move it at anytime.