Help regarding AI script not working

Jesus4Lyf

Good Idea™
Reaction score
397
Seems silly asking why it doesn't work, but hey, why not...
JASS:
//==================================================================================================
// 
// Map Script
// 
// Name:   First TD
// Author: Jesus4Lyf
// 
//==================================================================================================

//--------------------------------------------------------------------------------------------------
// Libs
//--------------------------------------------------------------------------------------------------
include "TriggerLibs/NativeLib"
//include "TriggerLibs/natives"

void InitLibs () {
    libNtve_InitLib();
}

//--------------------------------------------------------------------------------------------------
// Snippets
//--------------------------------------------------------------------------------------------------
void WriteLine(string message){
    UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,StringToText(message));
}
void WriteError(string message){
    WriteLine("ERROR: "+message);
}

unitgroup PlayerUnits(int player){
    return AIFindUnits(player,null,Point(0,0),500000,c_noMaxCount);
}

void SpawnThread(string funcName){
    TriggerAddEventMapInit(TriggerCreate(funcName));
}

int IssuePointOrder(unit whichUnit, string abilLink, point targPoint) {
    abilcmd cmd=AbilityCommand(abilLink,0);
    order ord;
    
    if (cmd==c_nullCmd){
        WriteError("null abilcmd returned from AbilityCommand(abilLink,0).");
    }
    
    ord = Order(cmd);
    
    if (ord==null){
        WriteError("null order returned from Order(cmd).");
    }
    
    OrderSetPlayer(ord,UnitGetOwner(whichUnit));
    OrderSetTargetPoint(ord,targPoint);
    
    if (!UnitOrderIsValid(whichUnit,ord)){
        WriteError("order not valid for unit.");
    }
    
    return AICast(whichUnit,ord,c_noMarker,c_castHold);
}
void IssuePointOrderGroup(unitgroup src, string abilLink, point targPoint){
    int count=UnitGroupCount(src,c_unitCountAll);
    while(count>0){
        IssuePointOrder(UnitGroupUnit(src,count),abilLink,targPoint);
        count-=1;
    }
}

// Countdown Timer
int countdownTimer=30;
void onCountdownExpire();
bool threadCountdownUpkeep (bool testConds, bool runActions) {
    while(true){
        UIDisplayMessage(PlayerGroupAll(),2,StringToText(IntToString(countdownTimer)));
        Wait(1,0);
        countdownTimer-=1;
        if(countdownTimer==0){
            onCountdownExpire();
        }
    }
    return true;
}

//--------------------------------------------------------------------------------------------------
// Code
//--------------------------------------------------------------------------------------------------
void onCountdownExpire(){
    WriteLine("The Zerglings! They come!");
    AIStart(2, false, 4000);
    IssuePointOrderGroup(PlayerUnits(2),c_AB_Move,Point(80,80));
}

//--------------------------------------------------------------------------------------------------
// Melee Initialisation
//--------------------------------------------------------------------------------------------------
bool gt_MeleeInitialization_Func (bool testConds, bool runActions) {
    MeleeInitResources();
    MeleeInitUnits();
    MeleeInitAI();
    MeleeInitOptions();
    return true;
}

//--------------------------------------------------------------------------------------------------
// Trigger Initialisation
//--------------------------------------------------------------------------------------------------
void InitTriggers () {
    SpawnThread("gt_MeleeInitialization_Func");
    SpawnThread("threadCountdownUpkeep");
}

//--------------------------------------------------------------------------------------------------
// Map Initialisation
//--------------------------------------------------------------------------------------------------
void InitMap(){
    InitLibs();
    InitTriggers();
}

In my map I have 20 Zerglings owned by player 2, which are successfully enumerated into a group. Unfortunately, when they should be issued an order, nothing happens. The text displays, etc, but the Zerglings just don't move. :(

Any ideas?
 

UndeadDragon

Super Moderator
Reaction score
447
Do you get any of the errors which you included in your IssuePointOrder function?
 

Romek

Super Moderator
Reaction score
963
It seems a bit silly asking for help here when none of us even have an editor, let alone a complete list of natives. :p
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
Is Point(80,80) an invalid location? (as in: Somewhere no unit can go except for air units).

Has player 2 been defeated and thus won't his units move anymore?

