Author Topic: Generic Gamemode Help (Formerly: Creating AIPlayer Movement)  (Read 4384 times)

I went back and highlighted the parts you might be interested in. Specifically look at the node system in Slayer_PathHandlerSG and the pathfinding scripts in Support_Pathing.

You can look at Slayer's (very limited) implementation. It's using a modified version of Port's A* script temporarily.

Support_Pathing <- This contains the pathfinding scripts.
AiPlayer.cs <- Player-related functions - spawning, etc.
AiController.cs <- temporary AiConnection replacement
Slayer_AiController.cs <- Slayer-specific AiController - handles AI objectives
Slayer_PathHandlerSG.cs <- Manages the node system

Okay, will take a look at tomorrow, I can't code or read code when I'm sleepy.

Okay, I've done a lot of re-working that I've been putting off to get myself out of this standstill because of limited original controller functions.
Code: [Select]
datablock fxDTSBrickData (BotTileBrickData)
{
brickFile = "./Shapes/botTile.blb";
category = "Special";
subCategory = "Bot Wars";
uiName = "Bot Tile";
iconName = "./Shapes/botTile";
orientationFix = 3;
        hasPrint = 1;
printAspectRatio = "ModTer";
collisionShapeName = "./Shapes/botTile.dts";
};

function serverCmdWar(%client, %a)
{
if(%a $= "move" || %a $= "spawn")
{
%client.actionQue = %a;
messageClient(%client,'',"\c6Action type set to \c3" @ %a @".");
}
else
messageClient(%client,'',"\c6Unknown action type. (Move, Spawn)");
}

function fxDTSBrick::onActivate(%brick, %obj, %client, %pos, %dir)
{
if(%brick.getDatablock().getName() $= BotTileBrickData)
{
// if(isObject(%client.activeTroop))
// {
// if(%client.activeTroop.activeBrick $= %brick)
// {
// %client.activeTroop.delete();
// return;
// }
//
// BotWars_HandleMovement(%client.activeTroop, %brick);
//
// return;
// }
//
// %client.activeTroop = new AIPlayer(){datablock = playerstandardarmor; position = %brick.getPosition();};
// %client.activeTroop.activeBrick = %brick;
// %client.activetroop.isWarTroop = true;
//
// if(BotWars_settleMovementType(%brick) $= "water")
// {
// %client.activeTroop.movementType = "water";
// }
// else
// {
// %client.activeTroop.movementType = "ground";
// }

if(%client.actionQue $= "move")
{
if(!isObject(%client.activeTroop))
{
talk("no set troop");  //NO TROOP SET
return;
}
if(%brick $= %client.activetroop.activebrick)
{
talk("same brick"); //SAME BRICK, NO MOVEMENT
return;
}

BotWars_HandleMovement(%client.activeTroop, %brick);
return;
}

if(%client.actionQue $= "spawn")
{
if(isobject(%brick.activeTroop))
{
%brick.activeTroop.delete();  //TROOP DELETE
talk("there is active troop");
return;
}

%currentTroop = new AIPlayer(){datablock = playerstandardarmor; position = %brick.getPosition(); owner = %client; activeBrick=%brick; isWarTroop = true;};
%movementType = BotWars_settleMovementType(%brick);
%currentTroop.movementType = %movementType;
%brick.activeTroop = %currentTroop;
return;
}
}
}

package BotWars_activateStuffPackage
{
function Player::Activatestuff(%obj)
{
parent::activateStuff(%obj);
%ray = containerRaycast(%obj.getEyePoint(),vectorAdd(%obj.getEyePoint(),vectorScale(%obj.getEyeVector(),3)),$Typemasks::playerObjectType,%obj);  //Checking if the player clicked a bot
if(isObject(%col=firstWord(%ray)) && %col.isWarTroop)
{
%obj.client.activetroop = %col;
talk("set active troop");
}
}
};
activatePackage(Botwars_activateStuffPackage);

