Jump to content
Sign in to follow this  
Purzel

Need help with "add action" and ".sqf"

Recommended Posts

Hi there,

EDIT: This thread contains a mp-working guidance how to switch streetlights off in a certain radius,

triggered via action menu, which only occurs, when player is in range of a certain object.

(e.g.: player switches a generator off, which delivers power supply to streetlights and houses)

This is finally done without a "lightsoff.sqf"-file, instead we use only a init.sqf, a marker and an object.

Go here for the solution

Now here´s the original question and the way to solution:

I need a trigger, which switches the light in an area of 100m off.

The problem is not the "trigger" or the "lightsoff.sqf":

The problem is: I want any player to enter the trigger-area and only that player should be able to see a new entry in his action-menu ("switch lights off").

after using that action-menu-entry the "lightsoff.sqf" should be executed after 5 seconds.

What do I need in the init/activation-fields of that trigger..?

Thanks for your help!

Edited by Purzel

Share this post


Link to post
Share on other sites

Condition of the trigger:

unitname in thislist;

In the activation of the trigger:

Lightaction = unitname addAction ["Switch Lights Off ", "lightsoff.sqf"]

Then, in the lightsoff.sqf before all the code, add:

sleep 5;

Inviato dal mio GT-I9300 con Tapatalk 4

Share this post


Link to post
Share on other sites

Thanks a lot!

Seems to be easy, but it does not work...

I copied all your stuff into the fields, but there´s no entry in that action menu...

Do I have to replace "unitname" through other names or do i have to define a "thislist" ..?

And should I write

unitname sidechat "Lights are going off in a few seconds!"

into the lightsoff.sqf, or should I put it into the trigger activation field?

Edited by Purzel

Share this post


Link to post
Share on other sites

unitname should be the name of the unit that you want in the trigger and that you want to do the action, when you place a unit you can give him a name, or if the unit that you want to have the action is the player, just use "player" without the quotes instead of unitname.

Yes, you can write it in the script.

EDIT: Just to be sure, you want the action available when any units is in the area, or when the unit that should use the action is in the area?

Share this post


Link to post
Share on other sites

Condition of the trigger:

player in thislist;

In the activation of the trigger:

Lightaction = player addAction ["Switch Lights Off ", "lightsoff.sqf"]

Then, in the lightsoff.sqf before all the code, add:

sleep 5;

just edited the code from Antorugby, to just work with any player.

Share this post


Link to post
Share on other sites

Any "blue" Unit should be able to trigger the lights off!

Just in case the right one is not remaining at that time in the mission and died before it could trigger the lights off.

Ahhh! THANK YOU!

I will try tonight, have to work now! CU later

Share this post


Link to post
Share on other sites

After I used Lappihuan´s script the lights will still not go off.

Now the "addAction"-thing works, but stays in menu (and mostly in sight!)

But it should disappear when the player is out of triggerzone.

My "lightsOff.sql" seems to be ok, because when I put this into a radio alpha trigger, it works!

Please: What do i write into the deactivation field?

I guess it´s something with "removeaction"? But what?

Share this post


Link to post
Share on other sites

One easy way to do it is to set a condition for the action:

nul = player addAction ["Switch Lights Off ", "lightsoff.sqf", [], 0, false, true, "", "_this distance someRelevantCoordinates/object < 100"];

Share this post


Link to post
Share on other sites

I'm a great addaction scripter? I can also help you with police sirens and lights? I was recently designing one, so ill follow this thread ;)

Share this post


Link to post
Share on other sites

@ Gekkibi:

"_this distance someRelevantCoordinates/object < 100"

Can i use an object-number? If so - how do i write this?

Sorry, but that scripting stuff is to much for me - I don´t know anything about that scripting-commands.