Have you activated some wrong AI thing that takes full control of the zerglings and doesn't allow for other commands?

Try to do killunit instead of a command on every zergling to see if it reaches that far (and thus you probably have the wrong constant for moving)

Not implemented yet / bug?



Come on guys be creative, this guy needs help and we are his only hope :p.
 

Sholdak

New Member
Reaction score
1
I've been trying the same thing, with similar results. It seems AICast has to be called within the correct AI thread, which makes sense of course. It would be weird if 1 AI could control another player's units.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Does OrderSetTargetPoint() work? Just out of curiosity..

JASS:
// Map Script
// 
// Name:   First TD
// Author: Jesus4Lyf


VERY CREATIVE. :D
 

Jesus4Lyf

Good Idea™
Reaction score
397
I've been trying the same thing, with similar results. It seems AICast has to be called within the correct AI thread, which makes sense of course. It would be weird if 1 AI could control another player's units.
How do you put something into an AI thread, let alone start an AI thread?
 

Steel

Software Engineer
Reaction score
109
I'm with Romek here. Why are you asking people here? Seems kind of silly....

Why are you putting in so much effort to these things when you have absolutely no idea what will be finalized? They're just ripped from SC2.exe. Maybe I'm just being rude here but unless someone actually has their hands on the editor, there isn't any reason to start doing these things yet. Do you have the editor?

TDG's leader, Chunk, was lucky enough to help a bunch of us get into the beta. Membership has perks! (/shameless promotion for TDG) We are hoping for early access to the editor to start debugging things quickly. A contact of Chunk's actually sent me out an email today and hopes to get us the editor, if possible. So as far as I know, no one has access to it yet.

Not trying to be snide, but this is like if you're going to work on a new programming language that is coming out and you don't know what is going to happen with it. If they release something for you to look at and work with, then they want you to start toying with it and learning it. If they don't release anything, they don't want you to see it because it isn't done or ready at all.
 

UndeadDragon

Super Moderator
Reaction score
447
man you have editor on your beta ??
how you can test this
??

He imports the script into a map using an MPQ editor and tests it through the game, like normal.
 

Sholdak

New Member
Reaction score
1
After further testing, AICast seems to work fine in the mapscript, but only for players that are actively controlled by an AI. It doesn't seem work on neutral players (or players that aren't in the map) or human-controlled units.

It doesn't seem to work on workers (maybe because they are constantly gathering?) or on units built by the AI.


Code:
unitgroup MyGroup;
unit bc;
order o;
bool valid_o;

bool order_func (bool testConds, bool runActions) {
	int i;	
	o = Order(AbilityCommand("move",0));
	OrderSetTargetPoint(o,Point(150,150));

	Wait (3,0);
	while(true)
	{
		MyGroup = PlayerUnits(2);
		i = UnitGroupCount(MyGroup, 1);

		while (i>0){
			bc = UnitGroupUnit(MyGroup, i);

			valid_o = UnitOrderIsValid(bc, o);
			if(valid_o){		
				AICast(bc,o,c_noMarker,false);
			}
			i = i-1;
		}

	TriggerDebugOutput(1, StringToText("units ordered"), true);
	Wait(2,0);
	}

	if (runActions) {
        
    	}
	
	return true;
}



//--------------------------------------------------------------------------------------------------
void gt_MeleeInitialization_Init () {
    gt_MeleeInitialization = TriggerCreate("gt_MeleeInitialization_Func");
    TriggerAddEventMapInit(gt_MeleeInitialization);
    TriggerAddEventMapInit(TriggerCreate("order_func"));
}

Basically with this I managed to move Overlords and extra pre-placed units added in the Objects file to the map.

None of this is terrible useful though since we still have no way to create/destroy anything.

Btw, not sure if anyone has mentioned this yet, but the new Trigger Debugger in SC2 is pretty useful. You can view all current global variables, running threads, constants, etc. Presumably we'll be able to set breakpoints inside script once we get the editor.
 

peq

New Member
Reaction score
1
None of this is terrible useful though since we still have no way to create/destroy anything.

We can use the SpawnLarva Behavior to spawn new units periodically (works fine). If we manage to issue upgrade orders to buildings this could be used to automatically spawn creeps for a TD.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top