Making Friendly Units

Started by CobraKill, May 20, 2013, 10:52:27 PM

Previous topic - Next topic

CobraKill

Is it possible to get CLPR cores to request packets from a network?

I have absolutely no idea how to code these things other than basic creeper commands. I have no knowledge of the extant of how much the scripts can do. I'm hoping to create two units in a custom map I'm working on. I want to make a beam tower that can damage creeper. I'm also want to create a maker that requests AC and energy. How would I do this?
Never trust a computer that doesn't fit through your nearest window.

Hunter Seeker

Currently a CRPL core can not attach to a player network directly but i used a roundabout way to achieve what you are trying to accomplish.  Virgil has mentioned a possibility of adding such a feature but nothing is in the current build.

This is a script i used to make a windmill that is powered by the player:

# Mpower.crpl
# Created on: 5/15/2013 12:16:18 PM
# ------------------------------------------
#use var $Name on unit to be powered
$NamePowered:"Name"
#Powered Scriptname is the name of the script (include .crpl)
$PoweredScriptName:"Name"
#Powered Scriptname needs to have the following predefinded variables: $Power $Name
once
SetUnitAttribute(Self CONST_TAKEMAPSPACE 1)
SetUnitAttribute(Self CONST_NULLIFIERDAMAGES 0)
SetUnitAttribute(Self CONST_CREATEPZ 0)
SetUnitAttribute(Self CONST_SUPPORTSDIGITALIS 0)
SetUnitAttribute(Self CONST_COUNTSFORVICTORY 0)
SetImagePositionZ(Self "main" -0.1)
endonce

once
#attach to preselected object
GetUnitsInRange(CurrentCoords 2)
if(1 eq)
->PoweringUID
else
#this means more than 1 unit is at starting location, or no unit
ClearStack
endif

GetCoresWithVar("Name" <-NamePowered)
1 eq if
->PoweredUID
else
#this means more than 1 unit has this name, or no unit
ClearStack
endif
#clear starting ammo
SetUnitAttribute(<-PoweringUID CONST_AMMO 0)
endonce

GetUnitAttribute(<-PoweringUID CONST_AMMO)->ammo
if(<-ammo 1 gte)
SetUnitAttribute(<-PoweringUID CONST_AMMO <-ammo 1 sub)
SetScriptVar(<-PoweredUID <-PoweredScriptName "Power" add(1 GetScriptVar(<-PoweredUID <-PoweredScriptName "Power")))
endif


This takes 1 ammo from the player unit for one "power".  In the code the CRPL attaches itself to whatever player unit is located at the same location as the CRPL core at the start of the map.  You can modify this code to apply to AC or to be able to attach to different units if you wanted.  If you wanted to see how the code looked in the map look at my Wind map I have in the CW3 custom map section.  I also changed the image of the CRPL core to be something that looked more like a unit that i was trying to go for.  The map i created had no runner units so i used snipers as the player unit.  For AC ammo you would need to use sprayers or bombers as the player unit.  If you had more questions about my code or something similar let me know and i will see how i can help.
Aspire to Inspire

CobraKill

Never trust a computer that doesn't fit through your nearest window.

knucracker

Yes... that was a very clever way to get a 'friendly'  CRPL unit.  It was something I never thought about doing myself... and I like seeing things like that :)

I could probably add support for network connected CRPL cores that can request packets.  That is one part of a friendly unit.  Allowing a unit to be selected and moved and all of that is another part that is separate from "connectable".  Time permitting this week before the next build I'll at least look at the connectable capacity to see if it is simple or difficult to implement.

Grauniad

I think you should shelve the entire 'friendly unit" issue for post-release. It is not on the critical release path, regardless of how much time/effort it takes.
A goodnight to all and to all a good night - Goodnight Moon

J

#5
Here's another way to make friendly units:

Script 1:
"TOTEM" CurrentCoords CreateUnit ->totemUID
"totem" ->unitName
4 delay self 0 Destroy


Script 2:once
2 delay
"unitName" "totem" GetCoresWithVar dup ->totemcount 0 do
"totem.crpl" "totemUID" getScriptVar
"totem" I concat ->!
loop
endonce

0 ->activecount
<-totemcount 0 do
"totem" I concat <-! dup ->unitUID CONST_AMMO GetUnitAttribute
0 gt if
<-activecount 1 add ->activecount
<-unitUID CONST_AMMO <-unitUID CONST_AMMO GetUnitAttribute 0.1 sub SetUnitAttribute
ShowTraceLog
"ACTIVE" Trace
<-activecount Trace
endif
loop


You can put as many cores with script 1 on the map as you want. One (another) core should get script 2. The variable activecount keeps track of the amount of active totems. Use that to expand the script with the right behaviour. The script might not work correctly right now, I'll have to wait till the next build before I can continue debugging. Forge should be disabled when using this.

TrickyDragon

I also believe this should be post release.  Also, being able to select and move te cell could be another option.  Could make some "super weapon" scripts or such, and not being able to move them can add to strategy.
This is Life,  Life happens.

knucracker

Quote from: J on May 21, 2013, 10:38:38 AM
Here's another way to make friendly units:

Script 1:
"TOTEM" CurrentCoords CreateUnit ->totemUID
"totem" ->unitName
4 delay self 0 Destroy


Script 2:once
2 delay
"unitName" "totem" GetCoresWithVar dup ->totemcount 0 do
"totem.crpl" "totemUID" getScriptVar
"totem" I concat ->!
loop
endonce

0 ->activecount
<-totemcount 0 do
"totem" I concat <-! dup ->unitUID CONST_AMMO GetUnitAttribute
0 gt if
<-activecount 1 add ->activecount
<-unitUID CONST_AMMO <-unitUID CONST_AMMO GetUnitAttribute 0.1 sub SetUnitAttribute
ShowTraceLog
"ACTIVE" Trace
<-activecount Trace
endif
loop


You can put as many cores with script 1 on the map as you want. The variable activecount keeps track of the amount of active totems. The script might not work correctly right now, I'll have to wait till the next build before I can continue debugging. Forge should be disabled when using this.

So you are turning a CRPL core into a Totem (kinda of), then milking the totems for ammo.  That should in theory work in the next build since I added the checkbox to totems that allows them to charge even if there is no forge.  I color totem packets green, but they still add to the 'ammo'  reserves on the totem.  So that they are green shouldn't make any difference.  Nice use of the reflection operators ( <-! and ->! ), btw.

Hunter Seeker

code Cobra and I developed for AC instead of ammo:
changes to Mpower.crpl were 2 instances of CONST_AMMO to CONST_AMMOAC:

# Mpower.crpl
# Created on: 5/15/2013 12:16:18 PM modified 5/23/13 to AC
# ------------------------------------------
#use var $Name on unit to be powered
$NamePowered:"Name"
#Powered Scriptname is the name of the script (include .crpl)
$PoweredScriptName:"Name"
#Powered Scriptname needs to have the following predefinded variables: $Power $Name
once
SetUnitAttribute(Self CONST_TAKEMAPSPACE 1)
SetUnitAttribute(Self CONST_NULLIFIERDAMAGES 0)
SetUnitAttribute(Self CONST_CREATEPZ 0)
SetUnitAttribute(Self CONST_SUPPORTSDIGITALIS 0)
SetUnitAttribute(Self CONST_COUNTSFORVICTORY 0)
SetImagePositionZ(Self "main" -0.1)
endonce

once
#attach to preselected object
GetUnitsInRange(CurrentCoords 2)
if(1 eq)
->PoweringUID
else
#this means more than 1 unit is at starting location, or no unit
ClearStack
endif

GetCoresWithVar("Name" <-NamePowered)
1 eq if
->PoweredUID
else
#this means more than 1 unit has this name, or no unit
ClearStack
endif
#clear starting ammo
SetUnitAttribute(<-PoweringUID CONST_AMMO 0)
endonce



GetUnitAttribute(<-PoweringUID CONST_AMMOAC)->ammo
if(<-ammo 1 gte)
SetUnitAttribute(<-PoweringUID CONST_AMMOAC <-ammo 1 sub)
SetScriptVar(<-PoweredUID <-PoweredScriptName "Power" add(1 GetScriptVar(<-PoweredUID <-PoweredScriptName "Power")))
endif

this makes 1 AC per AC drained:

# AC.crpl
# Created on: 5/23/2013 8:11:00 PM
# ------------------------------------------

$Name:"AC"
$Power:0

once
SetUnitAttribute(Self CONST_TAKEMAPSPACE 1)
SetUnitAttribute(Self CONST_NULLIFIERDAMAGES 1)
SetUnitAttribute(Self CONST_CREATEPZ 1)
SetUnitAttribute(Self CONST_SUPPORTSDIGITALIS 0)
SetUnitAttribute(Self CONST_COUNTSFORVICTORY 0)
endonce

AddCreeper(CurrentCoords <-Power -1 mul)
0 ->Power
15 delay

Aspire to Inspire