Forum Jump :

Author Message


Posts: 9
Rank:


Level: Member

Country: au
Location: Melbourne
Occupation: IT
Age: 35
In-game name: Havoc

 
#1 Posted at 2016-09-25 08:06        
     
I'm trying to throw together a script to run on our Liberation server to stop players just sitting around and going AFK for extended periods of time, we've come back to find several towns and a FOB lost a few times now and it's getting annoying.

So far below is what I have:

_name = name player;
_playerpos1 = getposATL player; 
sleep 300;
_playerpos2 = getposATL player;
if (_playerpos1 == _playerpos2) then {
player systemChat ("_name " + "you have not moved for 5 minutes and will be kicked if stationary for another 10.");
};
sleep 300;

_playerpos2 = getposATL player; 
if (_playerpos1 == _playerpos2) then {
player systemChat ("_name " + "you have not moved for 10 minutes and will be kicked if stationary for another 5.");
};
sleep 240;

_playerpos2 = getposATL player; 
if (_playerpos1 == _playerpos2) then { 
player systemChat ("_name " + "you have not moved for 14 minutes and will be kicked if stationary for another 1.");
};
sleep 60;

_playerpos2 = getposATL player; 
if (_playerpos1 == _playerpos2) then { 
player systemChat ("_name " + "you have not moved for 15 minutes and are being kicked.");
sleep 5;
serverCommand ("#kick " + _name):
};

I can't seem to get the kick to work, there's probably other mistakes I've made that you guys will pickup but I'm lost as to what I'm doing wrong. I did have sideChat messages that I confirmed work spread throughout the script just to make sure each block ran and recuded the timers for testing but removed them and switched the time back to post it here. Any help would be greatly appreciated.


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#2 Posted at 2016-09-25 21:12        
     
Check the wiki page for serverCommand, you'll see this icon: . This means that this scripting command must be executed on the server to work properly in multiplayer.

So you need to use remoteExec and tun the kick code on the server.
("#kick " + profileName) remoteExec ["serverCommand", 2];

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Advertisement


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 58
In-game name: Kobayashi Maru

 
#3 Posted at 2016-09-26 05:21        
     
Where do you run this script. Player has sense only on clients computers (+ hosted server), not on dedicated one.
Prefer special variable _x instead of player, wrapped into:
{
 <your code here >
} forEach allPlayers;

Another problem could be: When do you need to run this script? Repeatable? At this stage, script will run a start of the mission on server, not for JIP for example.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message

Tajin  



Posts: 433
Rank:


Level: Member

Country: de
Location: Bavaria
Occupation: Communications Designer
Age: 34
In-game name: Tajin

 
#4 Posted at 2016-09-26 15:03        
     
You'll have to use a different structure if you want that to work. The code you posted will sleep for a long time even if the player moves so it's not gonna loop correctly.

_name = name player;
while { hasInterface } do {
	_lastpos = getPosATL player
	_c = 0;
	sleep 60;
	while { (getPosATL player) isEqualTo _lastpos } do {
		_c = _c+1;
		switch _c do 
		{
			case 5: 
			{
				player systemChat (_name + " you have not moved for 5 minutes and will be kicked if stationary for another 10.");
			};
			case 10: 
			{
				player systemChat (_name + " you have not moved for 10 minutes and will be kicked if stationary for another 5.");
			};
			case 14: 
			{
				player systemChat (_name + " you have not moved for 14 minutes and will be kicked if stationary for another 1.");
			};
			case 15: 
			{
				player systemChat (_name + " you have not moved for 15 minutes and are being kicked.");
				sleep 5;
				("#kick " + profileName) remoteExec ["serverCommand", 2];
			};			
		};
		sleep 60;
	};
};

this should do. Put it in a file and execVM it from your init.sqf.

There are a lot of very capable people on this forum, willing to spend some of their time to help you out. So if you have a problem, it surely isn't too much to ask that you atleast take the time to describe it properly. Thanks.