Jump to content

Recommended Posts

Hi all !

 

I have a small problem, I would like to add a trigger and set two conditions for it's activation. _won is the name of the car.

The first is "this", player is present in the area (cicle 3,3 around _won).

The second is "!(player in _won)", player is not in the vehicle.

 

I can't find a way to make it work...

// _won is the name of the car   

_trg = createTrigger ["EmptyDetector", getPos _won, false];
_trg setTriggerArea[3,3,0,false];
_trg setTriggerActivation["WEST","PRESENT",true];
_trg setTriggerStatements[    
                            "this &&  !(player in _won)",
                            "hint 'yes yes yes'",
                            "hint 'no civilian near wonno'"
                         ];

Share this post


Link to post
Share on other sites

add

 

won = _won;

 

before everything and change condition to 

 

"this &&  !(player in won)"

Share this post


Link to post
Share on other sites

If the car has no name or is added via script, you may setVariable it to the trigger and getVariable it inside the condition again. That way, you don't need a global variable:

_won = createVehicle [_type, _position, [], 0, "NONE"];
_trg = createTrigger ["EmptyDetector", getPos _won, false];
_trg setTriggerArea [3, 3, 0, false];
_trg setTriggerActivation ["WEST","PRESENT",true];
_trg setVariable ["won", _won];
_trg setTriggerStatements [    
	"this &&  !(player in (thisTrigger getVariable 'won'))",
	"hint 'yes yes yes'",
	"hint 'no civilian near wonno'"
];

Share this post


Link to post
Share on other sites

I prefer using local variables in this script because it's going to be run locally and maybe simultaneously.

Thank you for the help Killzone_kid and Heeeere's johnny!

Share this post


Link to post
Share on other sites

A local variable is local to the code it is defined in. The scope of the local variable is the script/function/code. It does not exist outside that scope. A global variable exists in every scope on the client/entity it was created. Simple explanation:

 

car.sqf > _won only exists in car.sqf. 

 

car.sqf > won exists in all scripts/code on the client it was defined on.

 

More info on variables on KK's blog: http://killzonekid.com/arma-scripting-tutorials-variables-part-1/

Share this post


Link to post
Share on other sites

I am now trying to get over the issue of quotation marks...

Instead of "hint 'yes yes yes'" on activation I would like an addaction with text format inside.

 

Tried the code bellow and it works.

"(thisTrigger getVariable 'won') addaction [ format ['<t>Hello<t>'], 'staz\staz.sqf']"

However once I am trying to change the text's color, this bellow doesn't work.

"(thisTrigger getVariable 'won') addaction [ format ['<t color '#0000FF'>Hello<t>'], 'staz\staz.sqf']",

Share this post


Link to post
Share on other sites

A local variable is local to the code it is defined in. The scope of the local variable is the script/function/code. It does not exist outside that scope. A global variable exists in every scope on the client/entity it was created:

 

car.sqf > _won only exists in car.sqf. 

 

car.sqf > won exists in all scripts/code on the client it was defined on.

 

Thanks Whiztler for clarifying.

Share this post


Link to post
Share on other sites

You're missing a "=" and an opened <t> must be closed using a </t>:

 

<t color='#0000FF'>Hello</t>

Oh, I didn't pay attention, but it still doesn't work...

Share this post


Link to post
Share on other sites

The issue must be in your "staz.sqf" then, because it works for me.

 

And btw, you don't need to use format if you don't put anything (like numbers or so) into the string.

Share this post


Link to post
Share on other sites

The issue must be in your "staz.sqf" then, because it works for me.

 

And btw, you don't need to use format if you don't put anything (like numbers or so) into the string.

 

I don't think the file linked makes any differences because it's not yet run.

Ok, do I just write this ?

"(thisTrigger getVariable 'won') addaction ['<t color='#0000FF'>Hello</t>', 'staz\staz.sqf','',5]",

Share this post


Link to post
Share on other sites

Can you not just use the action? Otherwise every time the trigger is activated there will be a new action on the car.

_won = createVehicle [_type, _position, [], 0, "NONE"];
_won addAction [ "<t color '#0000FF'>Hello</ t>", "staz\staz.sqf", [], 1, true, true, "",
    "_this distance _target < 3 && side _this isEqualTo west && !( _this in _target )"
];

Share this post


Link to post
Share on other sites

 Larrow, is that an addaction with a condition ? Seems like a good idea...

 

 

Can you not just use the action? Otherwise every time the trigger is activated there will be a new action on the car.

_won = createVehicle [_type, _position, [], 0, "NONE"];
_won addAction [ "<t color '#0000FF'>Hello</ t>", "staz\staz.sqf", [], 1, true, true, "",
    "_this distance _target < 3 && side _this isEqualTo west && !( _this in _target )"
]; 

I didn't mention something in the first post, the deactivation is not :

"hint 'no civilian near wonno'"

but

"removeallactions (thisTrigger getVariable 'won')"

Basically each time the player gets in the vehicle or out of the 3 meters area, the addaction ealier added will be gone.

Share this post


Link to post
Share on other sites

What exactly does not work? Is nothing happening when you use the action or is the action not showing up at all?

 

When I launch the script, it doesn't display the addaction (while stepping into the 3 meters zone).

Share this post


