James Grimm 0 Posted January 4, 2018 Ok, now I want you all to know that I started scripting a few days ago and as most of you can understand I am not a genius just yet. All I need help with is to make a code run while the trigger is activated. something along the lines of. "while" _Caller is in the trigger run (_caller addScore 10 .... sleep 5) So pretty much while the player is in the trigger he will be given score every 5 seconds. And on top of that I know how you make an sqf run via (addAction) but how do you make an sqf run when a trigger is activated / a player enters the trigger. Sorry for the stupid questions trying to learn. Share this post Link to post Share on other sites
gc8 977 Posted January 4, 2018 for single player something like this should do it: while { true } do { if(player inArea trigger1) then // trigger1 is trigger placed in the editor { player addScore 10; }; sleep 5; }; put that in init.sqf for example. Share this post Link to post Share on other sites
James Grimm 0 Posted January 4, 2018 How would one go about doing it in multiplayer? @gc8 Thanks for the help. and I simply added a sign where you can get score _caller = _this select 1; _caller addScore 10; This works for me but not for if my friends try it no score gets added Share this post Link to post Share on other sites
gc8 977 Posted January 4, 2018 in MP I would use this code but there maybe other solutions: while { true } do { { _plr = _x; if(_plr inArea trigger1) then { _plr addScore 10; }; } forEach playableUnits; sleep 5; }; Share this post Link to post Share on other sites
James Grimm 0 Posted January 4, 2018 Ok as I said I am very new to this. would you mind explaining what the _plr = _x means? Share this post Link to post Share on other sites
gc8 977 Posted January 4, 2018 Just now, James Grimm said: would you mind explaining what the _plr = _x means? simply it assigns the value of variable _x to variable _plr. So they are like copies of the same variable. I do that just so that my code looks clearer. :) so both _x and _plr points to player object. Share this post Link to post Share on other sites
James Grimm 0 Posted January 4, 2018 Thanks for all the help Gc8 That worked great! But why have you got to put in in the init.sqf? does that constantly run or something? Share this post Link to post Share on other sites
gc8 977 Posted January 4, 2018 2 minutes ago, James Grimm said: But why have you got to put in in the init.sqf? does that constantly run or something? init.sqf is run only once at mission start so its ok place to have the while loop going. Share this post Link to post Share on other sites
James Grimm 0 Posted January 4, 2018 Ok, fantastic. I've got one more stupid question for you. on the point of while loops https://prnt.sc/hw0ipm _tele = _this select 0; _caller = _this select 1; Offroad setPos (getpos (OffroadStart)); _caller moveingunner Offroad; i = 35 while (i>1) then { hint format["you have %1 Secounds left",i]; sleep 1; i = i-1; } sleep 35; Offroad setPos (getpos (OffroadEnd)); Offroad setVehicleAmmo 1; Offroad setDamage 0; _caller setPos (getpos (OffroadEnd2)); that code worked until I added the while loop what it does it teleport an offroad form one place to another teleports the player inside waits 35 sec (Where I tried adding a timer) and then teleport everything away and repairs. But the loop doesn't work and everything after the loop doesn't run. here is the error message i get in-game http://prntscr.com/hw098x Share this post Link to post Share on other sites
gc8 977 Posted January 4, 2018 one problem that I see is that the line: while (i>1) then { should be with do instead of then: while (i>1) do { also the ending } needs ; like so: }; And "i = 35" needs ; as well, like so: i = 35; Share this post Link to post Share on other sites
gc8 977 Posted January 4, 2018 another tip: use _i instead of i because i makes a global variable when all you need is local variable: _i Share this post Link to post Share on other sites
pierremgi 4840 Posted January 4, 2018 @James Grimm Please don't duplicate your topic. You have 2 errors: while {cond} do {code}; // no ( ) but { } then, in you addAction, you will have a further error like: suspension not allowed in this context, because you need to spawn your scheduled code (using a sleep command). Share this post Link to post Share on other sites
AZCoder 921 Posted January 4, 2018 Crikey I didn't see this was in 2 threads by the same author before I posted an answer in the other thread. LOL. Share this post Link to post Share on other sites
Sgt. Dennenboom 98 Posted January 4, 2018 addActions already spawn their code, so you are safe to use sleeps in there. 1 Share this post Link to post Share on other sites
pierremgi 4840 Posted January 5, 2018 3 hours ago, Sgt. Dennenboom said: addActions already spawn their code, so you are safe to use sleeps in there. I missed that. Share this post Link to post Share on other sites
MeIvin 10 Posted January 5, 2018 Just remember that addScore must be run on the server to work properly, as per: https://community.bistudio.com/wiki/addScore (which it will since it's in the init). But it might be an idea to place the code in initServer.sqf to prevent it from running on all the clients. Melvin Share this post Link to post Share on other sites