Home   Help Search Login Register  

Author Topic: finding which units are controled by a client  (Read 4943 times)

0 Members and 2 Guests are viewing this topic.

ido_

  • Guest
finding which units are controled by a client
« on: 25 Sep 2006, 22:51:35 »
Hey all, is there a way to find if a certian unit is AI or not ?
I have a coop mission with three squads and I want to run a script if the squad leader is not a human player.
I thought about something like this:
Code: [Select]
?((local u2_1)<>(local server)) : exitbut if the mission will not run on dedicated server it wont work...

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: finding which units are controled by a client
« Reply #1 on: 26 Sep 2006, 00:32:48 »
in the init field of the squad leader put [this] exec "myscript.sqs"  (myscript refering to the script you want to use)

at the top of your script put:
Code: [Select]
_unit = _this select 0
?(_unit == player):exit
...the rest of your script...

if the unit is AI the script will continue, else it will be stopped

ido_

  • Guest
Re: finding which units are controled by a client
« Reply #2 on: 26 Sep 2006, 09:00:45 »
Ok so maybe I missunderstood the "player" var. If lets say I got 3 players connected to a dedicated server (player1, player2 and player3 and their unit names u1, u2, u3). now the script runs and the first line is ?(u1==player) : exit, wouldn't the condition be false on players 2&3 machines ?

I'll elaborate  on what I'm trying to achive. I have a C130 landing it has: this addaction ["Remove jeeps", "release.sqs"] in its init field.
After the plane landes the leader of the team in the back of the plane disembarks the groop and should do this action and get into the jeeps. From what I read in this forum AI cannot preform custom actions so I must find somehow if the leader (I have 3 teams) of the team is AI or not, and if he is I need to script the jeeps out of the C130s

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: finding which units are controled by a client
« Reply #3 on: 26 Sep 2006, 10:11:13 »
You are right: u1==player will only be true on u1's machine. It will return false on everybody elses computers (including the dedicated server). I need to think a little before I answer the rest of your question... *thinking*

EDIT: Add this to your init.sqs. It's an ad hoc solution, and I didn't test it, but it should work. Here it goes:

u1play=false; publicVariable "u1play"
u2play=false; publicVariable "u2play"
u3play=false; publicVariable "u3play"

?(u1==player): u1play=true; publicVariable "u1play"
?(u2==player): u2play=true; publicVariable "u2play"
?(u3==player): u3play=true; publicVariable "u3play"

Now you can easily check if the unit is under player control (in wich case you don't need to do anything). If he's not under player control you must run the script/trigger/whatever that unloads the jeeps from the plane.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: finding which units are controled by a client
« Reply #4 on: 26 Sep 2006, 11:46:09 »
nominesine's method is the way to go but it needs some minor corections;


init.sqs will be executed everywhere, so there's no need to use publicVariable in there
for the 'false' status - when saying: u1play = false it will be false everywhere.


Code: [Select]
u1play=false
u2play=false
u3play=false

The second part - the check wether a unit is player or not you should also not do in
init.sqs, since it's also not wise to use publicVariable in there in case it's required to.

at startup there's a lot of performance hit so that some publicVariable information migh
get lost.


Therefore you can either use triggers or execute a script to do that.

:note - don't execute the script from the init fields of the units since they become executed
before init.sqs and thus you would overwrite the true status by init.sqs to false again.


~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: finding which units are controled by a client
« Reply #5 on: 26 Sep 2006, 12:00:19 »

init.sqs will be executed everywhere, so there's no need to use publicVariable in there
for the 'false' status - when saying: u1play = false it will be false everywhere.


Opinions are divided regarding this matter ;)

Technically Chris is correct, but since the clients can be pretty desynched during mission start I publicVariable'd the "false" command. It's better to be safe than sorry :D If you want to be absolutely 100% sure you can start a script from the init.sqs, delay it for a few seconds, and check wether the player is a player or not a few seconds into the game. I assume it will take some time before the server will need to know wether the unit is under human or AI control?
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: finding which units are controled by a client
« Reply #6 on: 26 Sep 2006, 12:11:36 »
hmm - that's first time i hear about the dividing opinions in case of init.sqs.

You can easily check that by camcreating an object in init.sqs which would
always be visible only where the command has been executed.
Result would be that you see that object everywhere.

In earlier days people where using init.sqs to  create random stuff, which ended
up in having different results everywhere due to randomness.

init.sqs is executed locally, but each network participant executes the same
code.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: finding which units are controled by a client
« Reply #7 on: 26 Sep 2006, 12:17:49 »
I just meant that desynch produces funny effects sometimes, especially on slow connections like mine. Sometimes a machine will skip a scriptline (it seems), and in this case the publicVariable from the other computers would then correct that. But I agree I could have explained it better.

@Ido
Don't let my second reply confuse you. Listen to what CD said in his first reply. My second answer is mostly technical mumbo-jumbo to wich there is no real solution anyway. I should have given it more thought before replying.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

ido_

  • Guest
Re: finding which units are controled by a client
« Reply #8 on: 26 Sep 2006, 12:30:31 »
Ok guys thanks, if I put the whole thing in the init.sqs than I guess it wont be a good idea to publicate the FALSE because maybe on another client it was already set to true... but I can do it a little later, there are about 2 minutes until the C130s land :P

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: finding which units are controled by a client
« Reply #9 on: 26 Sep 2006, 21:42:28 »
Where a boolean variable is expected and the variable is undefined, the result is false right? Doesn't the comref explicitly say so?

Quote
When undefined value is encountered in field where boolean value is expected, it is converted to false.

Are you guys aware of any exceptions to this rule stated by the comref (when it doesn't work like expected)? I never ran into them but it doesn't mean there are no exceptions.

For sure I initialize all global variables in the mission start, though, were they boolean or not.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: finding which units are controled by a client
« Reply #10 on: 27 Sep 2006, 01:22:11 »
All MP tutes I've come across has told me to define the variables as false in init.sqs. That's why I always do it. I don't know about any exceptions.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: finding which units are controled by a client
« Reply #11 on: 27 Sep 2006, 19:04:04 »
It is a good practice and I follow it too, but I am quite sure it is not technically required. I'd just like to hear if anyone has any actual proof of when it is absolutely required to do so to make some thing work.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: finding which units are controled by a client
« Reply #12 on: 28 Sep 2006, 01:22:15 »
[offtopic]MP editing is all voodoo. You end up doing a lot of things, such as double triggering mission critical conditions, just to avoid the possibility of minor fault/desync bugs. Predefining in the init.sqs all variables you intend to P.V., to either 0, [], FALSE, or ObjNull is all part of the black art. Don't mess with the mojo.

I would not recommend using P.V. in the init.sqs. With desync (which as C.D. said can be massive at mission start), you have no clue what is going to happen. If your init.sqs is short, it will definitely be processed before the mission starts, and all clients will start with the variables in sync.

P.V. near a mission start drops like crazy, unless all clients have excellent connections to an excellent server.  If you have to P.V. near mission start, it is best to have a small pause (~0.5- 1), and then P.V. each variable 3 times with a small pause (~0.1-0.2) in between.  That way no matter how crap the connections your variables will start synched between all clients and the server.[/offtopic]
urp!

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: finding which units are controled by a client
« Reply #13 on: 28 Sep 2006, 18:15:05 »
Yeah. The trigger desync problem in multiplayer was covered by Kegetys in an old forum post (in Finnish, I translated it to English and posted it to the Editors Depot). Some other tutorial(s) claimed that triggers are always synchronized by the server, which has been proven not to work reliably. I have seen it many times in multiplayer missions when triggers between clients are not in sync and players are reporting different mission situations, caused by some of them had triggers executing but some didn't.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: finding which units are controled by a client
« Reply #14 on: 28 Sep 2006, 20:39:00 »
I remember reading that tute and finding it very useful. I wish it had been around to read before I started MP editing. Would have saved me a lot of grief. It the tutorial still alive somewhere?


edit: found it :)

edit2: removed text. Submitted to beta resources as tutorial: Triggers, Scripts & addAction in MultiPlayer
« Last Edit: 29 Sep 2006, 15:57:33 by Mr.Peanut »
urp!