AX.ChatCommand.afk = {};
function AX.ChatCommand.afk:func(player, chatMsg)
--================================================== =================================
-- your Config.
--================================================== =================================
local Delay = 15; -- in Minutes
local maxafkUser = 2; -- max. Afk User, Exception CoAdmins and Admins
--================================================== =================================
if (player.actor:GetSpectatorMode()~=0) then
XMessageChatToPlayer( player, "[ERROR] You must in Game to use!");
return;
end
if (player:IsDead()) then
return;
end
local preGame=g_gameRules:GetState()=="PreGame";
if (preGame) then
XMessageChatToPlayer( player, "[ERROR] Please wait until the game starts!");
return;
end
if (player.WelcomeMsg) then
XMessageChatToPlayer( player, "[ERROR] Until 60 seconds after start available!");
return;
end
local afkDelay = math.floor(Delay * 60);
if (player.AFK and player.AFK.Status== "false") and (not XIsAdmin(player) and not XIsCoAdmin(player)) then
local mustWait = DelayControl(Delay, player.AFK.goTime);
if (mustWait) then
XMessageChatToPlayer( player, "[ERROR] You can only use !afk every "..Delay.." Minutes (Remaining Time: "..mustWait.." Minutes)!");
return;
end
end
if (XIsProtected(player)) then
XMessageChatToPlayer( player, "[ERROR] Go first out from Admin Mode");
return;
end
local players = g_gameRules.game:GetPlayers();
local counter = 0;
for i, check in ipairs(players) do
if (not XIsAdmin(check)) and (not XIsCoAdmin(check)) then
if (check.AFK and check.AFK.Status=="true") then
counter = counter + 1;
end
end
end
if (counter>=maxafkUser) and (not XIsAdmin(player)) and (not XIsCoAdmin(player)) then
if (not player.AFK) or (player.AFK and player.AFK.Status=="false") then
XMessageChatToPlayer( player, "[ERROR] Maximum "..maxafkUser.." Player can simultaneously use afk!");
return;
end
end
if (player:IsOnVehicle()) then
XMessageChatToPlayer( player, "[ERROR] Leave your Vehicle!");
return;
end
local name = player:GetName();
if (not player.AFK or player.AFK.Status== "false") then
local Count = 0;
for i, actor in ipairs(players) do
if (actor.inventory:GetCountOfClass("TACGun")==1) then
Count = Count + 1;
end
end
if (Count>2) then
XMessageChatToPlayer(player, "[ERROR] During the TacParty !afk is not Possible!");
return;
elseif (player.inventory:GetItemByClass("TACGun")) then
XMessageChatToPlayer(player, "[ERROR] !afk is not Possible when you have a TACGun, drop the Weapon to go AFK!");
return;
end
local Pos = player:GetWorldPos();
player.AFK = {Pos = Pos; goTime = _time; Status = "true";};
g_gameRules.game:SetInvulnerability(player.id, true, 3);
g_gameRules.game:MovePlayer(player.id, {x = Pos.x, y = Pos.y, z = Pos.z + 1200}, player:GetWorldAngles());
g_gameRules:CreateExplosion(player.id,weaponId,1,{ x = Pos.x, y = Pos.y, z = Pos.z - 1},g_Vectors.up,1,1,1,1,"explosions.cluster_bomb.i mpact",0.2, 0.2, 0.2, 0.2);
g_gameRules:CreateExplosion(player.id,weaponId,1,{ x = Pos.x, y = Pos.y, z = Pos.z - 0.5},g_Vectors.up,1,1,1,1,"explosions.Grenade_SCAR .alien",0.2, 0.2, 0.2, 0.2);
XMessageChatToAll( name.." go AwayFromKeyboard..");
XPlayerChangeName(player, XAddTag(name, "[AFK]"));
else
local Pos = player.AFK.Pos;
player.AFK.Status = "false";
g_gameRules.game:SetInvulnerability(player.id, true, 3);
g_gameRules.game:MovePlayer(player.id, {x = Pos.x, y = Pos.y, z = Pos.z}, player:GetWorldAngles());
XRemoveTag(player, "[AFK]");
XMessageChatToAll(player:GetName().." is back..");
end
end