Page 1 of 1

Idle SCV to gather minerals

Posted: Wed Jan 12, 2011 5:57 am
by abhisheknage
Hey Guys,

Firstly this is my first post here, and I am an ultra noob in coding.

My problem is I am unable to have idle/just spawned SCV's to gather minerals.

This is my code here:

for(std::set<Unit*>::const_iterator i= Broodwar->self()->getUnits().begin();i!=Broodwar->self()->getUnits().end();i++){
//Broodwar->sendText("collecting all units information");
if ((*i)->getType().isWorker())
if ((*i)->isGatheringMinerals()){
Broodwar->sendText("is gathering minerals");

Unit* closestMineral=NULL;
Broodwar->sendText("getting free workers1");
for(std::set<Unit*>::iterator m=mineralFieldsLeft.begin();m!=mineralFieldsLeft.end();m++)

if (closestMineral==NULL || (*i)->getDistance(*m)<(*i)->getDistance(closestMineral))

if (closestMineral!=NULL){

mineralFieldsList is already defined, but it seems that when it's playing starcraft, the message getting free workers does show up, but I don't know now what to do, because the free worker won't mine minerals.

Any help would be greatly appreciated.


Posted: Wed Jan 12, 2011 7:11 am
by krasi0
When do you use this code? in onStart or onFrame? If it's onFrame, know that it takes a few frames for the SCV to head to the minerals so (*i)->isGatheringMinerals() may return false for a while.

Posted: Wed Jan 12, 2011 9:39 am
by abhisheknage
hi krasi0,

Well i am using it on onFrame, and i found out where i made the mistake though. Else if((*i)->isIdle && (*i)->isCompleted)
I guess i shud have added tht. But now it works.