Jump to content
  • 0

Need help for a new script (count players)


FragZ

Question

I tried putting together a script to execute when players uses either action menu or Right-click option on a map or something similar (you get the idea), that counts players in a X meters radius and hint them the amount.

However, I would like to make it only usable once every 5 minutes (or any other time lapse) and I do not know how to do it...

Once this is done I will release it on the Server mods corner even though it's nothing big ;) just for some new features some people loved on my server (instead of keeping track of the players in your area over the debug monitor).


Any help/recommendation/modification suggestion is welcome!



Here is the first version of the code I put together fast yesterday:


 

/*
Player count in area script by FragZ
You can make this script execute over action menu or with right-click option in the extra_rc.hpp
You can also execute it over a trigger to make a pvp zone that counts participants!
*/
//Change 1300 to whatever distance you want the script to check for alive players
_playercount = (({isPlayer _x} count (getPos vehicle player nearEntities [['AllVehicles'], 1300]))-1);

uisleep 3;

if (_playercount == 0) then {
cutText ["You are currently the only human in your area.", "PLAIN DOWN"];
};
if (_playercount = 1) then {
cutText ["There is one other human in your area.", "PLAIN DOWN"];
};
if (_playercount > 1) then {
cutText ["There are %1 in your area!", "PLAIN DOWN"];
};

NOTE: I might have got some syntax errors I was pretty wasted writing this xD

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0
/*
Player count in area script by FragZ
You can make this script execute over action menu or with right-click option in the extra_rc.hpp
You can also execute it over a trigger to make a pvp zone that counts participants!
*/
//Change 1300 to whatever distance you want the script to check for alive players
_playercount = (({isPlayer _x} count (getPos vehicle player nearEntities [['AllVehicles'], 1300]))-1);
 
uisleep 3;
 
if (_playercount == 0) then {
cutText ["You are currently the only human in your area.", "PLAIN DOWN"];
};
if (_playercount = 1) then {
cutText ["There is one other human in your area.", "PLAIN DOWN"];
};
if (_playercount > 1) then {
cutText [format["There are %1 in your area!",_playercount], "PLAIN DOWN"];
};

Little typo in the last cuttext.

For the 5 minute delay I can help you but I have to go to sleep, I'll try to do it tomorrow!

 

xBowBii

 

What so like I got to add the variable after the cuttext so it recognize the variable to be read by %1? Sorry my brain is being dumb.

Thanks man!

And alright will see that :)

Link to comment
Share on other sites

  • 0
/*
Player count in area script by FragZ
You can make this script execute over action menu or with right-click option in the extra_rc.hpp
You can also execute it over a trigger to make a pvp zone that counts participants!
*/
//Change 1300 to whatever distance you want the script to check for alive players
_playercount = (({isPlayer _x} count (getPos vehicle player nearEntities [['AllVehicles'], 1300]))-1);
 
uisleep 3;
 
if (_playercount == 0) then {
cutText ["You are currently the only human in your area.", "PLAIN DOWN"];
};
if (_playercount = 1) then {
cutText ["There is one other human in your area.", "PLAIN DOWN"];
};
if (_playercount > 1) then {
cutText [format["There are %1 in your area!",_playercount], "PLAIN DOWN"];
};

Little typo in the last cuttext.

For the 5 minute delay I can help you but I have to go to sleep, I'll try to do it tomorrow!

 

xBowBii

 

 

If you want performance aswell try this as count

_playercount = count (player nearEntities ["CAManBase", 1300]); // only gets people, not all vehicles, besides, i think people are not in the ALLVechicle variable xp

Fuck it: here is your complete script:

/*
Player count in area script by FragZ & Zupa
You can make this script execute over action menu or with right-click option in the extra_rc.hpp
You can also execute it over a trigger to make a pvp zone that counts participants!
*/

// Config
_allowedDistance = 1300; 
_allowedAfterTime = 300000; // 1000 = 1 sec, 5*60*1000 = 300000
// Config End

if(isNil "LastUsedCheck")then{
LastUsedCheck = 0;
};

if( LastUsedCheck == 0 || (diag_tickTime-LastUsedCheck)>_allowedAfterTime)then{

_playercount = count (player nearEntities ["CAManBase", _allowedDistance ]); // only gets people, not all vehicles, besides, i think people are not in the ALLVechicle variable xp
 
uisleep 3;

if (_playercount == 0) then {
cutText ["You are currently the only human in your area.", "PLAIN DOWN"];
};
if (_playercount = 1) then {
cutText ["There is one other human in your area.", "PLAIN DOWN"];
};
if (_playercount > 1) then {
cutText [format["There are %1 in your area!",_playercount], "PLAIN DOWN"];
};
LastUsedCheck = diag_tickTime;
}else{
cutText [format["You can not use this now. Available in %1 sec.",(_allowedAfterTime  - (diag_tickTime-LastUsedCheck))/1000], "PLAIN DOWN"];
}; 
Link to comment
Share on other sites

  • 0

 

If you want performance aswell try this as count

_playercount = count (player nearEntities ["CAManBase", 1300]); // only gets people, not all vehicles, besides, i think people are not in the ALLVechicle variable xp

Fuck it: here is your complete script:

/*
Player count in area script by FragZ & Zupa
You can make this script execute over action menu or with right-click option in the extra_rc.hpp
You can also execute it over a trigger to make a pvp zone that counts participants!
*/

// Config
_allowedDistance = 1300; 
_allowedAfterTime = 300000; // 1000 = 1 sec, 5*60*1000 = 300000
// Config End

if(isNil "LastUsedCheck")then{
LastUsedCheck = 0;
};

if( LastUsedCheck == 0 || (diag_tickTime-LastUsedCheck)>_allowedAfterTime)then{

_playercount = count (player nearEntities ["CAManBase", _allowedDistance ]); // only gets people, not all vehicles, besides, i think people are not in the ALLVechicle variable xp
 
uisleep 3;

if (_playercount == 0) then {
cutText ["You are currently the only human in your area.", "PLAIN DOWN"];
};
if (_playercount = 1) then {
cutText ["There is one other human in your area.", "PLAIN DOWN"];
};
if (_playercount > 1) then {
cutText [format["There are %1 in your area!",_playercount], "PLAIN DOWN"];
};
LastUsedCheck = diag_tickTime;
}else{
cutText [format["You can not use this now. Available in %1 sec.",(_allowedAfterTime  - (diag_tickTime-LastUsedCheck))/1000], "PLAIN DOWN"];
}; 

Thank you very much for your time!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...