Packet Request CPRL script Help Needed

Started by Jacobwde12, June 09, 2014, 11:10:01 PM

Previous topic - Next topic

Jacobwde12

Is there something I'm doing wrong? The tower is able to be connected to the player's network grid and accepts packets but it won't make AC as shown in the bottom of the script.

#Connectible tower
Self CONST_CONNECTABLE 1 SetUnitAttribute

# Can Request Packets
Self CONST_CANREQUESTAMMO 1 SetUnitAttribute

# Request Packets
Self CONST_REQUESTPACKETS 1 SetUnitAttribute

# Maximum number of Packets
Self CONST_MAXAMMO 10 SetUnitAttribute

#Make AC if it has packets
CONST_AMMO eq if
CurrentCoords -10 SetCreeper
endif

Crimson King

What are you comparing in your if statement?

If you want to compare the unit's current ammo to the max ammo, you'll need something like this:

...

# Maximum number of Packets
Self CONST_MAXAMMO 10 SetUnitAttribute
10 ->maxammo

#Gets current ammo
Self CONST_AMMO GetUnitAttribute ->ammo

#Make AC if it has packets
<-ammo <-maxammo eq if
CurrentCoords -10 SetCreeper
endif

I set the maxammo variable to 10 so it mimics the max ammo unit attribute. I then get the ammo attribute which returns the amount of ammo the unit currently has and store that to the ammo variable. Finally, I compare the ammo and maxammo variables and if they are equal create creeper.

If you want it to use the ammo in the process, use the SetUnitAttribute to set CONST_AMMO to 0 in the if block.

P.S. You can and probably should put your SetUnitAttribute lines in a once block. This way it doesn't set those attributes every time the code runs.

Jacobwde12

Thanks Crimson King. I'm new and don't know much code so thanks for the advice!