Link to post
Share on other sites

Let me try a different approach here:

_won = createVehicle ["C_SUV_01_F", getPosATL player, [], 0, "NONE"];
_trg = createTrigger ["EmptyDetector", getPos _won, false];
_trg setTriggerArea [3, 3, 0, false];
_trg setTriggerActivation ["WEST", "PRESENT", true];
_trg setVariable ["won", _won];
[
    _trg,
    {
        if (_x == player) then {
            hint 'action added';
            player setVariable ["wonAction", player addAction ["<t color='#0000FF'>Hello</t>", "staz\staz.sqf", "", 5]];
        };
    },
    {
        if (_x == player) then {
            hint 'action removed';
            player removeAction (player getVariable "wonAction");
        };
    }
] call fnc_triggerListChanged; //Source: https://forums.bistudio.com/?showtopic=179622

Share this post


Link to post
Share on other sites

Strange thing, when I try this, it works :

"(thisTrigger getVariable 'won') addaction [ '<t>Hello</t>', 'staz\staz.sqf','',5]",

When I try this, it doesn't :

"(thisTrigger getVariable 'won') addaction [ '<t color='#FF0000'>Hello</t>', 'staz\staz.sqf','',5]",

Share this post


Link to post
Share on other sites

 

Strange thing, when I try this, it works :

"(thisTrigger getVariable 'won') addaction [ '<t>Hello</t>', 'staz\staz.sqf','',5]",

When I try this, it doesn't :

"(thisTrigger getVariable 'won') addaction [ '<t color='#FF0000'>Hello</t>', 'staz\staz.sqf','',5]",

 

It's a quotation problem. Your second line doesn't work, because you use the same quotes for color=... as you do for the whole action text string. If you remove the quotes encapsulating the whole line, you'll see:

(thisTrigger getVariable 'won') addaction [ '<t color='FF0000'>Hello</t>', 'staz\staz.sqf','',5]

I removed the # because it caused some unexpected behaviour with the coloration. But as you can see, the action text is pretty much broken into two pieces namely '<t color=' and '>Hello</t>' and since the interpreter cannot handle the stuff in between, it's a syntax error.

 

You can solve this by using double-double quotes, like this:

"(thisTrigger getVariable 'won') addaction [ '<t color=""#FF0000"">Hello</t>', 'staz\staz.sqf','',5]"

Share this post


Link to post
Share on other sites

Working !

 

quote / snip

 

:o I knew that "#FF0000" wouldn't work because it went red in the code editor. However I wasn't aware double " existed !

Thank you Heeeere's johnny!, lesson learned !

Share this post


Link to post
Share on other sites

Working !

 

 

:o I knew that "#FF0000" wouldn't work because it went red in the code editor. However I wasn't aware double " existed !

Thank you Heeeere's johnny!, lesson learned !

 

Double " is not what you think, it is not a special type of quotes, it is just a way to instruct compiler to ignore quotes. In other languages \ is used for that, for example "\"" in SQF teh same quote is used to achieve the same effect "" or ''

 

hint "1""2""3"; //works - 1"2"3

hint '1''2''3'; //works too - 1'2'3

Share this post


Link to post
Share on other sites

 

Modified your code :

_won addAction [
                                "<t color '#0000FF'>Hello</ t>",
                                "staz\staz.sqf",
                                _won,
                                1,
                                "",
                                "",
                                "",
                                "(player distance _won) < 3"
                            ];

This doesn't display the addAction, while approaching the car.

Share this post


Link to post
Share on other sites

Double " is not what you think, it is not a special type of quotes, it is just a way to instruct compiler to ignore quotes. In other languages \ is used for that, for example "\"" in SQF teh same quote is used to achieve the same effect "" or ''

 

hint "1""2""3"; //works - 1"2"3

hint '1''2''3'; //works too - 1'2'3

 

Well, at least to some excant it is what I expected. Never tried it with the single quote though, good to know. But when I started learning SQF, I was missing the \ to escape stuff until I stumbled across this "" notation. I wonder why they introduced the \ for escaping line breaks in defines, but not for ecaping quotes in strings.

Share this post


Link to post
Share on other sites

Final code :

// script for trigger
_trg = createTrigger ["EmptyDetector", getPos _won, false];
_trg setTriggerArea [3, 3, 0, false];
_trg setTriggerActivation ["WEST","PRESENT",true];
_trg setVariable ["won", _won];

_trg setTriggerStatements [    
                       "this &&  !(player in (thisTrigger getVariable 'won'))",
                       "(thisTrigger getVariable 'won') addaction [ '<t color=""#FF0000"">Hello</t>', 'staz\staz.sqf','',5]",
                       "removeallactions (thisTrigger getVariable 'won')"
                          ];

Share this post


Link to post
Share on other sites

Please correct me if I get something wrong in the following:

 

If a blufor player enters the trigger area, this trigger activates and "won" gets the action.

If a blufor player leaves the trigger area or mounts "won", the action gets removed from "won".

If bluforPlayer1 and bluforPlayer2 enter the trigger area and bluforPlayer1 mounts "won", the action gets removed from "won", but only on the machine of bluforPlayer1.

 

So bluforPlayer2 can still use the action, because he neither left the trigger area nor mounted "won". Is that correct?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×