function printBrickToPrintName(%brick)
{
%texture = getPrintTexture(%brick.getPrintId());
%path = filePath(%texture);
%underscorePos = strPos(%path, "_");
%name = getSubStr(%path, %underscorePos + 1, strPos(%path, "_", 14) - 14) @ "/" @ fileBase(%texture);
if($printNameTable[%name] !$= "")
%f = %name;
return %f;
}


function BotWars_HandleMovement(%troop, %brick)
{
%bricktype = BotWars_settleMovementType(%brick);
%trooptype = %troop.movementType;
if(%bricktype !$= %trooptype)
{
talk("Can't go");
return;
}
talk("movement pass"); //MOVEMENT HERE
}

function BotWars_settleMovementType(%brick)
{
%name = printBrickToPrintName(%brick);
if(%name $= "ModTer/defaultwater")
return "water";
else
return "ground";
}

Are all the necessary variables being carried along to continue to the actual movement part?
Suggestions on what to change to make my life easier?
Anything that sticks out as dumbly made? (Oh boy, this should be fun :P)

I don't see anything obviously wrong there, but I don't really see anything related to actually moving the bot.

I am making sure that I am not leaving out important variables or info I should be passing along for the movement part.

I am making sure that I am not leaving out important variables or info I should be passing along for the movement part.

I feel like you should be able to figure this one out. What does the movement require? something to move, a source, and a destination

I have no idea what I am doing. Like, to give you an idea, I don't even know what to say I don't understand because I am not really even sure where I should begin. I'm using a Hexagon field, if that matters.

I'm slightly confused....why can't you just use events to make the bots move?

I'm slightly confused....why can't you just use events to make the bots move?
Because this section of the forums is Coding Help.. (joke)

Because this section of the forums is Coding Help.. (joke)

I know but making bots move where you want them is simple enough in-game without over complicating their movement via code. I think I understand the basics of what he's doing. Basically, the bot moves on the grid in a direction (north, east, south, or west) but only move one unit at a time (provided this is turn based)

It's like a bot wars thing (which is always fun)


Because that wouldn't work at ALL for my purpose and the scale I want to take this to.

I have no idea what I am doing. Like, to give you an idea, I don't even know what to say I don't understand because I am not really even sure where I should begin. I'm using a Hexagon field, if that matters.
The first thing that you need to do is to create a node system. Look at Slayer_PathHandlerSG above. Each brick should have/be its own node. You have two options here: either make each brick be the node and watch for when the bot touches the brick, or create a zone above each brick and wait for the bot to enter it.

I saw the bricks for this project btw and I like where I think it's going.
« Last Edit: March 30, 2015, 10:19:38 PM by Greek2me »

Quote
==>exec("Add-Ons/Gamemode_Slayer/Server.cs");
-exec snip-
Executing Add-Ons/Gamemode_Slayer/server/dependencies/nodes.cs.
-more exec snip-
Direct load saves/hexafield.bls, 3, 0, 1,
LOADING BRICKS: saves/hexafield.bls (ColorMethod 3)
==>new AIPlayer(asdf){datablock=playerstandardarmor;position="0 0 0";};
==>//23605 is a hex brick
==>Slayer_PathHandlerSG::addNode(asdf.getID(), 23605);

Add-Ons/Gamemode_Slayer/server/dependencies/nodes.cs (33): Unable to find object: '' attempting to call function 'isMember'
BackTrace: ->ConsoleEntry::eval->Slayer_PathHandlerSG::addNode


Add-Ons/Gamemode_Slayer/server/dependencies/nodes.cs (42): Unable to find object: '' attempting to call function 'add'
BackTrace: ->ConsoleEntry::eval->Slayer_PathHandlerSG::addNode

Add-Ons/Gamemode_Slayer/server/dependencies/nodes.cs (45): Unknown command findLinks.
 
What am I doing wrong?


You really can't reuse the system from Slayer. You'll need to create your own, although you can use Slayer's as a reference.