Author Topic: AI control of Playerobject  (Read 2161 times)

This has a multitude of uses if we can get it working right, servers where when a player disconnects, the bot takes over to maintain continues teamcount, where a player can become "rabid" or what have you and loose control temporarily, etc.

I am right in suspecting that AIplayer is just an inherited player with additional functionality to run on it's own?
Thus it has no associated client, wherin if you assign a client to that aiplayer, you can override the commands, and that works fine and dandy in all my tests. But I am having trouble achieving the reverse.

My best guess right now is that I have to just copy all the information from the player, delete it, spawn a AI player of duplicate information, and mount the camera to that ai player until the duration expires, and then switch it all back. I can see this causing alot of problems though if used with other mods that might override the spawnfunction to determine scoring or whatever.

Is there anyway to dynamically apply the components to make the player act through standard AI without having to basically overwrite all the holebot package components to also include players under the circumstance they are lacking a client? I mean thats doable but rather bulky for the smallscale unobtrusive implementation I was hoping for.

Slayer basically does this. Here's some code. (edit: Most of what you're interested in occurs here.)

Each Slayer bot consists of an AiConnection (inherits from GameConnection) and an AiPlayer (inherits from Player).

However, note that there's no default AI. The bots will just sit there without one. Slayer uses the Bot_Hole AI.
« Last Edit: October 09, 2014, 01:10:37 PM by Greek2me »

Thanks this is certainly helpful, however I noticed there you were recycling AIconnections, how do you retrieve them later for creating a new instance, I cannot seem to find any calls for that.

Thanks this is certainly helpful, however I noticed there you were recycling AIconnections, how do you retrieve them later for creating a new instance, I cannot seem to find any calls for that.
CreateAIClient(%persistence);

Unless Greek2Me changed it.

It's done in this function. Basically the AiConnection is removed from the AiRecycler and is ready to re-use.

You could pretty much do this:
Code: [Select]
if(isObject(AiRecycler) && AiRecycler.getCount() > 0)
{
%bot = AiRecycler.getObject(0);
AiRecycler.remove(%bot);
}
else
{
%bot = new AiConnection();
}

In fact, let me write a support script for this so that we can get a standardized recycler. Give me a couple minutes.

CreateAIClient(%persistence);
?



I dunno.

http://forum.blockland.us/index.php?topic=241284.0
Seeing as I am doing this in a context that may or may not include slayer, this is actually exactly what I'm looking for when it comes to that.

Which of course reading it its just copypasted bits of the slayer code but in a more universally implementable format

The only problem I see with it is that by default it recycles the AiConnection whenever the AiPlayer is killed. That's not how it's supposed to work. Clients should remain even after the player has died. Enabling that package at the same time as Slayer will cause problems with the Slayer bots.

If you want to use that, make the packaged GameConnection::onDeath method only affects bots created by CreateAIClient.
« Last Edit: October 09, 2014, 05:39:23 PM by Greek2me »

The only problem I see with it is that by default it recycles the AiConnection whenever the AiPlayer is killed. That's not how it's supposed to work. Clients should remain even after the player has died. Enabling that package at the same time as Slayer will cause problems with the Slayer bots.

Oh dear, then I guess all of my mods that have custom bots are completely incompatible with Slayer.


The non-persistent mode is for people who don't want to have to deal with respawning AIs.  As long as you're making your own AIs persistent, there should be no problem when other people do not.

Especially when I know things such as I will never have more than 3 servant bots at a time etc, you can make a limited AIConnectionPool of sorts and also test to not create more servants until the pool is clear. This should end up working thanks.

Oh dear, then I guess all of my mods that have custom bots are completely incompatible with Slayer.


The non-persistent mode is for people who don't want to have to deal with respawning AIs.  As long as you're making your own AIs persistent, there should be no problem when other people do not.

No, your script assumes that every bot that has an AiConnection should be recycled on death. Your script is incompatible with everything that uses AiConnections and AiPlayers together.

Instead of affecting everything without regard for how it was created, it should only affect things that were made by your script. Other scripts shouldn't have to add a "persistent" field to work around your script.
« Last Edit: October 11, 2014, 02:43:59 PM by Greek2me »

No, your script assumes that every bot that has an AiConnection should be recycled on death. Your script is incompatible with everything that uses AiConnections and AiPlayers.

By default, Blockland deletes AIConnections when their associated player dies.  Or at least, it's supposed to; the fact we need a recycler proves it doesn't do it right.  If I make it so that all AI clients are assumed persistent until told otherwise, any scripts which are ported poorly will leak AIConnections that never get cleaned up, and ultimately cause the game to crash at ~3.5k clients.

No, actually, AiConnections are meant to function just like GameConnections. When the player dies, they stay.

You aren't responsible for other peoples' mods. Don't try to fix other scripts with your own. It's intrusive and causes unintended behavior. The proper thing to do would be to inform the authors of said mods.

If my mod is not using your system, it shouldn't be affected by your system.

I still don't agree with you, but withdraw from the argument because I cannot find fault with your logic.