I will never understand, what all those { / [ _ "" stuff means and how it is written in a correct way?

I try and try and try to understand it in a logical way, so I need it written in a working way.

I just want to do a nice map, but scripting is not my friend!

Share this post


Link to post
Share on other sites

Ya, it takes time to learn SQF. The magic trick is: practice - practice - practice. I started with SQS back in the OFP days, and switched to SQF when Arma 2 was released (I was too stubborn to learn new tricks when I played Arma 1, and sticked with SQS). It sure was pain in the donkey at first... Protip: keep this page in one of your browser tab, at all times.

But back to topic: "_this distance centerPoint < 100"

Create an empty invisible helipad, name it centerPoint and place it where you want. The action is visible when the player is closer than 100 meters from this object. When he gets closer than 100 meters he will see the action in his action menu. After he gets further it will suddenly disappear, and appear again when he's closer. This way you don't have to constantly create and remove the action (assuming you want to do that, that is).

Share this post


Link to post
Share on other sites

@Ok, I tried and the action menu is working so far, but it adds continuesly the action, as long as I´m inside the defined "zone"...

lightsoffmenuymbdx.jpg

but the lightsOff.sql isn´t working after the sleep command.

Here´s the code:

player sidechat "LightsOff in 10 seconds!"

sleep 5

_types = ["Lamps_Base_F", "PowerLines_base_F"];

_onoff = _this select 0;

for [{_i=0},{_i < (count _types)},{_i=_i+1}] do

{

// powercoverage is a marker I placed.

_lamps = getMarkerPos "lightMarkerTest" nearObjects [_types select _i, 500];

sleep 1;

{_x setDamage _onoff} forEach _lamps;

};

player sidechat "Lights are OFF now! Gogogo!"

Edited by Purzel

Share this post


Link to post
Share on other sites

Oh dear, I didn't realize how and where you added the action to your action menu... ;)

Ya, you only need to create it once.

Could you post the current version of the sqf?

Share this post


Link to post
Share on other sites

You can see it above... I lowered the time to 5 secs for "I dont want to wait"- reasons.

Ya, you only need to create it once.

how? :confused:

Share this post


Link to post
Share on other sites

To remove the action when you exit the trigger area, take a look at my code:

Lightaction = unitname addAction ["Switch Lights Off ", "lightsoff.sqf"]

I gave the action a name, so in the deactivation field of the trigger put this:

unitname removeaction Lightaction;

Inviato dal mio Nexus 10 con Tapatalk 4

Share this post


Link to post
Share on other sites

Put this to your player unit, you can completely remove the trigger.

nul = this addAction ["Switch Lights Off ", "lightsoff.sqf", [], 0, false, true, "", "_this distance markerPos 'lightMarkerTest' < 100"];

Cleaned it up for you.

player sidechat "LightsOff in 10 seconds!";
sleep 10;
{
_x setDamage 1;
} forEach (getMarkerPos "lightMarkerTest" nearObjects ["Lamps_Base_F", 500]) + (getMarkerPos "lightMarkerTest" nearObjects ["PowerLines_base_F", 500]);
player sidechat "Lights are OFF now! Gogogo!";

PS. Don't forget these:

;

Share this post


Link to post
Share on other sites

Thank you...

I don´t want to ungrateful. The mission is:

Sneak near the House, where the hostage is held, switch off power (aka lights) in that area, so you can get closer and unseen to the object.

For that reason I searched for a "powergenerator-like" part of a nearby building, where the only place is, where you can switch off the lights.

So someone of our heros needs to go there and switch off the lights. (every player should be able to do this, if the other is already dead!)

This switch is only to be done one time, and we don´t need it anymore.

Maybe we can re-switch the power after the assault (e.g. to light the nearby landingzone of the rescuechopper), but it will not be nesessary!

In my sql-case I see, I forgot the ;, Waaaaah! I´m so stupid! :mad:

Share this post


Link to post
Share on other sites

MAJOR EDIT: forgot this was for MP... Didn't take locality into concideration...

In case of power generator, edit the action. Because the object is always in the right place, you can clean the addAction as well. Name the generator "generator".

lightsoff.sqf

player sidechat "LightsOff in 10 seconds!";
sleep 10;
lightsOutVariable = true;
publicVariable "lightsOutVariable";

Create init.sqf where is this text:

nul = player addAction ["Switch Lights Off ", "lightsoff.sqf", [], 0, false, true, "", "_this distance generator < 5"];
if (isServer) then {
waitUntil {!isNil "lightsOutVariable"};
{
	_x setDamage 1;
	sleep 0.01;
} forEach (getMarkerPos "lightMarkerTest" nearObjects ["Lamps_Base_F", 500]) + (getMarkerPos "lightMarkerTest" nearObjects ["PowerLines_base_F", 500]);
};

Edited by Gekkibi

Share this post


Link to post
Share on other sites

MAJOR EDIT:

Can I clear the trigger fields and/or delete the trigger? Is that correct?

EDIT:

Yiiiieeeehhhaaaaa!!!!!!!!!!!!!!! It works!!!!!

THANK YOU!!!

btw: I already mentioned to get that effect! Now you did this "on-the-fly" with my problem! great!

I wish you hot naked girls, free gasoline and may the luck be with you! :p

Edited by Purzel

Share this post


Link to post
Share on other sites

Ha! now the lightsOff-stuff works!!!!

Can I get the "sidechat"-text into the middle of the screen?

Share this post


Link to post
Share on other sites

Yes, with cutText.

However, extra steps must be made if you want others than just the one who activated the action see the text... Use this...

init.sqf:

if (!isNull player) then {
[] spawn {
	nul = player addAction ["Switch Lights Off ", {lightsOut = true; publicVariable "lightsOut";}, [], 0, false, true, "", "_this distance generator < 5 && isNil 'lightsOutVariable'"];
	waitUntil {!isNil "lightsOut"};
	hint "plop";
	sleep 10;
	hint "bang";
};
};

if (isServer) then {
waitUntil {!isNil "lightsOut"};
sleep 10;
{
	_x setDamage 1;
	sleep 0.01;
} forEach (getPos generator nearObjects ["Lamps_Base_F", 500]) + (getPos generator nearObjects ["PowerLines_base_F", 500]);
};

Now it should be MP compatible...

Edit: And yes, you can remove the trigger completely. Also, delete the addAction from the player init field. All you need is init.sqf, plus the marker (and the generator, of course).

Edited by Gekkibi

Share this post


Link to post
Share on other sites

Grmpfl! :mad:

No it does not work anymore, wether in MP or when I test the map from editor. :confused:

Just for my understanding (as far as I getting through with this)

The "generator" is the "triggerzone" of a radius from 5m, in which the player has to be, when he wants to switch the lights off.

The "lightMarkerTest" is the center of the "dark zone" (in this case 500m around will become dark, if triggered)

The "<-put your text here->" should be replaced by sidechat/cuttext-Messages?

And no triggers needed anymore.

Your last version worked very well (not tested in MP)

Share this post


Link to post
Share on other sites

fix'd, I was tired yesterday, and I didn't test what I wrote. The addAction condition had !isNil instead of isNil.

I made it so that you don't need lightsOff.sqf at all. All you need is a object "generator" and init.sqf, that is all. No other sqf's or markers on the map...

...And this time I tested it in Arma 3, works like a charm. ;)

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
Sign in to follow this  

×