25.04.2011, 21:22
PHP код:
//==============================================================================
// -> Includes <-
//==============================================================================
#include <a_samp>
#include <JunkBuster>
//==============================================================================
// -> Script Colors <-
//==============================================================================
#define RED 0xFF0000FF
#define GREEN 0x009500AA
#define GREEN2 0x00DD00AA
#define GREY 0xAEAEAEA4
//==============================================================================
// -> Configuration <-
// true - Enable | false - Disable
//==============================================================================
#define AutoAfk true //Enable/disable Player Automatically come into AFK mode after Delay.
#define AutoKick true //Enable/disable Player Automatically Kick into AFK mode after Delay.
#define Music true //Enable/disable Players listen Music in AFK Mode.
#define RotationCam true //Enable/disable Players Rotating Camera in AFK Mode
#define SaveAfkLog true //Enable/disable Save in Log file players who Entered and Left the AFK Mode
#define AfkSecondMsg true //Enable/Disable The textdraw that Indicates the time that the player are in AFK Mode
#define UseOneLog false //Enable/disable Save in ONE Log file players who Entered and Left the AFK Mode
#define AutoAfk_Delay 60 //Seconds before player enter in AFK Mode (If it does not move, and the 'AutoAfk' is enabled)(Not Below 30)
#define AutoKick_Delay 600 //Seconds before kicking AFK Players (If 'AutoKick is enabled) (Not Below 60)
//==============================================================================
enum Info
{
ObjBed,
tTime,
AfkTime,
bool:InAfk,
Float:Pos[4],
key[3],
pName[24],
bool:pSpawned,
};
new LpInfo[MAX_PLAYERS][Info];
new Float:MoveCam = 0.0;
new Text:TextAfkMsg[MAX_PLAYERS];
new Text:TextTimer[MAX_PLAYERS];
new lstring[80];
new TimerString[120];
new ScoreTimer;
enum Config
{
LAutoAFK_Time,
LAutoKick_Time,
LMusic,
LAutoAFK,
LAutoKick,
LRotoCam
};
new LConfig[Config];
new Musics_IDs[] = {
1068, 1183, 1076, 1097, 1068,
1185, 1187, 1062, 1185, 1187,
1097, 1097,1062, 1068
};
new Dances_IDs[][] = {
"DAN_Loop_A","dnce_M_a","dnce_M_c"
};
forward GiveScore(playerid);
forward UpdateAfkSystem();
//==============================================================================
// -> ScriptInit <-
//==============================================================================
public OnFilterScriptInit()
{
UpdateConfiguration();
LoadTextDraws();
MoveCam = 100/4000.0;
ScoreTimer = SetTimer("UpdateAfkSystem", 100, true);
SetTimer("GiveScore", 60000, true);
print("\n");
print("_________________________________");
print(" ");
print(" LuX Ultimate AFK System v2.0 ");
print(" ------------- ");
print(" By LuxurioN ");
print("_________________________________");
print("\n");
}
//==============================================================================
// -> ScriptExit <-
//==============================================================================
public OnFilterScriptExit()
{
for(new i; i<MAX_PLAYERS; i++)
TextDrawHideForPlayer(i, TextTimer[i]);
return 1;
}
//==============================================================================
// -> Player Connect <-
//==============================================================================
public OnPlayerConnect(playerid)
{
ResetPInfo(playerid);
LoadAnims(playerid);
return true;
}
//==============================================================================
// -> Player Spawn <-
//==============================================================================
public OnPlayerSpawn(playerid)
{
LpInfo[playerid][pSpawned] = true;
return true;
}
//==============================================================================
// -> Player Death <-
//==============================================================================
public OnPlayerDeath(playerid, killerid, reason)
{
LpInfo[playerid][pSpawned] = false;
return true;
}
//==============================================================================
// -> Commands <-
//==============================================================================
public OnPlayerCommandText(playerid, cmdtext[])
{
//======================
// AFK LIST
//======================
if(strcmp("/afklist", cmdtext, true, 7) == 0)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SendClientMessage(playerid, 0x009E00AA, "____________|- AFK Players -|____________");
if(!LpInfo[i][InAfk]) {
return SendClientMessage(playerid, RED, "In moment any players is on Afk Mode!");
}
if(LpInfo[i][InAfk])
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(i, PlayerName, MAX_PLAYER_NAME);
format(lstring, 256, "Player: \"%s\" | ID: %d", PlayerName, i);
SendClientMessage(playerid, GREEN2, lstring);
}
}
}
return 1;
}
//======================
// AFK
//======================
if(!strcmp(cmdtext, "/afk"))
{
if(LpInfo[playerid][pSpawned])
EnterInAfk(playerid);
else
SendClientMessage(playerid, RED, "|- AFK Error: You are not Spawned! -|");
return true;
}
else if(LpInfo[playerid][InAfk])
return true;
return false;
}
public OnPlayerText(playerid, text[])
{
if(LpInfo[playerid][InAfk])
return false;
return true;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == 16 && LpInfo[playerid][InAfk])
EnterInAfk(playerid);
}
//==============================================================================
// -> Update AFK <-
//==============================================================================
public UpdateAfkSystem()
{
for(new i = 0, j = GetMaxPlayers(); i < j; i++)
{
if(IsPlayerConnected(i) && LpInfo[i][pSpawned])
{
GetPlayerKeys(i,LpInfo[i][key][0],LpInfo[i][key][1],LpInfo[i][key][2]);
if(LpInfo[i][key][0] + LpInfo[i][key][1] + LpInfo[i][key][2] == 0 && !LpInfo[i][InAfk])
{
LpInfo[i][AfkTime] ++;
if(LpInfo[i][AfkTime] == LConfig[LAutoAFK_Time])
EnterInAfk(i);
}
else LpInfo[i][AfkTime] = 0;
if (LpInfo[i][InAfk])
{
UpdateTextDraw(i);
if(LConfig[LRotoCam])
RotAfkCam(i);
}
}
}
}
//==============================================================================
// -> Camera Rotating <-
//==============================================================================
RotAfkCam(playerid)
{
LpInfo[playerid][Pos][3] += MoveCam;
SetPlayerCameraPos(playerid,
LpInfo[playerid][Pos][0] + floatcos(LpInfo[playerid][Pos][3])*5,
LpInfo[playerid][Pos][1] + floatsin(LpInfo[playerid][Pos][3])*5,
LpInfo[playerid][Pos][2] + 1);
SetPlayerCameraLookAt(playerid,LpInfo[playerid][Pos][0], LpInfo[playerid][Pos][1],LpInfo[playerid][Pos][2] + 0.5);
}
//==============================================================================
// -> Player Enter in AFK <-
//==============================================================================
EnterInAfk(playerid)
{
LpInfo[playerid][InAfk] = !LpInfo[playerid][InAfk];
GetPlayerName(playerid, LpInfo[playerid][pName], 24);
if(LpInfo[playerid][InAfk])
{
//======================
// Enter
//======================
#if AfkSecondMsg == true
GameTextForPlayer(playerid,"~w~~n~~n~~n~~n~~n~~n~~n~Type ~b~ENTER ~w~or ~g~/afk ~w~to exit",2000,3);
#endif
format(lstring,sizeof(lstring),"|- \"%s\" is in AFK Mode! (Busy/Unavailable) -|",LpInfo[playerid][pName]);
SendClientMessageToAll(GREEN, lstring);
format(lstring,sizeof(lstring),"Player \"%s\" has entered in AFK Mode!",LpInfo[playerid][pName]);
#if UseOneLog == true
SaveLog("AfkLog",lstring);
#else
SaveLog("EnteredAfkLog",lstring);
#endif
strins(LpInfo[playerid][pName],"[AFK]",0);
SetPlayerName(playerid, LpInfo[playerid][pName]);
TogglePlayerControllable(playerid, false);
KillTimer(ScoreTimer);
GetPlayerPos(playerid,LpInfo[playerid][Pos][0],LpInfo[playerid][Pos][1], LpInfo[playerid][Pos][2]);
GetPlayerFacingAngle(playerid, LpInfo[playerid][Pos][3]);
for(new i=0; i<MAX_PLAYERS; i++)
{
TextDrawShowForPlayer(i, TextTimer[i]);
TextDrawShowForPlayer(i, TextAfkMsg[i]);
}
LpInfo[playerid][tTime] = GetTickCount();
AfkEffects(playerid, true);
//======================
}
else
{
//======================
// Exit
//======================
strdel(LpInfo[playerid][pName], 0, 5);
SetPlayerName(playerid, LpInfo[playerid][pName]);
format(lstring,sizeof(lstring),"|- \"%s\" have Returned to Game! (Online) -|",LpInfo[playerid][pName]);
SendClientMessageToAll(GREEN2, lstring);
format(lstring,sizeof(lstring),"Player \"%s\" has exited the AFK Mode!",LpInfo[playerid][pName]);
#if UseOneLog == true
SaveLog("AfkLog",lstring);
#else
SaveLog("ExitedAfkLog",lstring);
#endif
TogglePlayerControllable(playerid, true);
ScoreTimer = SetTimer("GiveScore", 60000, true);
SetCameraBehindPlayer(playerid);
for(new i=0; i<MAX_PLAYERS; i++)
{
TextDrawHideForPlayer(i, TextTimer[i]);
TextDrawHideForPlayer(i, TextAfkMsg[i]);
}
LpInfo[playerid][tTime] = 0;
AfkEffects(playerid, false);
//======================
}
}
//==============================================================================
// -> Save in Log - Players in AFK <-
//==============================================================================
SaveLog(logname[],text[])
{
#if SaveAfkLog == true
new File:Lfile;
new filepath[256];
new string[256];
new year,month,day;
new hour,minute,second;
getdate(year,month,day);
gettime(hour,minute,second);
format(filepath,sizeof(filepath),"Afk/%s.txt",logname);
Lfile = fopen(filepath,io_append);
format(string,sizeof(string),"[%02d/%02d/%02d | %02d:%02d:%02d] %s\r\n",day,month,year,hour,minute,second,text);
fwrite(Lfile,string);
fclose(Lfile);
#endif
return 1;
}
//==============================================================================
// -> Afk Effects (Anims & Musics) <-
//==============================================================================
AfkEffects(playerid, bool:toggle)
{
if (toggle)
{
if (LConfig[LMusic])
PlayerPlaySound(playerid,Musics_IDs[random(sizeof(Musics_IDs))], 0.0,0.0,0.0);
if (!IsPlayerInAnyVehicle(playerid))
{
switch(random(6))
{
case 0:
{
ApplyAnimation(playerid,"INT_HOUSE","BED_Loop_R",4.0,1,0,0,0,0);
LpInfo[playerid][ObjBed] = CreateObject(1771,LpInfo[playerid][Pos][0],LpInfo[playerid][Pos][1],LpInfo[playerid][Pos][2]-0.48,0.0,0.0,LpInfo[playerid][Pos][3]+75.0);
}
case 1:
ApplyAnimation(playerid,"ped","cower",3.0,1,0,0,0,0);
case 2:
ApplyAnimation(playerid,"BEACH","bather",4.0,1,0,0,0,0);
case 3:
ApplyAnimation(playerid,"DANCING",Dances_IDs[random(sizeof(Dances_IDs))],4.0,1,0,0,0,0);
case 4:
ApplyAnimation(playerid,"COP_AMBIENT","Coplook_loop",4.0,0,1,1,1,-1);
case 5:
ApplyAnimation(playerid,"BEACH","ParkSit_M_loop",4.0,1,0,0,0,0);
}
}
}
else
{
ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 0, 0, 0);
if (LConfig[LMusic])
PlayerPlaySound(playerid, 1063, 0.0,0.0,0.0);
if (IsValidObject(LpInfo[playerid][ObjBed]))
{
DestroyObject(LpInfo[playerid][ObjBed]);
LpInfo[playerid][ObjBed] = 0;
}
}
}
//==============================================================================
// -> Reset Player AFK Stats <-
//==============================================================================
ResetPInfo(playerid)
{
LpInfo[playerid][InAfk] = false;
LpInfo[playerid][pSpawned] = false;
LpInfo[playerid][tTime] = 0;
LpInfo[playerid][AfkTime] = 0;
LpInfo[playerid][ObjBed] = 0;
}
//==============================================================================
// -> Update Timer TextDraw <-
//==============================================================================
UpdateTextDraw(playerid)
{
new Time = floatround((GetTickCount() - LpInfo[playerid][tTime]) / 1000),
Secs = Time % 60,
Mins = floatround((Time/60), floatround_floor),
KickTime = floatround(LConfig[LAutoKick_Time] - Time);
format(lstring, sizeof(lstring), "~g~%02d:%02d",Mins, Secs);
TextDrawSetString(TextTimer[playerid], lstring);
if (LConfig[LAutoKick] && KickTime <= floatround(LConfig[LAutoKick_Time]/3))
{
format(lstring, sizeof(lstring), "~b~AutoKick ~n~ ~r~%d",KickTime);
TextDrawSetString(TextTimer[playerid], lstring);
if (KickTime < 1)
{
EnterInAfk(playerid);
format(lstring, sizeof(lstring), "|- You have been Automatically Kicked! | Reason: Exceeded %d Seconds in AFK Mode! -|",LConfig[LAutoKick_Time]);
SendClientMessage(playerid,RED,lstring);
format(lstring, sizeof(lstring), "~w~~n~~n~~n~~n~Exceeded ~r~%d ~w~Seconds in ~y~AFK Mode!",LConfig[LAutoKick_Time]);
GameTextForPlayer(playerid,lstring,60000,3);
TextDrawSetString(TextAfkMsg[playerid], "You are ~r~Kicked!");
TextDrawShowForPlayer(playerid, TextAfkMsg[playerid]);
TogglePlayerControllable(playerid, false);
for(new i = 0; i < 15; i++)
SendClientMessage(playerid,0," ");
Kick(playerid);
}
}
}
//==============================================================================
// -> Verify and Update Configs <-
//==============================================================================
UpdateConfiguration()
{
LConfig[LMusic] = Music;
LConfig[LRotoCam] = RotationCam;
LConfig[LAutoAFK] = AutoAfk;
LConfig[LAutoKick] = AutoKick;
LConfig[LAutoAFK_Time] = AutoAfk_Delay;
LConfig[LAutoKick_Time] = AutoKick_Delay;
//----------------------
if(LConfig[LAutoKick_Time] < 60) LConfig[LAutoKick_Time] = 60;
if(LConfig[LAutoAFK_Time] < 30) LConfig[LAutoAFK_Time] = 30;
//----------------------
LConfig[LAutoAFK_Time] = floatround((LConfig[LAutoAFK_Time]*1000)/100);
}
//==============================================================================
// -> PreLoad TextDraws <-
//==============================================================================
LoadTextDraws()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
format(TimerString, sizeof(TimerString), " ");
TextTimer[i] = TextDrawCreate(300.000000, 122.000000, TimerString);
TextDrawBackgroundColor(TextTimer[i], 255);
TextDrawFont(TextTimer[i], 1);
TextDrawLetterSize(TextTimer[i], 0.340000, 1.000000);
TextDrawColor(TextTimer[i], -1);
TextDrawSetOutline(TextTimer[i], 0);
TextDrawSetProportional(TextTimer[i], 1);
TextDrawSetShadow(TextTimer[i], 1);
TextAfkMsg[i] = TextDrawCreate(227.000000, 92.000000, "You are in ~r~AFK!");
TextDrawBackgroundColor(TextAfkMsg[i], 255);
TextDrawFont(TextAfkMsg[i], 1);
TextDrawLetterSize(TextAfkMsg[i], 0.699999, 2.699999);
TextDrawColor(TextAfkMsg[i], -1);
TextDrawSetOutline(TextAfkMsg[i], 1);
TextDrawSetProportional(TextAfkMsg[i], 1);
}
}
//==============================================================================
// -> PreLoad Anims <-
//==============================================================================
LoadAnims(playerid)
{
ApplyAnimation(playerid,"CARRY", "null",0.0,0,0,0,0,0);
ApplyAnimation(playerid,"DANCING", "null",0.0,0,0,0,0,0);
ApplyAnimation(playerid,"ped", "null",0.0,0,0,0,0,0);
ApplyAnimation(playerid,"INT_HOUSE", "null",0.0,0,0,0,0,0);
ApplyAnimation(playerid,"BEACH", "null",0.0,0,0,0,0,0);
ApplyAnimation(playerid,"COP_AMBIENT", "null" ,0.0,0,0,0,0,0);
}
//==============================================================================
public GiveScore()
{
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
SetPlayerScore(i, GetPlayerScore(i) + 1);
}
}
}
// ©The LuxurioN - All Rights Reserved.