Comrades in Arms Discussion Board

Full Version: Need help with vehicle trigger
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My question is about finding a trigger that activates when a player gets inside a seat of a vehicle on a multiplayer game on a dedicated server. In my time of mission making i have come into errors when using the trigger condition codes i know of.

Lets say the rifleman of a group gets inside the gunner seat of a HMG hunter.

player = gunner H1
player in H1

Hunter name is H1 btw,

So far i have come run into the problem that they sometimes only work in singleplayer games and run into errors on a multiplayer game and sometimes JIP. What can i use instead?
First of all, a word of warning: NEVER use "player". The player is different on every client, and is not defined on a dedicated server. Using "player" is a sure way to make your game not work on a dedicated server.

Regarding your problem: Do you want it to trigger when a specific guy gets in, or any guy ?

Any guy is the easiest, the trigger condition would basically be

count (crew H1) != 0

This would trigger as soon as anyone is in the Hunter, regardless of players or not.

If you specifically want a player, you'd use

({isPlayer _x} count (crew H1)) != 0

If you need a specific guy to be in, give the guy a name (I usually call all my playable characters with a specific pattern, like westMan1_2 for the second guy in the first group of playable units on side WEST).

Then, the trigger condition would be

westMan1_2 in H1

Or, ii a specific position is needed

driver H1 == westMan1_2

Note that if this is a trigger that is placed on the map in the editor, it will run on all clients and the server.


Hope that helps
Would "crew count H1 == 1" work?
(08-16-2014, 07:34 AM)Watchmen link Wrote: [ -> ]Would "crew count H1 == 1" work?

No, it would generate a script error. "count (crew H1) == 1" would work
Veranon can you explain to me why it would cause a script error, it's not that i doubt you just that i know nuts about programming.

I assume that the order of "words" is wrong, bad programming grammar(which i want to learn and improve)possibly?
You just need to respect the function syntax so the compiler / interpretor can understand it.
I guess I can use a python example of print on why.

Back in 2.0 print "hi" works

In 3.0 print "hi" fails so you have to do print("hi")

Just how the compiler interprets it.
(08-16-2014, 08:34 PM)Phantom link Wrote: [ -> ]I guess I can use a python example of print on why.

Back in 2.0 print "hi" works

In 3.0 print "hi" fails so you have to do print("hi")

Just how the compiler interprets it.

It's not the same, actually. Python 2 vs 3 has made a few deliberate changes, which included unification of function calls.

In the case of "crew count H1 == 1", it's simply the syntax that is wrong.

"crew" expects a single argument, an Object type. H1 is such an object type. Crew returns an array with the crew of the vehicle.

"count" is a function that (among other things) counts the entries in an array. That is, it requires an array as an argument and returns an integer.

crew count H1 doesn't make sense. count cannot count h1, since it is a vehicle. It needs an array, so you must give it an array.

so, at best we're at "count crew H1". Now, Varanon put brackets around crew h1. This isn't because count is a function, there is no such concept in SQF. What it does, however, is establish precedence. count crew H1 can be interpreted left-to-right or right to left, or outer-to-inner vs. inner-to-outer. Without brackets, it can be interpreted as "(count crew) H1" or "count (crew H1)". If the rules aren't clear, then it is better to explicitly give a precedence by using brackets.

BTW, an interesting tidbit about SQF. While the language looks weird to anyone that knows a normal programming language, there are a few governing rules that make it extremely simple. Everything in SQF is an operator and either accepts zero, one or two argument.

Zero argument operators are for example "west", "player", etc. They don't have any argument and just deliver a result. Single argument operators expect their argument on the RIGHT side of the operator, and (usually) yield a result (which can be nothing). Examples for this are "count", "group", "units", etc.

Finally, binary operators are those that expect arguments on both sides. Examples for this are "createVehicle", "addWaypoint", "setMarkerPos" etc. Some operators like count exist in more than one version. Count can also be prefixed by code, which should return a boolean value. For example

{alive _x} count allUnits

counts all units from "allUnits" that are alive.

All the control structures like if statements, while loops etc. are operators too. Interestingly, the main oeprator for a conditional is "then". 'then' is a binary operator accepting an "if-type" on one side and a piece of code on the other side. "if-types" are only returned by the (unary) if operator. So:

if (condition) then {code};

"then" takes the if-type returned by if and executes code only if it is true.

if (condition) then {code} else {code2};

else is kind of like a switch statement. else is a binary operator and returns either its left ("code") or right ("code2") argument based on the if-type.

Same with while. The "real" loop operator is "do". It exists in two versions, with either a switch or a while type.

You probably get the idea.

Knowing these rules actually makes the language quite clear.

(if you read this up to here, congrats Big Grin)
Alwarren, uou jusy scarrd everyone Wink
I read it, though I guess I shall come back to it if I have something bork somewhere