Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- // Tank Light System by O.K.Style™
- #define TANK_LIGHTS_SYNC_DELAY 30 * 1000
- new TankTimer[MAX_PLAYERS char], tlight[MAX_PLAYERS * 2 char];
- public OnFilterScriptExit()
- {
- for(new i = 0; i < sizeof(tlight); i++) if(IsValidObject(tlight{i})) DestroyObject(tlight{i});
- for(new i = GetMaxPlayers() - 1; i != -1; i--) KillTimer(TankTimer{i});
- return 1;
- }
- public OnPlayerConnect(playerid) return TogglePlayerClock(playerid, 1);
- public OnPlayerDisconnect(playerid, reason) return KillTimer(TankTimer{playerid});
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(GetPVarInt(playerid, "TLOff") == 1) return 1;
- if(newstate == PLAYER_STATE_DRIVER)
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- if(GetVehicleModel(vehicleid) != 432) return 1;
- new hour, minute;
- GetPlayerTime(playerid, hour, minute);
- #pragma unused minute
- if(hour < 6 || hour > 21)
- {
- tlight{playerid} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- tlight{playerid + MAX_PLAYERS} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- AttachObjectToVehicle(tlight{playerid}, vehicleid, 1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
- AttachObjectToVehicle(tlight{playerid + MAX_PLAYERS}, vehicleid, -1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
- return 1;
- }
- TankTimer{playerid} = SetTimerEx("CheckTank", TANK_LIGHTS_SYNC_DELAY, 1, "i", playerid);
- return 1;
- }
- if(oldstate == PLAYER_STATE_DRIVER && newstate != PLAYER_STATE_DRIVER)
- {
- if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 432) return 1;
- if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
- if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
- KillTimer(TankTimer{playerid});
- return 1;
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256], idx;
- cmd = strtok(cmdtext, idx);
- if(strcmp(cmd, "/time", true) == 0)
- {
- if(!IsPlayerAdmin(playerid)) return 1;
- for(new i = GetMaxPlayers() - 1; i != -1; i--)
- {
- if(!IsPlayerConnected(i)) continue;
- SetPlayerTime(i, strval(strtok(cmdtext, idx)), 0);
- }
- return 1;
- }
- if(strcmp(cmdtext, "/tloff", true) == 0)
- {
- if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 432) return 1;
- if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
- if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
- SetPVarInt(playerid, "TLMC", 1); // Tank Lights Manual Control
- return 1;
- }
- if(strcmp(cmdtext, "/tlon", true) == 0)
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- if(GetVehicleModel(vehicleid) != 432) return 1;
- if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
- if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
- tlight{playerid} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- tlight{playerid + MAX_PLAYERS} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- AttachObjectToVehicle(tlight{playerid}, vehicleid, 1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
- AttachObjectToVehicle(tlight{playerid + MAX_PLAYERS}, vehicleid, -1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
- SetPVarInt(playerid, "TLMC", 1);
- return 1;
- }
- if(strcmp(cmdtext, "/tld", true) == 0) return DeletePVar(playerid, "TLMC");
- return 0;
- }
- forward CheckTank(playerid);
- public CheckTank(playerid)
- {
- if(GetPVarInt(playerid, "TLMC") == 1) return 1;
- new vehicleid = GetPlayerVehicleID(playerid);
- if(GetVehicleModel(vehicleid) != 432) return 1;
- new hour, minute;
- GetPlayerTime(playerid, hour, minute);
- #pragma unused minute
- if(IsValidObject(tlight{playerid})) DestroyObject(tlight{playerid});
- if(IsValidObject(tlight{playerid + MAX_PLAYERS})) DestroyObject(tlight{playerid + MAX_PLAYERS});
- if(hour < 6 || hour > 21)
- {
- tlight{playerid} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- tlight{playerid + MAX_PLAYERS} = CreateObject(19280, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- AttachObjectToVehicle(tlight{playerid}, vehicleid, 1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
- AttachObjectToVehicle(tlight{playerid + MAX_PLAYERS}, vehicleid, -1.6, 3.83, 0.675, 15.075, 0.0, 0.0);
- return 1;
- }
- return 1;
- }
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' ')) index++;
- new offset = index, result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) result[index - offset] = string[index], index++;
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement