How to create COMPLEATED player units using CRPL?

Started by pawel345, January 24, 2014, 06:49:45 AM

Previous topic - Next topic

pawel345

I read somewhere that building a unit is actually increasing it's health so I tried doing it this way:


CreateUnit("Siphon" <-rx <-ry) ->unit
5 0 do
<-unit CONST_HEALTH <-unit CONST_HEALTH GetUnitAttribute 1 add SetUnitAttribute
loop



Dosn't work, it makes this siphion build 1/5.

eduran

Short answer: it's impossible. The best you can do is either make the building cost one packet or preplace the units in the editor, move them out of view and bring them back when you want to 'create' a unit.

Long answer: http://knucklecracker.com/forums/index.php?topic=14600.0 Anything about not resetting connections is resolved as of 1.66, the rest is still true.

Grayzzur

What seems to be happening, is Health is used for building when the unit has not been constructed yet. So, Health goes from zero to Build Cost, then then unit becomes built and Health immediately becomes Max Health. You can set the health for built-in units to (Build Cost - 1), and it will request one packet and become built, but that's the best you can do right now, if you don't want to change the build cost as eduran suggests.

eduran: wouldn't having units out of view cause other issues? Might they become targets for sport towers, for instance?
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

eduran

Quote from: Grayzzur on January 24, 2014, 09:44:13 AM
eduran: wouldn't having units out of view cause other issues? Might they become targets for sport towers, for instance?

I never thought about that. Spores are probably bad on a map with hidden player units. The only units I've ever placed out of view are resource packs.

pawel345

I noticed that if the Build Cost of a structure is 0 it gets build after 1 frame(no packets form CN needed). But you can't change the Build Cost with CRPL... :(

stewbasic

From reading the other threads, it sounds like the best option for making a prebuilt unit is

1) Always have a guppy offscreen with max ammo
1) Create unit next to the guppy
2) Mess with unit HP so that it only needs 1 packet
3) Wait for unit to finish building
4) Return the unit's HP to its default
5) Move unit to desired location on screen

(IIUC. Haven't actually tried this). The only problem is that off screen units are still accessible - the player could select another guppy and press O to select all guppies.

knucracker

Well I apologize for not noticing this issue and thinking about it before now.  There's no reason to have to jump through all these hoops to build player structures that are already finished with their building phase.  In tonight's build you will be able to do this:


CreateUnit("MORTAR" 10 10) ->uid
SetUnitAttribute(<-uid CONST_ISBUILDING FALSE)
SetUnitAttribute(<-uid CONST_HEALTH 999)
SetUnitAttribute(<-uid CONST_AMMO 999)


The CONST_ISBUILDING attribute was formerly limited to only operating on Crpl Towers.  I have removed this restriction so it will work on other units.  Note that I have not tested it with every unit and I don't know what will happen if you set it back to false after it has been true.  So there may be a way to get into trouble with this.  But the general case above does seem to work properly.  Note that ISBUILDING just changes that raw state on a unit.  It does not set the health and ammo to their max values.  It literally just takes the unit out of the "building" state.  So you have to set the health and ammo (if that is what you want).  You can set them to some high value and they will be clipped by the max amount.  That's where the 999 comes from in the above example.  It's just some value greater than the max.

pawel345

Triple Hooray!!! for a lighting fast response and another cool feature added to the game allowing for more interesting map to be made :D :D :D