Author Topic: Computer controlled objects over TNet  (Read 3862 times)

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Computer controlled objects over TNet
« on: April 29, 2013, 07:52:49 PM »
Hi, I was wondering how AI or NPC or some other computer controlled entities are handled over TNet. Say I have a few little followers, They have orders to move the closest cube. If I use the same object on my client and someone elses client will both be trying to control the object and then both try to sync making it do some weird stuff? Or have the client create objects that are on their team as the ai object and just a placeholder object that forwards functions like take damage and whatever to the real object. Which becomes hard when there are npcs that is on no one's team. Sorry I'm awful at explaining things. If you need more information I'll give you the example I am hoping to use.

Kind regards,
Scobbo.

Braveheart

  • Guest
Re: Computer controlled objects over TNet
« Reply #1 on: April 29, 2013, 08:09:26 PM »
I read that it'd be prudent to use the host client to control things like AI. (TNManager.isHosting) I haven't tried it myself yet as I'm still struggling with the issues in my thread.  Let me know if it works though, I'll need to look at using it soon.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Computer controlled objects over TNet
« Reply #2 on: April 29, 2013, 08:28:47 PM »
Run AI on one of the clients -- generally the host, as Braveheart mentioned. Use TNManager.isHosting to check for this before running AI logic. To issue commands, do that by sending RFC calls (tno.Send("MoveTo", Target.All, pos) for example). Watch this video first: http://www.tasharen.com/?page_id=4537

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Computer controlled objects over TNet
« Reply #3 on: April 29, 2013, 09:52:39 PM »
Ok, I was going to be running a persistent world with several players (about 8 or so). So I would need to make a server version that created a server that dealt with the AI and game logic and a client version that dealt with just the player input and sent that to the server and received position and creation and destruction events and displayed values like health. Is that right?
« Last Edit: April 29, 2013, 10:24:32 PM by Scobbo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Computer controlled objects over TNet
« Reply #4 on: April 29, 2013, 11:34:29 PM »
8 players isn't much, and I strongly advise you going with a client-based approach, leaving the server as-is. Basically start up an instance of TNServer -- either from within a game (P2P) or on a hosted server somewhere (like Amazon), and have players connect to it. One of the players will be automatically designates "host", and this is the person that should run all the AI logic. others simply exit out. Ie: if you had an Update function that did AI logic, just do this at the top:
  1. if (!TNManager.isHosting) return;

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Computer controlled objects over TNet
« Reply #5 on: April 29, 2013, 11:51:55 PM »
Oh I see, now the problem arises that I don't want other people to start a server. (For the moment) will it sync with a client that is slightly different, say one that has the entire game plus a host button?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Computer controlled objects over TNet
« Reply #6 on: April 29, 2013, 11:55:58 PM »
Yup. But it's up to you to make sure that all functions you are trying to use exist on both versions.

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Computer controlled objects over TNet
« Reply #7 on: April 30, 2013, 12:06:10 AM »
Brilliant! Thanks so much!