Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILTERSCRIPT
- #include <a_samp>
- #include <evf> // http://forum.sa-mp.com/showthread.php?t=486060
- #include <progress2> // http://forum.sa-mp.com/showthread.php?t=537468
- #include <streamer> // http://forum.sa-mp.com/showthread.php?t=102865
- #include <izcmd> // http://forum.sa-mp.com/showthread.php?t=576114
- #define TRASH_BAG_VALUE (125) // value of a collected trash bag (default: 125)
- #define REFILL_TIME (300) // trash container refill time - in seconds (default: 300)
- #define ATTACHMENT_INDEX (4) // for setplayerattachedobject (default: 4)
- #define TRASH_LIMIT (10) // trashmaster capacity (default: 10)
- // location, x, y, z
- {"Los Santos", 2432.553710, -2115.611328, 13.546875},
- {"Las Venturas", 981.711303, 2168.738769, 10.820312},
- {"San Fierro", -1044.592895, -606.348876, 32.007812}
- };
- new
- bool: HasTrash[MAX_PLAYERS],
- TrashCP[MAX_PLAYERS] = {-1, ...},
- FactoryIcons[MAX_PLAYERS][sizeof(FactoryData)],
- PlayerText: CapacityText[MAX_PLAYERS],
- PlayerBar: CapacityBar[MAX_PLAYERS];
- new
- LoadedTrash[MAX_VEHICLES];
- Trash_InitPlayer(playerid)
- {
- HasTrash[playerid] = false;
- TrashCP[playerid] = -1;
- for(new i; i < sizeof(FactoryData); i++)
- {
- TogglePlayerDynamicCP(playerid, FactoryData[i][FactoryCP], 0);
- FactoryIcons[playerid][i] = -1;
- }
- CapacityText[playerid] = CreatePlayerTextDraw(playerid, 32.000000, 290.000000, "Vehicle Capacity (0/10)");
- PlayerTextDrawBackgroundColor(playerid, CapacityText[playerid], 255);
- PlayerTextDrawFont(playerid, CapacityText[playerid], 1);
- PlayerTextDrawLetterSize(playerid, CapacityText[playerid], 0.200000, 1.000000);
- PlayerTextDrawColor(playerid, CapacityText[playerid], -1);
- PlayerTextDrawSetOutline(playerid, CapacityText[playerid], 1);
- PlayerTextDrawSetProportional(playerid, CapacityText[playerid], 1);
- PlayerTextDrawSetSelectable(playerid, CapacityText[playerid], 0);
- CapacityBar[playerid] = CreatePlayerProgressBar(playerid, 30.000000, 304.000000, 118.500000, 6.199999, -1429936641, TRASH_LIMIT, 0);
- return 1;
- }
- Trash_ResetPlayer(playerid, removeUI = 0)
- {
- if(IsPlayerAttachedObjectSlotUsed(playerid, ATTACHMENT_INDEX)) RemovePlayerAttachedObject(playerid, ATTACHMENT_INDEX);
- if(IsValidDynamicCP(TrashCP[playerid])) DestroyDynamicCP(TrashCP[playerid]);
- HasTrash[playerid] = false;
- TrashCP[playerid] = -1;
- if(removeUI)
- {
- PlayerTextDrawDestroy(playerid, CapacityText[playerid]);
- DestroyPlayerProgressBar(playerid, CapacityBar[playerid]);
- }
- return 1;
- }
- Trash_ShowCapacity(playerid)
- {
- new vehicleid = GetPlayerVehicleID(playerid), capacity_string[32];
- format(capacity_string, sizeof(capacity_string), "Vehicle Capacity (%d/%d)", LoadedTrash[vehicleid], TRASH_LIMIT);
- PlayerTextDrawSetString(playerid, CapacityText[playerid], capacity_string);
- PlayerTextDrawShow(playerid, CapacityText[playerid]);
- SetPlayerProgressBarValue(playerid, CapacityBar[playerid], LoadedTrash[vehicleid]);
- ShowPlayerProgressBar(playerid, CapacityBar[playerid]);
- return 1;
- }
- Trash_Closest(playerid)
- {
- new closest_id = -1, Float: dist = 3.0, Float: tempdist;
- for(new i; i < sizeof(TrashData); i++)
- {
- tempdist = GetPlayerDistanceFromPoint(playerid, TrashData[i][TrashX], TrashData[i][TrashY], TrashData[i][TrashZ]);
- if(tempdist > 3.0) continue;
- if(tempdist <= dist)
- {
- dist = tempdist;
- closest_id = i;
- }
- }
- return closest_id;
- }
- public OnFilterScriptInit()
- {
- new label[128];
- for(new i; i < sizeof(TrashData); i++)
- {
- format(label, sizeof(label), "%s\n{FFFFFF}\n/pickup to collect.", (TrashData[i][TrashType] == TYPE_BIN) ? ("Trash Bin") : ("Dumpster"));
- TrashData[i][TrashLabel] = CreateDynamic3DTextLabel(label, 0x2ECC71FF, TrashData[i][TrashX], TrashData[i][TrashY], TrashData[i][TrashZ]+1.25, 15.0, .testlos = 1);
- TrashData[i][TrashLevel] = (TrashData[i][TrashType] == TYPE_BIN) ? 1 : 2;
- }
- for(new i; i < sizeof(FactoryData); i++)
- {
- format(label, sizeof(label), "Recycling Factory - %s\n\n{FFFFFF}Current Trash Bags: {F39C12}0\n{FFFFFF}Bring trash here to earn money!", FactoryData[i][FactoryName]);
- FactoryData[i][FactoryLabel] = CreateDynamic3DTextLabel(label, 0x2ECC71FF, FactoryData[i][FactoryX], FactoryData[i][FactoryY], FactoryData[i][FactoryZ] + 0.5, 15.0, .testlos = 1);
- FactoryData[i][FactoryCP] = CreateDynamicCP(FactoryData[i][FactoryX], FactoryData[i][FactoryY], FactoryData[i][FactoryZ], 6.0);
- }
- for(new i, m = GetPlayerPoolSize(); i <= m; i++)
- {
- if(!IsPlayerConnected(i)) continue;
- Trash_InitPlayer(i);
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i, m = GetPlayerPoolSize(); i <= m; i++)
- {
- if(!IsPlayerConnected(i)) continue;
- Trash_ResetPlayer(i, 1);
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Trash_InitPlayer(playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(HasTrash[playerid]) Trash_ResetPlayer(playerid);
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER)
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- if(GetVehicleModel(vehicleid) == 408)
- {
- if(LoadedTrash[vehicleid] > 0) {
- new string[128];
- format(string, sizeof(string), "TRASHMASTER JOB: {FFFFFF}This vehicle has {F39C12}%d {FFFFFF}trash bags which is worth {2ECC71}$%d.", LoadedTrash[vehicleid], LoadedTrash[vehicleid] * TRASH_BAG_VALUE);
- SendClientMessage(playerid, 0x2ECC71FF, string);
- SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You can sell your trash bags to recycling factories marked by a truck icon.");
- for(new i; i < sizeof(FactoryData); i++)
- {
- FactoryIcons[playerid][i] = CreateDynamicMapIcon(FactoryData[i][FactoryX], FactoryData[i][FactoryY], FactoryData[i][FactoryZ], 51, 0, _, _, playerid, 8000.0, MAPICON_GLOBAL);
- TogglePlayerDynamicCP(playerid, FactoryData[i][FactoryCP], 1);
- }
- }else{
- SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You can collect trash and sell them at recycling factories.");
- SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}Find trash cans/dumpsters and use /pickup.");
- }
- Trash_ShowCapacity(playerid);
- }
- SetPVarInt(playerid, "LastVehicleID", vehicleid);
- }
- if(oldstate == PLAYER_STATE_DRIVER)
- {
- for(new i; i < sizeof(FactoryData); i++)
- {
- if(IsValidDynamicMapIcon(FactoryIcons[playerid][i]))
- {
- DestroyDynamicMapIcon(FactoryIcons[playerid][i]);
- FactoryIcons[playerid][i] = -1;
- }
- TogglePlayerDynamicCP(playerid, FactoryData[i][FactoryCP], 0);
- }
- PlayerTextDrawHide(playerid, CapacityText[playerid]);
- HidePlayerProgressBar(playerid, CapacityBar[playerid]);
- }
- Trash_ResetPlayer(playerid);
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if((newkeys & KEY_NO) && HasTrash[playerid])
- {
- Trash_ResetPlayer(playerid);
- SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}Trash bag removed.");
- }
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- LoadedTrash[vehicleid] = 0;
- return 1;
- }
- public OnPlayerEnterDynamicCP(playerid, checkpointid)
- {
- if(checkpointid == TrashCP[playerid])
- {
- if(!HasTrash[playerid]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not carrying a trash bag.");
- new vehicleid = GetPVarInt(playerid, "LastVehicleID");
- if(LoadedTrash[vehicleid] >= TRASH_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}This vehicle is full, you can't load any more trash.");
- LoadedTrash[vehicleid]++;
- ApplyAnimation(playerid, "GRENADE", "WEAPON_throwu", 4.1, 0, 0, 0, 0, 0);
- SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You've collected a trash bag.");
- if(TRASH_LIMIT - LoadedTrash[vehicleid] > 0)
- {
- new string[96];
- format(string, sizeof(string), "TRASHMASTER JOB: {FFFFFF}You can load {F39C12}%d {FFFFFF}more trash bags to this vehicle.", TRASH_LIMIT - LoadedTrash[vehicleid]);
- SendClientMessage(playerid, 0x2ECC71FF, string);
- }
- new driver = GetVehicleDriver(vehicleid);
- if(IsPlayerConnected(driver)) Trash_ShowCapacity(driver);
- Trash_ResetPlayer(playerid);
- return 1;
- }
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- for(new i; i < sizeof(FactoryData); i++)
- {
- if(checkpointid == FactoryData[i][FactoryCP])
- {
- new string[128], vehicleid = GetPlayerVehicleID(playerid), cash = LoadedTrash[vehicleid] * TRASH_BAG_VALUE;
- format(string, sizeof(string), "TRASHMASTER JOB: {FFFFFF}Sold {F39C12}%d {FFFFFF}bags of trash and earned {2ECC71}$%d.", LoadedTrash[vehicleid], cash);
- SendClientMessage(playerid, 0x2ECC71FF, string);
- GivePlayerMoney(playerid, cash);
- FactoryData[i][FactoryCurrent] += LoadedTrash[vehicleid];
- LoadedTrash[vehicleid] = 0;
- Trash_ShowCapacity(playerid);
- format(string, sizeof(string), "Recycling Factory - %s\n\n{FFFFFF}Current Trash Bags: {F39C12}%d\n{FFFFFF}Bring trash here to earn money!", FactoryData[i][FactoryName], FactoryData[i][FactoryCurrent]);
- UpdateDynamic3DTextLabelText(FactoryData[i][FactoryLabel], 0x2ECC71FF, string);
- for(new x; x < sizeof(FactoryData); x++)
- {
- if(IsValidDynamicMapIcon(FactoryIcons[playerid][x]))
- {
- DestroyDynamicMapIcon(FactoryIcons[playerid][x]);
- FactoryIcons[playerid][x] = -1;
- }
- TogglePlayerDynamicCP(playerid, FactoryData[x][FactoryCP], 0);
- }
- break;
- }
- }
- }
- return 1;
- }
- forward FillTrash(id);
- public FillTrash(id)
- {
- TrashData[id][TrashLevel]++;
- if(TrashData[id][TrashType] == TYPE_BIN && TrashData[id][TrashLevel] > 1) TrashData[id][TrashLevel] = 1;
- if(TrashData[id][TrashType] == TYPE_DUMPSTER) {
- if(TrashData[id][TrashLevel] == 1) TrashData[id][TrashTimer] = SetTimerEx("FillTrash", REFILL_TIME * 1000, false, "i", id);
- if(TrashData[id][TrashLevel] >= 2)
- {
- TrashData[id][TrashLevel] = 2;
- KillTimer(TrashData[id][TrashTimer]);
- TrashData[id][TrashTimer] = -1;
- }
- Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, TrashData[id][TrashLabel], E_STREAMER_COLOR, (TrashData[id][TrashLevel] == 1) ? 0xF39C12FF : 0x2ECC71FF);
- return 1;
- }
- Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, TrashData[id][TrashLabel], E_STREAMER_COLOR, 0x2ECC71FF);
- return 1;
- }
- CMD:pickup(playerid, params[])
- {
- if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use this command in a vehicle.");
- new vehicleid = GetPVarInt(playerid, "LastVehicleID");
- if(GetVehicleModel(vehicleid) != 408) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Your last vehicle has to be a Trashmaster.");
- if(HasTrash[playerid]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already carrying a trash bag.");
- new id = Trash_Closest(playerid);
- if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any trash.");
- if(TrashData[id][TrashLevel] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}There's nothing here.");
- new Float: x, Float: y, Float: z;
- GetVehicleBoot(vehicleid, x, y, z);
- if(GetPlayerDistanceFromPoint(playerid, x, y, z) >= 30.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near your Trashmaster.");
- TrashData[id][TrashLevel]--;
- KillTimer(TrashData[id][TrashTimer]);
- TrashData[id][TrashTimer] = SetTimerEx("FillTrash", REFILL_TIME * 1000, false, "i", id);
- TrashCP[playerid] = CreateDynamicCP(x, y, z, 3.0, .playerid = playerid);
- HasTrash[playerid] = true;
- ApplyAnimation(playerid, "CARRY", "liftup105", 4.1, 0, 0, 0, 0, 0);
- SetPlayerAttachedObject(playerid, ATTACHMENT_INDEX, 1264, 6, 0.222, 0.024, 0.128, 1.90, -90.0, 0.0, 0.5,0.5, 0.5);
- Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, TrashData[id][TrashLabel], E_STREAMER_COLOR, (TrashData[id][TrashLevel] == 0) ? 0xE74C3CFF : 0xF39C12FF);
- SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You can press {F39C12}~k~~CONVERSATION_NO~ {FFFFFF}to remove the trash bag.");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement