I need help yet again with a fake ore packet. All i need is help for finding the exact location in terrain cells where a collector or relay is in a ten cell radius. I don't have much experience with CRPL so i have no idea what to put next in my code to have it find a collector or relay nearby. Here is my code so far...
# OrePacket.crpl
# Created on: 11/7/2015 7:59:41 PM
# ------------------------------------------
$Range:10
$Speed:2
once
Self CONST_CONNECTABLE 0 SetUnitAttribute
Self CONST_CREATEPZ 0 SetUnitAttribute
Self CONST_DESTROYMODE 0 SetUnitAttribute
endonce
CurrentCoords <-Range GetUnitCountInRange do
GetUnitType "COLLECTOR" eq if TRUE endif
GetUnitType "RELAY" eq if TRUE endif
loop
Any help is greatly appreciated! :)
This will get all collecters and relays within Range and put them in a list:
# Gets a list of all collectors and relays within Range
CreateList ->List
CurrentCoords <-Range GetUnitsInRange 0 do # Gets all units in Range, then loops through them
->UnitID # stores the UnitID
if (<-UnitID GetUnitType "COLLECTOR" eq <-UnitID GetUnitType "RELAY" eq or) # checks if unit type is a collector or relay
<-List <-UnitID AppendToList
endif
loop
Quote from: Hubs on November 11, 2015, 08:06:21 AM
This will get all collecters and relays within Range and put them in a list:
# Gets a list of all collectors and relays within Range
CreateList ->List
CurrentCoords <-Range GetUnitsInRange 0 do # Gets all units in Range, then loops through them
->UnitID # stores the UnitID
if (<-UnitID GetUnitType "COLLECTOR" eq <-UnitID GetUnitType "RELAY" eq or) # checks if unit type is a collector or relay
<-List <-UnitID AppendToList
endif
loop
Thanks! It works! :)
Quote from: Hubs on November 11, 2015, 08:06:21 AM
This will get all collecters and relays within Range and put them in a list:
# Gets a list of all collectors and relays within Range
CreateList ->List
CurrentCoords <-Range GetUnitsInRange 0 do # Gets all units in Range, then loops through them
->UnitID # stores the UnitID
if (<-UnitID GetUnitType "COLLECTOR" eq <-UnitID GetUnitType "RELAY" eq or) # checks if unit type is a collector or relay
<-List <-UnitID AppendToList
endif
loop
But how would i have the packet locate where the collector or relay is so it can move to it?
Sorry if i am asking to much. :P Nvm i found a way on how to do it.
GetUnitAttribute for X and Y coordinate.
Quote from: Hubs on November 11, 2015, 09:42:09 PM
GetUnitAttribute for X and Y coordinate.
Yeah, that's what I did. I did not realize that there was a unit attribute for coords :P