Advertisement
Guest User

Trashmaster Job

a guest
Mar 20th, 2016
2,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 32.77 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <evf>               // http://forum.sa-mp.com/showthread.php?t=486060
  4. #include    <progress2>         // http://forum.sa-mp.com/showthread.php?t=537468
  5. #include    <streamer>          // http://forum.sa-mp.com/showthread.php?t=102865
  6. #include    <izcmd>             // http://forum.sa-mp.com/showthread.php?t=576114
  7.  
  8. #define     TRASH_BAG_VALUE     (125)       // value of a collected trash bag (default: 125)
  9. #define     REFILL_TIME         (300)       // trash container refill time - in seconds (default: 300)
  10. #define     ATTACHMENT_INDEX    (4)         // for setplayerattachedobject (default: 4)
  11. #define     TRASH_LIMIT         (10)        // trashmaster capacity (default: 10)
  12. // location, x, y, z
  13.         {"Los Santos", 2432.553710, -2115.611328, 13.546875},
  14.         {"Las Venturas", 981.711303, 2168.738769, 10.820312},
  15.         {"San Fierro", -1044.592895, -606.348876, 32.007812}
  16.     };
  17.  
  18. new
  19.     bool: HasTrash[MAX_PLAYERS],
  20.     TrashCP[MAX_PLAYERS] = {-1, ...},
  21.     FactoryIcons[MAX_PLAYERS][sizeof(FactoryData)],
  22.     PlayerText: CapacityText[MAX_PLAYERS],
  23.     PlayerBar: CapacityBar[MAX_PLAYERS];
  24.  
  25. new
  26.     LoadedTrash[MAX_VEHICLES];
  27.  
  28. Trash_InitPlayer(playerid)
  29. {
  30.     HasTrash[playerid] = false;
  31.     TrashCP[playerid] = -1;
  32.    
  33.     for(new i; i < sizeof(FactoryData); i++)
  34.     {
  35.         TogglePlayerDynamicCP(playerid, FactoryData[i][FactoryCP], 0);
  36.         FactoryIcons[playerid][i] = -1;
  37.     }
  38.    
  39.     CapacityText[playerid] = CreatePlayerTextDraw(playerid, 32.000000, 290.000000, "Vehicle Capacity (0/10)");
  40.     PlayerTextDrawBackgroundColor(playerid, CapacityText[playerid], 255);
  41.     PlayerTextDrawFont(playerid, CapacityText[playerid], 1);
  42.     PlayerTextDrawLetterSize(playerid, CapacityText[playerid], 0.200000, 1.000000);
  43.     PlayerTextDrawColor(playerid, CapacityText[playerid], -1);
  44.     PlayerTextDrawSetOutline(playerid, CapacityText[playerid], 1);
  45.     PlayerTextDrawSetProportional(playerid, CapacityText[playerid], 1);
  46.     PlayerTextDrawSetSelectable(playerid, CapacityText[playerid], 0);
  47.    
  48.     CapacityBar[playerid] = CreatePlayerProgressBar(playerid, 30.000000, 304.000000, 118.500000, 6.199999, -1429936641, TRASH_LIMIT, 0);
  49.     return 1;
  50. }
  51.  
  52. Trash_ResetPlayer(playerid, removeUI = 0)
  53. {
  54.     if(IsPlayerAttachedObjectSlotUsed(playerid, ATTACHMENT_INDEX)) RemovePlayerAttachedObject(playerid, ATTACHMENT_INDEX);
  55.     if(IsValidDynamicCP(TrashCP[playerid])) DestroyDynamicCP(TrashCP[playerid]);
  56.     HasTrash[playerid] = false;
  57.     TrashCP[playerid] = -1;
  58.    
  59.     if(removeUI)
  60.     {
  61.         PlayerTextDrawDestroy(playerid, CapacityText[playerid]);
  62.         DestroyPlayerProgressBar(playerid, CapacityBar[playerid]);
  63.     }
  64.    
  65.     return 1;
  66. }
  67.  
  68. Trash_ShowCapacity(playerid)
  69. {
  70.     new vehicleid = GetPlayerVehicleID(playerid), capacity_string[32];
  71.     format(capacity_string, sizeof(capacity_string), "Vehicle Capacity (%d/%d)", LoadedTrash[vehicleid], TRASH_LIMIT);
  72.     PlayerTextDrawSetString(playerid, CapacityText[playerid], capacity_string);
  73.     PlayerTextDrawShow(playerid, CapacityText[playerid]);
  74.  
  75.     SetPlayerProgressBarValue(playerid, CapacityBar[playerid], LoadedTrash[vehicleid]);
  76.     ShowPlayerProgressBar(playerid, CapacityBar[playerid]);
  77.     return 1;
  78. }
  79.  
  80. Trash_Closest(playerid)
  81. {
  82.     new closest_id = -1, Float: dist = 3.0, Float: tempdist;
  83.     for(new i; i < sizeof(TrashData); i++)
  84.     {
  85.         tempdist = GetPlayerDistanceFromPoint(playerid, TrashData[i][TrashX], TrashData[i][TrashY], TrashData[i][TrashZ]);
  86.         if(tempdist > 3.0) continue;
  87.         if(tempdist <= dist)
  88.         {
  89.             dist = tempdist;
  90.             closest_id = i;
  91.         }
  92.     }
  93.    
  94.     return closest_id;
  95. }
  96.  
  97. public OnFilterScriptInit()
  98. {
  99.     new label[128];
  100.     for(new i; i < sizeof(TrashData); i++)
  101.     {
  102.         format(label, sizeof(label), "%s\n{FFFFFF}\n/pickup to collect.", (TrashData[i][TrashType] == TYPE_BIN) ? ("Trash Bin") : ("Dumpster"));
  103.         TrashData[i][TrashLabel] = CreateDynamic3DTextLabel(label, 0x2ECC71FF, TrashData[i][TrashX], TrashData[i][TrashY], TrashData[i][TrashZ]+1.25, 15.0, .testlos = 1);
  104.         TrashData[i][TrashLevel] = (TrashData[i][TrashType] == TYPE_BIN) ? 1 : 2;
  105.     }
  106.    
  107.     for(new i; i < sizeof(FactoryData); i++)
  108.     {
  109.         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]);
  110.         FactoryData[i][FactoryLabel] = CreateDynamic3DTextLabel(label, 0x2ECC71FF, FactoryData[i][FactoryX], FactoryData[i][FactoryY], FactoryData[i][FactoryZ] + 0.5, 15.0, .testlos = 1);
  111.         FactoryData[i][FactoryCP] = CreateDynamicCP(FactoryData[i][FactoryX], FactoryData[i][FactoryY], FactoryData[i][FactoryZ], 6.0);
  112.     }
  113.  
  114.     for(new i, m = GetPlayerPoolSize(); i <= m; i++)
  115.     {
  116.         if(!IsPlayerConnected(i)) continue;
  117.         Trash_InitPlayer(i);
  118.     }
  119.    
  120.     return 1;
  121. }
  122.  
  123. public OnFilterScriptExit()
  124. {
  125.     for(new i, m = GetPlayerPoolSize(); i <= m; i++)
  126.     {
  127.         if(!IsPlayerConnected(i)) continue;
  128.         Trash_ResetPlayer(i, 1);
  129.     }
  130.    
  131.     return 1;
  132. }
  133.  
  134. public OnPlayerConnect(playerid)
  135. {
  136.     Trash_InitPlayer(playerid);
  137.     return 1;
  138. }
  139.  
  140. public OnPlayerDisconnect(playerid, reason)
  141. {
  142.     if(HasTrash[playerid]) Trash_ResetPlayer(playerid);
  143.     return 1;
  144. }
  145.  
  146. public OnPlayerStateChange(playerid, newstate, oldstate)
  147. {
  148.     if(newstate == PLAYER_STATE_DRIVER)
  149.     {
  150.         new vehicleid = GetPlayerVehicleID(playerid);
  151.         if(GetVehicleModel(vehicleid) == 408)
  152.         {
  153.             if(LoadedTrash[vehicleid] > 0) {
  154.                 new string[128];
  155.                 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);
  156.                 SendClientMessage(playerid, 0x2ECC71FF, string);
  157.                 SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You can sell your trash bags to recycling factories marked by a truck icon.");
  158.  
  159.                 for(new i; i < sizeof(FactoryData); i++)
  160.                 {
  161.                     FactoryIcons[playerid][i] = CreateDynamicMapIcon(FactoryData[i][FactoryX], FactoryData[i][FactoryY], FactoryData[i][FactoryZ], 51, 0, _, _, playerid, 8000.0, MAPICON_GLOBAL);
  162.                     TogglePlayerDynamicCP(playerid, FactoryData[i][FactoryCP], 1);
  163.                 }
  164.             }else{
  165.                 SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You can collect trash and sell them at recycling factories.");
  166.                 SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}Find trash cans/dumpsters and use /pickup.");
  167.             }
  168.  
  169.             Trash_ShowCapacity(playerid);
  170.         }
  171.        
  172.         SetPVarInt(playerid, "LastVehicleID", vehicleid);
  173.     }
  174.    
  175.     if(oldstate == PLAYER_STATE_DRIVER)
  176.     {
  177.         for(new i; i < sizeof(FactoryData); i++)
  178.         {
  179.             if(IsValidDynamicMapIcon(FactoryIcons[playerid][i]))
  180.             {
  181.                 DestroyDynamicMapIcon(FactoryIcons[playerid][i]);
  182.                 FactoryIcons[playerid][i] = -1;
  183.             }
  184.  
  185.             TogglePlayerDynamicCP(playerid, FactoryData[i][FactoryCP], 0);
  186.         }
  187.        
  188.         PlayerTextDrawHide(playerid, CapacityText[playerid]);
  189.         HidePlayerProgressBar(playerid, CapacityBar[playerid]);
  190.     }
  191.    
  192.     Trash_ResetPlayer(playerid);
  193.     return 1;
  194. }
  195.  
  196. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  197. {
  198.     if((newkeys & KEY_NO) && HasTrash[playerid])
  199.     {
  200.         Trash_ResetPlayer(playerid);
  201.         SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}Trash bag removed.");
  202.     }
  203.    
  204.     return 1;
  205. }
  206.  
  207. public OnVehicleSpawn(vehicleid)
  208. {
  209.     LoadedTrash[vehicleid] = 0;
  210.     return 1;
  211. }
  212.  
  213. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  214. {
  215.     if(checkpointid == TrashCP[playerid])
  216.     {
  217.         if(!HasTrash[playerid]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not carrying a trash bag.");
  218.         new vehicleid = GetPVarInt(playerid, "LastVehicleID");
  219.         if(LoadedTrash[vehicleid] >= TRASH_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}This vehicle is full, you can't load any more trash.");
  220.         LoadedTrash[vehicleid]++;
  221.         ApplyAnimation(playerid, "GRENADE", "WEAPON_throwu", 4.1, 0, 0, 0, 0, 0);
  222.         SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You've collected a trash bag.");
  223.        
  224.         if(TRASH_LIMIT - LoadedTrash[vehicleid] > 0)
  225.         {
  226.             new string[96];
  227.             format(string, sizeof(string), "TRASHMASTER JOB: {FFFFFF}You can load {F39C12}%d {FFFFFF}more trash bags to this vehicle.", TRASH_LIMIT - LoadedTrash[vehicleid]);
  228.             SendClientMessage(playerid, 0x2ECC71FF, string);
  229.         }
  230.        
  231.         new driver = GetVehicleDriver(vehicleid);
  232.         if(IsPlayerConnected(driver)) Trash_ShowCapacity(driver);
  233.         Trash_ResetPlayer(playerid);
  234.         return 1;
  235.     }
  236.  
  237.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  238.     {
  239.         for(new i; i < sizeof(FactoryData); i++)
  240.         {
  241.             if(checkpointid == FactoryData[i][FactoryCP])
  242.             {
  243.                 new string[128], vehicleid = GetPlayerVehicleID(playerid), cash = LoadedTrash[vehicleid] * TRASH_BAG_VALUE;
  244.                 format(string, sizeof(string), "TRASHMASTER JOB: {FFFFFF}Sold {F39C12}%d {FFFFFF}bags of trash and earned {2ECC71}$%d.", LoadedTrash[vehicleid], cash);
  245.                 SendClientMessage(playerid, 0x2ECC71FF, string);
  246.                 GivePlayerMoney(playerid, cash);
  247.                 FactoryData[i][FactoryCurrent] += LoadedTrash[vehicleid];
  248.                 LoadedTrash[vehicleid] = 0;
  249.                 Trash_ShowCapacity(playerid);
  250.                 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]);
  251.                 UpdateDynamic3DTextLabelText(FactoryData[i][FactoryLabel], 0x2ECC71FF, string);
  252.                
  253.                 for(new x; x < sizeof(FactoryData); x++)
  254.                 {
  255.                     if(IsValidDynamicMapIcon(FactoryIcons[playerid][x]))
  256.                     {
  257.                         DestroyDynamicMapIcon(FactoryIcons[playerid][x]);
  258.                         FactoryIcons[playerid][x] = -1;
  259.                     }
  260.  
  261.                     TogglePlayerDynamicCP(playerid, FactoryData[x][FactoryCP], 0);
  262.                 }
  263.  
  264.                 break;
  265.             }
  266.         }
  267.     }
  268.    
  269.     return 1;
  270. }
  271.  
  272. forward FillTrash(id);
  273. public FillTrash(id)
  274. {
  275.     TrashData[id][TrashLevel]++;
  276.     if(TrashData[id][TrashType] == TYPE_BIN && TrashData[id][TrashLevel] > 1) TrashData[id][TrashLevel] = 1;
  277.  
  278.     if(TrashData[id][TrashType] == TYPE_DUMPSTER) {
  279.         if(TrashData[id][TrashLevel] == 1) TrashData[id][TrashTimer] = SetTimerEx("FillTrash", REFILL_TIME * 1000, false, "i", id);
  280.         if(TrashData[id][TrashLevel] >= 2)
  281.         {
  282.             TrashData[id][TrashLevel] = 2;
  283.             KillTimer(TrashData[id][TrashTimer]);
  284.             TrashData[id][TrashTimer] = -1;
  285.         }
  286.  
  287.         Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, TrashData[id][TrashLabel], E_STREAMER_COLOR, (TrashData[id][TrashLevel] == 1) ? 0xF39C12FF : 0x2ECC71FF);
  288.         return 1;
  289.     }
  290.  
  291.     Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, TrashData[id][TrashLabel], E_STREAMER_COLOR, 0x2ECC71FF);
  292.     return 1;
  293. }
  294.  
  295. CMD:pickup(playerid, params[])
  296. {
  297.     if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use this command in a vehicle.");
  298.     new vehicleid = GetPVarInt(playerid, "LastVehicleID");
  299.     if(GetVehicleModel(vehicleid) != 408) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Your last vehicle has to be a Trashmaster.");
  300.     if(HasTrash[playerid]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're already carrying a trash bag.");
  301.     new id = Trash_Closest(playerid);
  302.     if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near any trash.");
  303.     if(TrashData[id][TrashLevel] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}There's nothing here.");
  304.     new Float: x, Float: y, Float: z;
  305.     GetVehicleBoot(vehicleid, x, y, z);
  306.     if(GetPlayerDistanceFromPoint(playerid, x, y, z) >= 30.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near your Trashmaster.");
  307.     TrashData[id][TrashLevel]--;
  308.     KillTimer(TrashData[id][TrashTimer]);
  309.     TrashData[id][TrashTimer] = SetTimerEx("FillTrash", REFILL_TIME * 1000, false, "i", id);
  310.     TrashCP[playerid] = CreateDynamicCP(x, y, z, 3.0, .playerid = playerid);
  311.     HasTrash[playerid] = true;
  312.     ApplyAnimation(playerid, "CARRY", "liftup105", 4.1, 0, 0, 0, 0, 0);
  313.     SetPlayerAttachedObject(playerid, ATTACHMENT_INDEX, 1264, 6, 0.222, 0.024, 0.128, 1.90, -90.0, 0.0, 0.5,0.5, 0.5);
  314.     Streamer_SetIntData(STREAMER_TYPE_3D_TEXT_LABEL, TrashData[id][TrashLabel], E_STREAMER_COLOR, (TrashData[id][TrashLevel] == 0) ? 0xE74C3CFF : 0xF39C12FF);
  315.     SendClientMessage(playerid, 0x2ECC71FF, "TRASHMASTER JOB: {FFFFFF}You can press {F39C12}~k~~CONVERSATION_NO~ {FFFFFF}to remove the trash bag.");
  316.     return 1;
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement