OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: Rocko Bonaparte 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?
-
If _unit == player then .....
or
If _unit != player then .....
Don't you hate it when it ends up being so simple. ;D
-
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
-
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?
-
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
-
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.
-
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...
-
This doesn't seem right. From OFPEC's command reference:
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
-
you wouldn't do that on the script, you would do that globally, like in a trigger, or another script
-
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.
-
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?
-
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 . . . :-\
-
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?
-
You might want to check out this thread (http://www.ofpec.com/yabbse/index.php?board=7;action=display;threadid=19594).