Advertisement
RaFaeLs

AFK system by RaFaeL

Sep 18th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.03 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  4.  
  5. public OnFilterScriptInit()
  6. {
  7.     print("\n--------------------------------------");
  8.     print(" [RaFaeL] AFK system v0.1 by zRaFaeL loaded! ");
  9.     print("--------------------------------------\n");
  10.     return 1;
  11. }
  12.  
  13. enum eSpawns {
  14.     animname[64],
  15.     Float:x,
  16.     Float:y,
  17.     Float:z,
  18.     Float:a
  19. }
  20. new Spawns[] [eSpawns] = {
  21.     //{anim, x, y, z, a}
  22.     {"dnce_M_a",-2453.0132,1145.1104,65.2344,178.8782},
  23.     {"dnce_M_b",-2473.6882,1544.6368,36.8047,268.4924},
  24.     {"dnce_M_c",-1954.2953,1346.4600,31.2217,179.8182}
  25. };
  26.  
  27. enum eLastPos {
  28.     Float:lx,
  29.     Float:ly,
  30.     Float:lz,
  31.     Float:la
  32. }
  33. new LastPosition[MAX_PLAYERS][eLastPos];
  34.  
  35. // Change this!
  36. #define COLOR_INAFK 0xFF0000FF
  37. #define COLOR_OUTAFK 0xFF0000FF
  38.  
  39. new str[128];
  40.  
  41. public OnPlayerDisconnect(playerid, reason)
  42. {
  43.     SetPVarInt(playerid, "afk", 0);
  44.     return 1;
  45. }
  46.  
  47. public OnPlayerText(playerid, text[])
  48. {
  49.     if(GetPVarInt(playerid, "afk") >= 1) return Afk(playerid, GetPVarInt(playerid, "afk"));
  50.     return 1;
  51. }
  52.  
  53. public OnPlayerCommandText(playerid, cmdtext[])
  54. {
  55.     dcmd(AFK, 3, cmdtext);
  56.    
  57.     if(GetPVarInt(playerid, "afk") >= 1) return Afk(playerid, GetPVarInt(playerid, "afk"));
  58.    
  59.     // Here commands...
  60.    
  61.     return 0;
  62. }
  63.  
  64. dcmd_AFK(playerid, params[])
  65. {
  66.     if(strlen(params) > 0) {
  67.         return Afk(playerid, GetPVarInt(playerid, "afk"), params);
  68.     } else {
  69.         return Afk(playerid, GetPVarInt(playerid, "afk"));
  70.     }
  71. }
  72.  
  73. stock GetName(playerid) {
  74.         GetPlayerName(playerid, str, MAX_PLAYER_NAME);
  75.         return str;
  76. }
  77.  
  78. stock Afk(playerid, afkstats, reason[] = "no-reason") {
  79.     if(afkstats < 1) {
  80.         SetPVarInt(playerid, "afk", 1); //Set player afk stats to 1 - true
  81.         TogglePlayerControllable(playerid,0);
  82.  
  83.         //Save last position
  84.         GetPlayerPos(playerid, LastPosition[playerid][lx], LastPosition[playerid][ly], LastPosition[playerid][lz]);
  85.         GetPlayerFacingAngle(playerid, LastPosition[playerid][la]);
  86.        
  87.         //Set player to random spawn
  88.         new spawnid = random(sizeof(Spawns));
  89.         SetPlayerPos(playerid,Spawns[spawnid][x],Spawns[spawnid][y],Spawns[spawnid][z]);
  90.         SetPlayerFacingAngle(playerid, Spawns[spawnid][a]);
  91.         ApplyAnimation(playerid,"DANCING",Spawns[spawnid][animname],4.0,1,0,0,0,-1);
  92.  
  93.         format(str, sizeof(str), "The player %s is now afk(away from keyboard) [reason: %s]", GetName(playerid), reason);
  94.         return SendClientMessageToAll(COLOR_INAFK, str);
  95.     } else {
  96.         SetPVarInt(playerid, "afk", 0); //Set player afk stats to 0 - false
  97.         TogglePlayerControllable(playerid,1);
  98.  
  99.         //Set player to the last position
  100.         SetPlayerPos(playerid, LastPosition[playerid][lx], LastPosition[playerid][ly], LastPosition[playerid][lz]);
  101.         SetPlayerFacingAngle(playerid, LastPosition[playerid][la]);
  102.  
  103.         format(str, sizeof(str), "The player %s is now back to game", GetName(playerid));
  104.         return SendClientMessageToAll(COLOR_OUTAFK, str);
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement