Multi Spore Code

Started by Aeran01, November 19, 2014, 02:52:38 PM

Previous topic - Next topic

Aeran01

Hi everyone I'm a new user from Mexico and I play CW3 since a year more or less (I was playing with a 1.04 version free xD then I bought it like a week ago then I start with CRPL) well this morning I was trying to make a ACSpore maker that in the Script window we can input the Payload of AC and the payload is the same as the ammo needed so if we input -10 payload the ammo needed to make it work is 10 same if we input -2500 the ammo needed will be 2500 that was working perfectly but when I need to make many spores at once I didn't know how so I used a while to make it


$Spores:0
$ACPayload:0

Once
Self CONST_CONNECTABLE 1 SetUnitAttribute
Self CONST_CANREQUESTAMMO 1 SetUnitAttribute
Self CONST_REQUESTACPACKETS 1 SetUnitAttribute
Self CONST_ACPACKETREQUESTDELAY 1 SetUnitAttribute
<-ACPayload mul(-1) ->ACPayloadPos
Self CONST_MAXAMMOAC <-ACPayloadPos SetUnitAttribute
0 ->Counter
Endonce
Self CONST_AMMOAC GetUnitAttribute ->ammoac
if (<-ammoac eq(<-ACPayloadPos))
while <-Counter neq(<-Spores) repeat
CurrentCoords RandCoords 1 <-ACPayload CreateSpore
<-Counter add(1) ->Counter
endwhile
0 ->Counter
0 ->ammoac
Self CONST_AMMOAC <-ammoac SetUnitAttribute
endif


Well the first is to make a user defined vars we need only 2
Spores to input the number of spores we want each time
ACPayload to input the amount of AC each spore will have (In negative numbers)

I think I dont need to explain the first four commands of Once so I'll explain the 5th

<-ACPayload mul(-1) ->ACPayloadPos This makes to inverse the negative number of the payload and keep it on another var so when we define the max ammo is a positive number as big as the one we input (This makes the user can define the var only once)

Then we define a new Var Counter (I'll explain it later)

We finish now the Once-Endonce commands

Self CONST_AMMOAC GetUnitAttribute ->ammoac with this in the begining each change make it to keep it on another var so we can use it freely

Then the conditional

if (<-ammoac eq(<-ACPayloadPos)) This makes that the spore maker send spores ONLY when the ammo reach the max

Then we have the loop

while <-Counter neq(<-Spores) repeat
   CurrentCoords RandCoords 1 <-ACPayload CreateSpore
   <-Counter add(1) ->Counter
endwhile

This loops makes that we can input many spores without making it manualy so we dont have to make 10 lines of code to make 10 spores only we input it in the Spore var and the game makes it automaticaly to make this we add 1 to the counter so when the Counter reach the value of Spores the loop finish and continue reseting the counter with 0 ->Counter and the ammo var with
0->ammoac then with the Self CONST_AMMOAC <-ammoac SetUnitAttribute we reset the CRPL Ammo

I think i'ts all for now I post this because im kind of noob in CRPL and some other players too xD and yes im Mexican but I like to make my codes in english see ya!

Hubs

#1
You would be better off with a do loop:

#number of spores to make:
5 ->spores

#loop through to create each spore
<-spores 0 do
     #create spore code goes here
loop

Check out the crpl reference on the wiki for more info on do loop

Aeran01

I see thank you Im a noob in CRPL xD