Jump to content


Photo

39dll server side A.I


  • Please log in to reply
7 replies to this topic

#1 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 28 June 2012 - 10:05 AM

My game I am making involves A.I, being the players work together to fight off zombies and all sorts of the creatures being the A.I. My problem is that I am unsure as to how I can go about this.

Would I have to have the server controlling all the A.I work and sending their data to the clients?

I need ideas and solutions as to how I can achieve this. Would be greatly appreciated, thankyou.
  • 0

#2 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 28 June 2012 - 10:36 AM

one solution that worked greate for me was to update the position of the enemies once per second and let the clients asume/calculate their position between those updates.
  • 0

#3 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 94 posts
  • Version:GM8.1

Posted 28 June 2012 - 12:16 PM

Severside NPCs?
Assuming from your other topic, you're using the classic networking system like in Online's exacmple, so you have an array for players in both the client and the server. You just need to make the same exact thing, but for zombies. So when a zombie appears, server sends a message to the clients. The message would then contain that zombie's position in the array and probably his initial position in the level, then client creates a new instance of the corresponding object and assigns it to that position in the array, like
global.zombies[readbyte()] = instance_create(readshort(), readshort(), obj_zombie);

After that you pretty much just sync zombies' positions exactly like you do with players: server processes the AI in the zombie object, then sends a message containing its ID and coordinates, which then will be processed clientside like:
var zid;
zid = readbyte();
if !instance_exists(global.zombies[zid]) {break;} //assuming you have that in a switch-case construction
global.zombies[zid].x = readshort();
global.zombies[zid].y = readshort();
global.zombies[zid].whatever = readwhatever();

Then, after a zombie dies, server sends a message containing its ID, which the clients interpret like
var zid;
zid = readbyte();
if !instance_exists(global.zombies[zid]) {break;} //assuming you have that in a switch-case construction once again
with global.zombies[zid] {instance_destroy();}

Also, i don't recommend sending X, Y, image_index and all that stuff every step, like filulilus said, send em once a room_speed/2 or room_speed and make the clients calculate the positions in between. Or there's a nice little trick:
//client's position update receive
case MSG_POSITION:
  var pid;
  pid = readbyte();
  if !instance_exists(global.players[pid]) {break;}
  global.players[pid].xto = readshort();
  global.players[pid].yto = readshort();
break;

//client's player object's create event
xto = x;
yto = y;

//client's player object's end step event
if x > xto {x -= (x - xto)/3;} else {x += (xto - x)/3;}
if y > yto {y -= (y - yto)/3;} else {y += (yto - y)/3;}
image speed = abs(abs(x) - abs(xto))/5; //you can calculate the speed however you want
but that's cheap as hell.

Edited by PrimuS, 28 June 2012 - 12:27 PM.

  • 1

#4 BlackEnergy

BlackEnergy

    GMC Member

  • GMC Member
  • 66 posts
  • Version:GM8

Posted 28 June 2012 - 02:05 PM

So pretty much, the server would control the zombie's A.I, where in that becomes updated and received through the clients?

For example, the zombie object in the server would chase after the client with it's A.I all within the server, and all that information is sent to the client for the client to actually show what's happening?

So I would send all the player's variables to the server, so that the server zombie knows what to do, and it can then effect the player's variables such as damage and so forth via the server to be then sent to the client to be updated?

Edited by BlackEnergy, 28 June 2012 - 02:27 PM.

  • 0

#5 PrimuS

PrimuS

    GMC Member

  • GMC Member
  • 94 posts
  • Version:GM8.1

Posted 28 June 2012 - 02:44 PM

Pretty much yes. Server gets input from the clients, processes the game logic, sends the results back. That's how almost any client-server net game works.
  • 0

#6 Orbitguy

Orbitguy

    UNS Lead Guy

  • GMC Member
  • 314 posts
  • Version:GM:Studio

Posted 28 June 2012 - 03:17 PM

Thanks for adding the array technique, I had been looking for an example of how to do that. And yeah, I currently have server controlled AI as well, I had considered the possibility of client controlled AI, but it seemed to tricky because having one player host all or some of the AI and transferring them when the player left seemed like too much of a hassle.

I did used to play a game where all of the AI were run by the client, and each client could see the other players but the AI on their screen only showed to them, and it was *okay*, but if AI are a large component of your game I wouldn't recommend doing that.
  • 0

#7 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 29 June 2012 - 07:50 AM

This is how I made my online games:

Position of the enemies are being controlled by both server and clients but the server have the main controll and send the "real" positions of the enemies each half/whole second.

Damage and other vital information (such as a door opening/closing) are ONLY being controlled by the server (based on clients inputs of course) and are instantly beint sent to the clients when they change.

Edited by filulilus, 29 June 2012 - 07:50 AM.

  • 0

#8 iceshield

iceshield

    GMC Member

  • GMC Member
  • 393 posts

Posted 30 June 2012 - 10:22 AM

Calculate movement ,position of AI on server , send enemy position packages on clients that really need that package ,like send it if the players see that enemy, and use dead reckoning on client :whistle:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users