Game Development Community

Writing a script for kork

by Joel Hargarten · in Torque Game Engine · 11/08/2005 (12:32 pm) · 13 replies

Ok, I've managed to get kork to stop running around, but now he doesnt do anything. How do I write a specific list of actions for him to do? I want him to: attack, jump, run forwards, attack, run backwards, jump, attack. I see in aiplayer.cs that there is function called 'fire' but I don't know how to activate it, or where to call it from. But I need kork to do this specific series of actions, is there anyplace I can just list the right commands one after another and he'll use them? And I also need to know what the right commands for each action is. I know this is a lot, but any help would be great. Thanks.

#1
11/08/2005 (1:01 pm)
I'm at work so this is by memory, I appologize for wrong information.

If you get korks ID number, you can call those functions like this: assume for this example that korks ID is 1606. To call the "fire" function 1606.fire(); It may or may not need any variables passed to it. To make a command for kork to run backwards, you will probably have to create one for that.


Examine the fire function you found in aiplayer.cs. You'll notice most if not all of the functions will have "%this" as the first argument. "%this" is pretty much a standard variable used for the object calling the function.

Try using the fire function as a starting point for your other functions, and ask questions when you get lost.
Good luck :]
#2
11/08/2005 (1:45 pm)
Do a dump of kork to get the entire list of avaialbe commands.

kork.dump();


also in aiplayer.cs find

function AIManager::think(%this)



that function constantly runs for each AI, using that you have set conditions for him doing stuff.
#3
11/08/2005 (2:27 pm)
Ok, I've been able to call the fire command from the AIManager::think(%this), but I'm not sure that the aiplayer's fire function actually does anything. because I called the function, it gives me a couple of error's in the dump() and it doesnt do anything. It just gives me these error's:
starter.fps/server/scripts/aiplayer.cs (179): Unknown command setImageTrigger.
    Object AIManager(1449) AIManager -> ScriptObject -> SimObject
starter.fps/server/scripts/aiplayer.cs (180): Unknown command setImageTrigger.
    Object AIManager(1449) AIManager -> ScriptObject -> SimObject
starter.fps/server/scripts/aiplayer.cs (205): Unknown command nextTask.
    Object AIManager(1449) AIManager -> ScriptObject -> SimObject
#4
11/08/2005 (2:34 pm)
Can you show the code you inserted into AIManager::think(%this).

But if I guess I'd say that you are issuing command directly to ID number: something like
1449.setMoveDestination.....If you do you can't do that directly in script, cos TGE assign different ID number when it spawns kork.

This is working only in console when you know ID number of Kork.

I would reccomend you to get 3D Games programming all in one book. It will boost your start with TGE. Recently there is also Advanced 3D game programming all in one (you can find more about AI in there).
#5
11/08/2005 (2:37 pm)
I'm using this command:
AIPlayer::fire(%this,true);
#7
11/09/2005 (10:07 am)
This isn't working. even now when I call all of the funtions properly, and it doesnt give me any errors, kork just stands there and does nothing. I added this command into 'think':
AIPlayer::setImageTrigger(%this,0,true);
Its supposed to make the aiplayer fire, but it isnt working. any ideas?
#8
11/09/2005 (10:19 am)
You'll want to do something like that, rather:
%this.player.pushTask("fire(true)");
#9
11/09/2005 (10:55 am)
That doesnt work for me either, I had to change it to %this.player.pushTask(%this,"fire(true)"); just to get it to read properly, but kork still just sits there. here is my 'think' function:
function AIManager::think(%this)
{
   // We could hook into the player's onDestroyed state instead of
   // having to "think", but thinking allows us to consider other
   // things...
   if (!isObject(%this.player))
      %this.player = %this.spawn();

	%this.player.pushTask(%this,"fire(true)");
	
   %this.dump();
%this.schedule(500,think);

  
}

anything wrong?
#10
11/09/2005 (11:00 am)
Yes, it belongs into the 'if' case.
if (!isObject(%this.player))
   {
      %this.player = %this.spawn();
      %this.player.pushTask("wait(5)");
      %this.player.pushTask("setMoveDestination(\"3 4 0\")");
      %this.player.pushTask("fire(true)");
   }

   %this.schedule(500,think);

For some reason I also had to comment out the line with 'schedule' in the singleShot method of AIplayer.
[edit]
you need the wait five to actually see it happen. When I comment that out, the shot is long gone before the player is able to see it.
#11
11/09/2005 (11:38 am)
Thanks a lot Dirk, that works great! now I'll have to tweak it so that it does everything I want, but this is the base of everything I need the AI bot to do. Thanks. Now, can someone explain to me what the parameters in 'setMoveDestination(\"3 4 0\")' are? thanks again!
#12
11/09/2005 (11:43 am)
X y z coordinates. Glad I could help.
#13
11/10/2005 (8:01 pm)
Ok, now that kork can fire, how do I get him to fire at other bots? I noticed that there is a function called aimAt(), does this do that? Also, I don't want kork to just focus on one character, I want him to attack any character that gets near him. What method is used for this?