Jump to content
Sign in to follow this  
jandrews

script to start/stop based on server population

Recommended Posts

Not sure if this is a good way to have scripts start but a group member asked the question. Can a halo jump script be run at start of mission and then disable based on server pop, say more than 8 players, but turn back on once server pop is under 8 players?

Share this post


Link to post
Share on other sites

Yes, you could either use a trigger system or a while loop system based on the count of playableUnits.

Trigger (condition may be incorrect, but will get you on the right path):

//Also set to repeatable, and set radius to the whole map
//condition
count playableUnits >= 8

//onAct
...Disable call to halo...

//onDeact
...Re-enable call...

While-loop:

while {true} do {

if (count playableUnits >= 8) then {
//disable halo
} else {

//enable halo

};

sleep 20;//<<not a "manditory" script, needed right away

};

//FYI, you will probably need to use publicVariable, or global...

Edited by JShock

Share this post


Link to post
Share on other sites

thanks. I figured a trigger would work, just not sure since its a public server with invade/annex, they wanted it so the halo would disable with more than 8 players to encourage heli transport.

I am going to assume a loop would be better since scripted in.

Now i just need to learn that darn thing called scripting. lol

---------- Post added at 15:42 ---------- Previous post was at 14:17 ----------

Ok. just so I have a starting point. For trigger would I just make 1 trigger with x and y at 0, set to blufor and repeatedly, cond: this & count playableUnits >= 8 Act: disable halo script? Deact: call halo script?

while calling the halo script in the init.sqf at mission start. And this will also activate halo when less than 8? do I need something to call script once players < = 8

I found this

{_x in thisList} count (playableUnits + switchableUnits) > = 8

So to disable/enable a script based on player count? I will keep looking. If anyone else has input please do.

thanks

Edited by JAndrews1

Share this post


Link to post
Share on other sites

I found this

{_x in thisList} count (playableUnits + switchableUnits) > = 8

So to disable/enable a script based on player count? I will keep looking. If anyone else has input please do.

thanks

The condition would just be what you put there, no "this", and you only need the one trigger set to repeatedly, onAct means that once the condition is met, do this (being disable halo when there are 8 or more playable/switchable units) and onDeact means when the trigger conditions aren't met anymore do else (being enable it again when there aren't 8+ players). And yes x and y axes are set to 0.

When you use a condition that isn't "this", all the stuff above the condition field (activation, type, present/notpresent) are ignored.

So trigger condition is only the following:

{_x in thisList} count (playableUnits + switchableUnits) > = 8

Edited by JShock

Share this post


Link to post
Share on other sites
The condition would just be what you put there, no "this", and you only need the one trigger set to repeatedly, onAct means that once the condition is met, do this (being disable halo when there are 8 or more playable/switchable units) and onDeact means when the trigger conditions aren't met anymore do else (being enable it again when there aren't 8+ players). And yes x and y axes are set to 0.

When you use a condition that isn't "this", all the stuff above the condition field (activation, type, present/notpresent) are ignored.

So trigger condition is only the following:

{_x in thisList} count (playableUnits + switchableUnits) > = 8

Ok. that helps, although I usually get confused on when to use "this" sometimes, your input always helps.

Should I look for anything specific regards to the activation and deactivation of using the repair scripts?

Share this post


Link to post
Share on other sites
Should I look for anything specific regards to the activation and deactivation of using the repair scripts?

I believe that should be asked on the other thread of yours :p. But the answer is no, it only activates on a very specific set of criteria, no need to deactivate the script as it is only called when that trigger condition is met. Here, with player counts, that is dynamic, the repair trigger is static, that's why we have both onAct and onDeact fields for counting players, because that will be ever-changing, the repair is on an "on-call" basis.

Edited by JShock

Share this post


Link to post
Share on other sites
I believe that should be asked on the other thread of yours :p. But the answer is no, it only activates on a very specific set of criteria, no need to deactivate the script as it is only called when that trigger condition is met. Here, with player counts, that is dynamic, the repair trigger is static, that's why we have both onAct and onDeact fields for counting players, because that will be ever-changing, the repair is on an "on-call" basis.

