Advertisement
OKStyle

Tank Lights System

Mar 14th, 2013
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.49 KB | None | 0 0
  1. #include <a_samp>
  2. // Tank Light System by O.K.Style™
  3. #define TANK_LIGHTS_SYNC_DELAY 30 * 1000
  4. new TankTimer[MAX_PLAYERS char], tlight[MAX_PLAYERS * 2 char];
  5. public OnFilterScriptExit()
  6. {
  7.     for(new i = 0; i < sizeof(tlight); i++) if(IsValidObject(tlight{i})) DestroyObject(tlight{i});
  8.     for(new i = GetMaxPlayers() - 1; i != -1; i--) KillTimer(TankTimer{i});
  9.     return 1;
  10. }
  11. public OnPlayerConnect(playerid) return TogglePlayerClock(playerid, 1);
  12. public OnPlayerDisconnect(playerid, reason) return KillTimer(TankTimer{playerid});
  13. public OnPlayerStateChange(playerid, newstate, oldstate)
  14. {
  15.     if(GetPVarInt(playerid, "TLOff") == 1) return 1;
  16.     if(newstate == PLAYER_STATE_DRIVER)
  17.     {
  18.         new vehicleid = GetPlayerVehicleID(playerid);
  19.         if(GetVehicleModel(vehicleid) != 432) return 1;
  20.         new hour, minute;
  21.         GetPlayerTime(playerid, hour, minute);
  22.         #pragma unused minute
  23.         if(hour < 6 || hour > 21)
  24.         {
  25.             tlight{playerid} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  26.             tlight{playerid + MAX_PLAYERS} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  27.             AttachObjectToVehicle(tlight{playerid}, vehicleid, 1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
  28.             AttachObjectToVehicle(tlight{playerid + MAX_PLAYERS}, vehicleid, -1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
  29.             return 1;
  30.         }
  31.         TankTimer{playerid} = SetTimerEx("CheckTank", TANK_LIGHTS_SYNC_DELAY, 1, "i", playerid);
  32.         return 1;
  33.     }
  34.     if(oldstate == PLAYER_STATE_DRIVER && newstate != PLAYER_STATE_DRIVER)
  35.     {
  36.         if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 432) return 1;
  37.         if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
  38.         if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
  39.         KillTimer(TankTimer{playerid});
  40.         return 1;
  41.     }
  42.     return 1;
  43. }
  44. public OnPlayerCommandText(playerid, cmdtext[])
  45. {
  46.     new cmd[256], idx;
  47.     cmd = strtok(cmdtext, idx);
  48.     if(strcmp(cmd, "/time", true) == 0)
  49.     {
  50.         if(!IsPlayerAdmin(playerid)) return 1;
  51.         for(new i = GetMaxPlayers() - 1; i != -1; i--)
  52.         {
  53.             if(!IsPlayerConnected(i)) continue;
  54.             SetPlayerTime(i, strval(strtok(cmdtext, idx)), 0);
  55.         }
  56.         return 1;
  57.     }
  58.     if(strcmp(cmdtext, "/tloff", true) == 0)
  59.     {
  60.         if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 432) return 1;
  61.         if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
  62.         if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
  63.         SetPVarInt(playerid, "TLMC", 1); // Tank Lights Manual Control
  64.         return 1;
  65.     }
  66.     if(strcmp(cmdtext, "/tlon", true) == 0)
  67.     {
  68.         new vehicleid = GetPlayerVehicleID(playerid);
  69.         if(GetVehicleModel(vehicleid) != 432) return 1;
  70.         if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
  71.         if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
  72.         tlight{playerid} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  73.         tlight{playerid + MAX_PLAYERS} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  74.         AttachObjectToVehicle(tlight{playerid}, vehicleid, 1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
  75.         AttachObjectToVehicle(tlight{playerid + MAX_PLAYERS}, vehicleid, -1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
  76.         SetPVarInt(playerid, "TLMC", 1);
  77.         return 1;
  78.     }
  79.     if(strcmp(cmdtext, "/tld", true) == 0) return DeletePVar(playerid, "TLMC");
  80.     return 0;
  81. }
  82. forward CheckTank(playerid);
  83. public CheckTank(playerid)
  84. {
  85.     if(GetPVarInt(playerid, "TLMC") == 1) return 1;
  86.     new vehicleid = GetPlayerVehicleID(playerid);
  87.     if(GetVehicleModel(vehicleid) != 432) return 1;
  88.     new hour, minute;
  89.     GetPlayerTime(playerid, hour, minute);
  90.     #pragma unused minute
  91.     if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
  92.     if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
  93.     if(hour < 6 || hour > 21)
  94.     {
  95.         tlight{playerid} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  96.         tlight{playerid + MAX_PLAYERS} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  97.         AttachObjectToVehicle(tlight{playerid}, vehicleid, 1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
  98.         AttachObjectToVehicle(tlight{playerid + MAX_PLAYERS}, vehicleid, -1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
  99.         return 1;
  100.     }
  101.     return 1;
  102. }
  103. stock strtok(const string[], &index)
  104. {
  105.     new length = strlen(string);
  106.     while ((index < length) && (string[index] <= ' ')) index++;
  107.     new offset = index, result[20];
  108.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) result[index - offset] = string[index], index++;
  109.     result[index - offset] = EOS;
  110.     return result;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement