Home   Help Search Login Register  

Author Topic: Detect if unit is human or AI controlled  (Read 2452 times)

0 Members and 1 Guest are viewing this topic.

Rocko Bonaparte

  • Guest
Detect if unit is human or AI controlled
« on: 14 Dec 2004, 21:10:32 »
Originally posted in General scripting:

http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=20895

Is there a way to tell if a unit is AI controlled in a multiplayer script?

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Detect if unit is human or AI controlled
« Reply #1 on: 15 Dec 2004, 00:46:10 »
If _unit == player then .....

or

If _unit != player then .....

Don't you hate it when it ends up being so simple. ;D

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Detect if unit is human or AI controlled
« Reply #2 on: 15 Dec 2004, 00:53:38 »
after reading the first thread, yes that will work.
player is in reference to the player on each computer, so it will check for each player to see if they are the unit

Rocko Bonaparte

  • Guest
Re:Detect if unit is human or AI controlled
« Reply #3 on: 15 Dec 2004, 02:29:52 »
The script I'm using it for is controlling AI in units on the server when they aren't human controlled.  Will that determine, on server, whether any given unit is controlled by any player?

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Detect if unit is human or AI controlled
« Reply #4 on: 15 Dec 2004, 02:49:24 »
yes, what you could do, is something like this:
create an array, like nonai = []
then in your script have this:
?_unit == player:nonai = nonai + [player]

and that will make a list of players (units that aren't ai), or you could do the opposite:
AI = []

?_unit != player:AI = AI + [_unit]

but i would recommend the first, because the second probably won't work in mp

Rocko Bonaparte

  • Guest
Re:Detect if unit is human or AI controlled
« Reply #5 on: 15 Dec 2004, 03:51:01 »
How could I build this list?  The units subject to this script are ones selectable in the multiplayer menu.  If somebody opts to be one of these units, then the script won't run on it.  If the unit is set to be computer controlled, then the script should be run.  I imagine there's something to control this, but I don't know exactly what.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Detect if unit is human or AI controlled
« Reply #6 on: 15 Dec 2004, 04:32:04 »
is the script just to be used for your mission, or will you be submitting it?
if it's just for your use in the mission its easy, just make a list:
unitlist = [list of playable units]
?"_x == player" foreach allunits:unitlist = unitlist - [_x]
then exec using the foreach command with the list:
{[_x,other arguments] exec "script.sqs"} foreach unitlist

if you're submitting it... its a little harder...

Rocko Bonaparte

  • Guest
Re:Detect if unit is human or AI controlled
« Reply #7 on: 16 Dec 2004, 02:05:24 »
This doesn't seem right.  From OFPEC's command reference:
Quote
player

Type of returned value:
Object
Description:
person controled by player. In MP this value is different on each computer.

Example:
alive player

comment »
It sounds like to me all this will do is isolate the player running the server, if there is one.  This script is running on the server

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Detect if unit is human or AI controlled
« Reply #8 on: 16 Dec 2004, 02:39:15 »
you wouldn't do that on the script, you would do that globally, like in a trigger, or another script

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:Detect if unit is human or AI controlled
« Reply #9 on: 16 Dec 2004, 17:36:55 »
Yes, but let's say you wanted the server to delete AI players left behind when someone disconnects. How does the Player command behave when executed on the server?  If the Player command must be executed on each client, how do you keep your non-AI array synched?  Each computer would send it's own non-AI array back to the server and that array would only contain the player for that machine.  Your non-AI array on the server would end up being an array containing only the last non-AI player to PublicVariable.
urp!

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Detect if unit is human or AI controlled
« Reply #10 on: 16 Dec 2004, 21:29:43 »
but all it does is add the player to a globalvariable, that is an array
since it's global, all the players would end up in the list
right?

Rocko Bonaparte

  • Guest
Re:Detect if unit is human or AI controlled
« Reply #11 on: 17 Dec 2004, 06:21:54 »
In my case, each individual unit involved is its own squad.  Nobody directly commands anybody else.  I don't expect the AI to take over for a person that disconnects either.  With this in mind, is it possible at mission startup for each client to transmit its player to the server?  That would at least give me the correct list.

Somebody on the BI forums mentioned a CoC multiplayer addon for things like this.  Their system is expansive, and does a lot of things that don't matter to me in this mission.

What I was thinking of try is in the init.sqs:
A. Running server AI script if it's running on the server.  It would be delayed a second to give the clients a moment to transmit it.
B. Otherwise, this is the client, and transmiit player name to a global array.  

I presume all machines will have that array, and it should build up right when the mission starts.  I should be fine with that.  In fact, I'd be trying it right now if I could test it at the moment . . .  :-\

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:Detect if unit is human or AI controlled
« Reply #12 on: 17 Dec 2004, 15:01:20 »
It may be global to each client but not to the server.


but all it does is add the player to a globalvariable, that is an array
since it's global, all the players would end up in the list
right?
urp!

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:Detect if unit is human or AI controlled
« Reply #13 on: 17 Dec 2004, 15:27:17 »
You might want to check out this thread.
urp!