lol. typo, I meant halo script. So just so I "get it". I guess what I meant to "look" for anything else regards to act/deact was relating to "disable" halo script, is there a line of code I need to use to "disable"? I assume I just use its normal code for deact from init sqf.

trigger x,y = 0,

cond: {_x in thisList} count (playableUnits + switchableUnits) > = 8

Act: "disable" halo script. <----- what do I use to disable script.

Deact: call halo script

Share this post


Link to post
Share on other sites

Well, is your halo script called originally just in the init.sqf, or is it added to a whiteboard (you said I&A so I assume it's an addAction on a whiteboard), and if it's just the init.sqf, could you supply that, because I'm going to take a small detour from the trigger, not completely, just a little bit :p.

Share this post


Link to post
Share on other sites
Well, is your halo script called originally just in the init.sqf, or is it added to a whiteboard (you said I&A so I assume it's an addAction on a whiteboard), and if it's just the init.sqf, could you supply that, because I'm going to take a small detour from the trigger, not completely, just a little bit :p.

good call. Its on a whiteboard and flagpole. Oh boy, I feel it coming on....lol should I say F it now? lol

Share this post


Link to post
Share on other sites

It depends on whether or not you want to figure out how to remove actions and add them back in based on player count :p.

Share this post


Link to post
Share on other sites
It depends on whether or not you want to figure out how to remove actions and add them back in based on player count :p.

lol is that a trick question? I don't know if I want to know. Puts me in deeper down the rabbit hole. well....... (hesitation)...... give it to me in the basic terms.

Share this post


Link to post
Share on other sites

Those were the simple terms....but actually I just thought of a much easier way, which would be to add a condition to your action.

So...

addAction command goes like this:

object addAction ["Action Text", "script.sqf", [script Arguments], #(Priority Level number), Show Action Text, Display Scroll Menu, Shortcut, Condition];

example being:

object addAction ["Halo", "halo.sqf", [], 6, true, true, "", "_this distance _target < 3"];

The last thing in the command being "_this distance _target < 3", is basically your condition field saying once the player is less than 3 meters from the object, then show the action. So my easy way of doing this would be to put the following in the condition position within each of the addActions on your objects:

"(count playableUnits) + (count switchableUnits) < 8"

//i.e.

this addAction ["Halo", "halo.sqf", [], 6, true, true, "", "((count playableUnits) + (count switchableUnits) < 8)"];

I'm not sure if it's completely correct, but keeps us out of the sqf world :p.

Share this post


Link to post
Share on other sites

I did use a similar script system for halo from flagpole myself in Arma2, I allowed the halo as long as nobody was a pilot on the server.

Sadly I don't have the snippet handy but it was similar to Jshocks first loop but with a typeOf player == B_Pilot_F in the loop.

Just an idea for you :)

Share this post


Link to post
Share on other sites

Hmm. I was interested in this idea. What about handling the event without the loop? Idk how exactly you have this halo stuff set up. Anyhoo.. This will include only players and not Ai playable units.

Completely untested. No one to test with unfortunately.

if ( !( isServer ) ) exitWith {};

private [ "_players" ];

_players = [];
{
if ( isPlayer _x ) then {
	_players pushBack _x;
};
} forEach playableUnits

if ( ( count _players ) < 8 ) then {
missionNameSpace setVariable [ "haloEnabled", true, true ];
} else {
missionNameSpace setVariable [ "haloEnabled", false, true ];		
};

_someObject addAction [
"<t color='#0099FF'>HALO</t>", 
{ call some_halo_fnc; },
[],
6,
true,
true,
"",
"haloEnabled"
]; 

_id = addMissionEventHandler ["HandleDisconnect",{

waitUntil { !( isPlayer ( _this select 0 ) ) };

private [ "_players" ];
_players = [];
{
	if ( isPlayer _x ) then {
		_players pushBack _x;
	};
} forEach playableUnits

if ( ( count _players ) < 8 ) then {
	missionNameSpace setVariable [ "haloEnabled", true, true ];
} else {
	missionNameSpace setVariable [ "haloEnabled", false, true ];		
};

false

}];

Edited by Iceman77

Share this post


Link to post
Share on other sites

Why so complicated?

Something like this should suffice:

_someObject addAction [
   "<t color='#0099FF'>HALO</t>", 
   { call some_halo_fnc; },
   [],
   6,
   true,
   true,
   "",
   "({isPlayer _x} count playableUnits) > 8"
]; 

Share this post


Link to post
Share on other sites

Hehe. Idk, I guess less intensive to check for a bool then constantly counting all the playable units :p. And I was bored and interested in the handleDisconnect Eh :D

Share this post


Link to post
Share on other sites

Something like this?

this addAction["<t color='#ff9900'>HALO jump</t>", {"ATM_airdrop\atm_airdrop.sqf"},[],6,true,true,"","({isPlayer _x} count playableUnits) > 8"]; hint "use heli transport"

Edited by JAndrews1

Share this post


Link to post
Share on other sites

Yup that'd work if you want to constantly count all playable units =P. Nah jk it'll work just fine :)

Share this post


Link to post
Share on other sites
Something like this?

this addAction["<t color='#ff9900'>HALO jump</t>", {"ATM_airdrop\atm_airdrop.sqf"},[],6,true,true,"","({isPlayer _x} count playableUnits) > 8"];

Yeah that seems reasonable, Iceman and Tajin are going into using eventHandlers like onPlayerDisconnect and such :p, which could be beneficially in some ways, but for your case I'm not too sure it's completely necessary.

Share this post


Link to post
Share on other sites
Something like this?

this addAction["<t color='#ff9900'>HALO jump</t>", {"ATM_airdrop\atm_airdrop.sqf"},[],6,true,true,"","({isPlayer _x} count playableUnits) > 8"]; hint "para drop disabled, use heli transport"

lol. guys I just want it to work, I added a hint"", does that look right? Am open to any ideas at this time.

Share this post


Link to post
Share on other sites

I wouldn't put a hint in the whiteboard/flagpole's init field, just put the addAction in there. Basically what the condition does is, if there are fewer than 8 players, show the addAction on the whiteboard/flagpole, if there are more than 8 people, hide the action (in other words no one can use it). As to informing the players of that dynamic either just tell them or have it as a scrolling server message, or just a marker with text on the map.

Edited by JShock

Share this post


Link to post
Share on other sites
I wouldn't put a hint in the whiteboard/flagpole's init field, just put the addAction in there. Basically what the condition does is, if there are fewer than 8 players, show the addAction on the whiteboard/flagpole, if there are more than 8 people, hide the action (in other words no one can use it). As to informing the players of that dynamic either just tell them or have it as a scrolling server message, or just a marker with text on the map.

Got it. thanks for the explanations and help everyone.

Share this post


Link to post
Share on other sites
Hehe. Idk, I guess less intensive to check for a bool then constantly counting all the playable units :p. And I was bored and interested in the handleDisconnect Eh :D

Hehe, ok.

- The action-condition only runs when the player is nearby and looking at the object the action is attached to. So that itself already cuts down the load.

- My variant runs locally and doesn't require anything to be transmitted over the net.

It could probably be optimzed a bit further but "count" is pretty fast, so that is hardly worth the effort.

But I do agree: EventHandlers are awesome. :D

Share this post


Link to post
Share on other sites

Ahh okay. I figured it evaluated the condition on each frame to be able to determine what the count was at any given time. Learn new things every day.

Share this post


Link to post
Share on other sites

unfortuately guys neither of these work.

_someObject addAction [
   "<t color='#0099FF'>HALO</t>", 
   { call some_halo_fnc; },
   [],
   6,
   true,
   true,
   "",
   "({isPlayer _x} count playableUnits) > 8"
]; 

this addAction ["Halo", "halo.sqf", [], 6, true, true, "", "((count playableUnits) + (count switchableUnits) < 8)"];

ideas?

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  

×