Advertisement
Private200

Weed system [v1.2]

May 22nd, 2017
2,531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.28 KB | None | 0 0
  1. #include <a_samp>
  2. #include <crashdetect>
  3. #include <YSI\y_iterate>
  4. #include <YSI\y_timers>
  5. #include <y_foreach>
  6. #include <sscanf2>
  7. #include <zcmd>
  8. #include <streamer>
  9.  
  10. #define MAX_WEEDS                                                               1000
  11. #define MAX_LOOTS                                                               1000
  12.  
  13. new Iterator:Weeds<MAX_WEEDS>;
  14. new Iterator:Loots<MAX_LOOTS>;
  15.  
  16. enum weedinfo {
  17.     wProgress,
  18.     wObjectID,
  19.     Float:wLocation[3],
  20.     Float:oPosition[3],
  21.     Text3D:wLabel,
  22.     Timer,
  23.     Timer:x,
  24.     wSeed
  25. }
  26. new WeedInfo[MAX_WEEDS][weedinfo];
  27.  
  28. enum pinfo {
  29.     pSelection,
  30.     Seeds[5],
  31.     Weed[5]
  32. }
  33. new PlayerInfo[MAX_PLAYERS][pinfo];
  34.  
  35. enum lootinfo {
  36.     Text3D:lLabel,
  37.     Float:lLocation[3],
  38.     wType,
  39.     wGrams,
  40.     lObjectID
  41. }
  42. new LootInfo[MAX_LOOTS][lootinfo];
  43.  
  44. enum seedpacks {
  45.     id,
  46.     SeedName[36],
  47.     SeedPrice,
  48.     GpS,
  49.     time
  50. }
  51. new SeedInformation[][seedpacks] =
  52. {
  53.     {0, "Cannabis Indica", 500, 3, 60},
  54.     {1, "Cannabis Sativa", 500, 1, 30}
  55. };
  56.  
  57. new DrugsList[MAX_PLAYERS][5];
  58. new ListChoice[MAX_PLAYERS];
  59. new ToID[MAX_PLAYERS];
  60.  
  61. stock PlayerName(playerid)
  62. {
  63.     new ppName[24];
  64.     GetPlayerName(playerid, ppName, 24);
  65.     return ppName;
  66. }
  67.  
  68. public OnFilterScriptInit()
  69. {
  70.     return 1;
  71. }
  72.  
  73. public OnFilterScriptExit()
  74. {
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerConnect(playerid)
  79. {
  80.     PlayerInfo[playerid][pSelection] = -1;
  81.     for(new i = 0; i < 5; i++)
  82.     {
  83.         PlayerInfo[playerid][Seeds][i] = 0;
  84.         PlayerInfo[playerid][Weed][i] = 0;
  85.     }
  86.     return 1;
  87. }
  88.  
  89. public OnPlayerDisconnect(playerid)
  90. {
  91.     PlayerInfo[playerid][pSelection] = -1;
  92.     for(new i = 0; i < 5; i++)
  93.     {
  94.         PlayerInfo[playerid][Seeds][i] = 0;
  95.         PlayerInfo[playerid][Weed][i] = 0;
  96.     }
  97.     return 1;
  98. }
  99.  
  100. CMD:pickpackup(playerid, params[])
  101. {
  102.     foreach(new i : Loots)
  103.     {
  104.         if(IsPlayerInRangeOfPoint(playerid, 2, LootInfo[i][lLocation][0], LootInfo[i][lLocation][1], LootInfo[i][lLocation][2]))
  105.         {
  106.             new string[128];
  107.             PlayerInfo[playerid][Weed][LootInfo[i][wType]] += LootInfo[i][wGrams];
  108.             format(string, sizeof string, "* {E1E858}You have picked up a pack containing %i grams of %s.", LootInfo[i][wGrams], SeedInformation[LootInfo[i][wType]][SeedName]);
  109.             SendClientMessage(playerid, -1, string);
  110.             LootInfo[i][wGrams] = 0;
  111.             LootInfo[i][wType] = -1;
  112.             DestroyDynamic3DTextLabel(LootInfo[i][lLabel]);
  113.             DestroyDynamicObject(LootInfo[i][lObjectID]);
  114.             Iter_Remove(Loots, i);
  115.             ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0 ,0,0,0,0,1);
  116.             break;
  117.         }
  118.     }
  119.     return 1;
  120. }
  121.  
  122. CMD:buyseeds(playerid, params[])
  123. {
  124.     new string[1000];
  125.    
  126.     //if(!IsPlayerInRangeOfPoint(playerid, 2, 0, 0, 0)) return SendClientMessage(playerid, "{FF0000}ERROR: {FFFFFF}You must be in range of the dealer to buy seed packs.");
  127.  
  128.     for(new i; i < sizeof SeedInformation; i++)
  129.     {
  130.         if(i != sizeof(SeedInformation))
  131.             format(string, sizeof string, "%s{FFFFFF}[{E1E858}ID: %i{FFFFFF}] %s\t\t{FFFFFF}%d{4BD176}$\n", string, i, SeedInformation[i][SeedName], SeedInformation[i][SeedPrice]);
  132.         else
  133.             format(string, sizeof string, "%s{FFFFFF}[{E1E858}ID: %i{FFFFFF}] %s\t\t{FFFFFF}%d{4BD176}$", string, SeedInformation[i][SeedName], SeedInformation[i][SeedPrice]);
  134.     }
  135.    
  136.     PlayerInfo[playerid][pSelection] = -1;
  137.     ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "{EBC11A}WEED: {FFFFFF}Seeds menu", string, "Buy", "Close");
  138.     return 1;
  139. }
  140.  
  141. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  142. {
  143.     if(dialogid == 1)
  144.     {
  145.         if(response)
  146.         {
  147.             PlayerInfo[playerid][pSelection] = listitem;
  148.             ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "{EBC11A}WEED: {FFFFFF}Seeds menu", "{FFFFFF}Select the amount of seeds you would like to buy.", "Buy", "Close");
  149.         }
  150.         return 1;
  151.     }
  152.     if(dialogid == 2)
  153.     {
  154.         if(response)
  155.         {
  156.             if(strval(inputtext) <= 0) return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}You cannot buy this amount of seeds.");
  157.             new input = strval(inputtext), selection=PlayerInfo[playerid][pSelection];
  158.             //if(GetPlayerMoney(playerid) < (SeedInformation[selection][SeedPrice])*input) return SendClientMessage(playerid, -1, "{FF0000}ERROR: {FFFFFF}You do not have enough money for these seeds.");
  159.             GivePlayerMoney(playerid, -(SeedInformation[selection][SeedPrice])*input);
  160.             PlayerInfo[playerid][Seeds][selection] += input;
  161.             new string[128];
  162.             format(string, sizeof string, "* {E1E858}You have bought %i %s seeds.", input, SeedInformation[selection][SeedName]);
  163.             SendClientMessage(playerid, -1, string);
  164.         }
  165.         return 1;
  166.     }
  167.     if(dialogid == 3)
  168.     {
  169.         if(response)
  170.         {
  171.             ListChoice[playerid] = listitem;
  172.             ToID[playerid] = -1;
  173.             ShowPlayerDialog(playerid, 4, DIALOG_STYLE_LIST, "{EBC11A}WEED: {FFFFFF}Weed management", "{FFFFFF}Pack and drop\n{FFFFFF}Give to another\n{FFFFFF}Disperse", "Perform", "Close");
  174.         }
  175.         return 1;
  176.     }
  177.     if(dialogid == 4)
  178.     {
  179.         if(response)
  180.         {
  181.             if(listitem == 0) {
  182.                 ShowPlayerDialog(playerid, 7, DIALOG_STYLE_INPUT, "{EBC11A}WEED: {FFFFFF}Weed management", "{FFFFFF}Choose the amount of drugs you would like to package and drop:", "Pack and drop", "Close");
  183.             }
  184.             if(listitem == 1) {
  185.                 ShowPlayerDialog(playerid, 8, DIALOG_STYLE_INPUT, "{EBC11A}WEED: {FFFFFF}Weed management", "{FFFFFF}Choose the person (ID) you would like to give drugs to:", "Give", "Close");
  186.                
  187.                 if(IsPlayerConnected(strval(inputtext))) {
  188.                     SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}Player ID is invalid.");
  189.                 }
  190.                 else {
  191.                     ToID[playerid] = strval(inputtext);
  192.                 }
  193.             }
  194.             if(listitem == 2) {
  195.                 ShowPlayerDialog(playerid, 9, DIALOG_STYLE_INPUT, "{EBC11A}WEED: {FFFFFF}Weed management", "{FFFFFF}Choose the amount of drugs you would like to disperse:", "Disperse", "Close");
  196.             }
  197.         }
  198.         return 1;
  199.     }
  200.     if(dialogid == 7)
  201.     {
  202.         if(response)
  203.         {
  204.             if(strval(inputtext) > PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]] || strval(inputtext) <= 0) return SendClientMessage(playerid, -1, "{FF0000}ERROR: {FFFFFF}You do not have that amount of drugs.");
  205.             new lootID = Iter_Free(Loots), Float:PPos[3];
  206.             new slot = DrugsList[playerid][ListChoice[playerid]];
  207.             GetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]);
  208.            
  209.             PlayerInfo[playerid][Weed][slot] -= strval(inputtext);
  210.            
  211.             LootInfo[lootID][lLocation][0] = PPos[0];
  212.             LootInfo[lootID][lLocation][1] = PPos[1]-0.1060;
  213.             LootInfo[lootID][lLocation][2] = PPos[2]-0.8;
  214.            
  215.             LootInfo[lootID][lObjectID] = CreateDynamicObject(1575, PPos[0], PPos[1]-0.1060, PPos[2]-1, 0, 0, 0);
  216.             new title[50];
  217.             format(title, sizeof title, "{E1E858}[%i grams of %s]", strval(inputtext), SeedInformation[slot][SeedName]);
  218.  
  219.             new string[128];
  220.             format(string, sizeof string, "* {E1E858}You have packed and dropped %i grams of %s; %i left.", strval(inputtext), SeedInformation[slot][SeedName], PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]]);
  221.             SendClientMessage(playerid, -1, string);
  222.            
  223.             LootInfo[lootID][lLabel] = CreateDynamic3DTextLabel(title, -1, PPos[0], PPos[1]-0.1060, PPos[2]-0.8, 5);
  224.             LootInfo[lootID][wGrams] = strval(inputtext);
  225.             LootInfo[lootID][wType] = slot;
  226.            
  227.             Iter_Add(Loots, lootID);
  228.         }
  229.         return 1;
  230.     }
  231.    
  232.     if(dialogid == 8)
  233.     {
  234.         if(response)
  235.         {
  236.             ShowPlayerDialog(playerid, 6, DIALOG_STYLE_INPUT, "{EBC11A}WEED: {FFFFFF}Weed management", "{FFFFFF}Choose the amount of drugs you would like to give this person:", "Give", "Close");
  237.         }
  238.         return 1;
  239.     }
  240.    
  241.     if(dialogid == 9)
  242.     {
  243.         if(response)
  244.         {
  245.             if(strval(inputtext) > PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]] || strval(inputtext) <= 0) return SendClientMessage(playerid, -1, "{FF0000}ERROR: {FFFFFF}You do not have that amount of drugs.");
  246.             PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]] -= strval(inputtext);
  247.             new string[128];
  248.             format(string, sizeof string, "* {E1E858}You have dispersed %i grams of %s; %i left.", strval(inputtext), SeedInformation[DrugsList[playerid][ListChoice[playerid]]][SeedName], PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]]);
  249.             SendClientMessage(playerid, -1, string);
  250.         }
  251.         return 1;
  252.     }
  253.    
  254.     if(dialogid == 6)
  255.     {
  256.         if(response)
  257.         {
  258.             if(strval(inputtext) > PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]] || strval(inputtext) <= 0) return SendClientMessage(playerid, -1, "{FF0000}ERROR: {FFFFFF}You do not have that amount of drugs.");
  259.             PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]] -= strval(inputtext);
  260.             PlayerInfo[ToID[playerid]][Weed][DrugsList[playerid][ListChoice[playerid]]] += strval(inputtext);
  261.             new string[128];
  262.             format(string, sizeof string, "* {E1E858}You have given %i grams of %s to %s; %i grams left.", strval(inputtext), SeedInformation[DrugsList[playerid][ListChoice[playerid]]][SeedName], PlayerName(ToID[playerid]), PlayerInfo[playerid][Weed][DrugsList[playerid][ListChoice[playerid]]]);
  263.             SendClientMessage(playerid, -1, string);
  264.             format(string, sizeof string, "* {E1E858}You have been given %i grams of %s from %s; you now got %i grams.", strval(inputtext), SeedInformation[DrugsList[playerid][ListChoice[playerid]]][SeedName], PlayerName(playerid), PlayerInfo[ToID[playerid]][Weed][DrugsList[playerid][ListChoice[playerid]]]);
  265.             SendClientMessage(playerid, -1, string);
  266.         }
  267.         return 1;
  268.     }
  269.     return 0;
  270. }
  271.  
  272. CMD:myseeds(playerid, params[])
  273. {
  274.     new string[1000], templates[128], results = 0;
  275.     for(new i; i < 5; i++)
  276.     {
  277.         if(PlayerInfo[playerid][Seeds][i] != 0) {
  278.             format(templates, sizeof templates, "{FFFFFF}[{E1E858}Slot: %i{FFFFFF}] {FFFFFF}%i seeds of %s{FFFFFF}.\n", i, PlayerInfo[playerid][Seeds][i], SeedInformation[i][SeedName]);
  279.             strcat(string, templates, sizeof string);
  280.             results++;
  281.         }
  282.     }
  283.     if(results == 0) return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}You do not have any seeds.");
  284.     ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "{EBC11A}WEED: {FFFFFF}My seeds", string, "Okay", "");
  285.     return 1;
  286. }
  287.  
  288. CMD:mydrugs(playerid, params[])
  289. {
  290.     new string[1000], templates[128], results = 0;
  291.     for(new i; i < 5; i++)
  292.     {
  293.         if(PlayerInfo[playerid][Weed][i] != 0) {
  294.             format(templates, sizeof templates, "{FFFFFF}[{E1E858}Slot: %i{FFFFFF}] %i grams of %s{FFFFFF}.\n", i, PlayerInfo[playerid][Weed][i], SeedInformation[i][SeedName]);
  295.             strcat(string, templates, sizeof string);
  296.             DrugsList[playerid][results] = i;
  297.             results++;
  298.         }
  299.     }
  300.     if(results == 0) return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}You do not have any drugs.");
  301.     ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "{EBC11A}WEED: {FFFFFF}My drugs", string, "Manage", "Close");
  302.     return 1;
  303. }
  304.  
  305. CMD:plantseed(playerid, params[])
  306. {
  307.     new slot;
  308.     if(sscanf(params, "i", slot)) return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}/plantseeds [slot (/myseeds for slot]");
  309.  
  310.     foreach(new i : Weeds)
  311.     {
  312.         if(IsPlayerInRangeOfPoint(playerid, 5, WeedInfo[i][wLocation][0], WeedInfo[i][wLocation][1], WeedInfo[i][wLocation][2]))
  313.         {
  314.             return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}You cannot plant a weed plant so close to another.");
  315.         }
  316.     }
  317.    
  318.     if(PlayerInfo[playerid][Seeds][slot] != 0)
  319.     {
  320.         new weedID = Iter_Free(Weeds), Float:PPos[3];
  321.         GetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]);
  322.        
  323.         WeedInfo[weedID][wSeed] = slot;
  324.         WeedInfo[weedID][wProgress] = 0;
  325.         WeedInfo[weedID][wLocation][0] = PPos[0];
  326.         WeedInfo[weedID][wLocation][1] = PPos[1];
  327.         WeedInfo[weedID][wLocation][2] = PPos[2];
  328.        
  329.         WeedInfo[weedID][wObjectID] = CreateDynamicObject(19473, PPos[0], PPos[1], PPos[2]-2.2100, 0, 0, 0);
  330.         WeedInfo[weedID][oPosition][0] = PPos[0];
  331.         WeedInfo[weedID][oPosition][1] = PPos[1];
  332.         WeedInfo[weedID][oPosition][2] = PPos[2]-2.2100;
  333.        
  334.         new title[50];
  335.         format(title, sizeof title, "{E1E858}[%s - 0%%]", SeedInformation[slot][SeedName]);
  336.         WeedInfo[weedID][wLabel] = CreateDynamic3DTextLabel(title, -1, PPos[0], PPos[1], PPos[2], 15.0);
  337.        
  338.        
  339.         WeedInfo[weedID][x] = repeat WeedProg(weedID, slot);
  340.        
  341.         PlayerInfo[playerid][Seeds][slot] -= 1;
  342.        
  343.         Iter_Add(Weeds, weedID);
  344.         ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0 ,0,0,0,0,1);
  345.     }
  346.     else SendClientMessage(playerid, -1, "* {FF0000}Error: {FFFFFF}You do not have any seeds in that slot.");
  347.     return 1;
  348. }
  349.  
  350. timer WeedProg[1000](weedID, slot)
  351. {
  352.     new title[50];
  353.    
  354.    
  355.     new Float:fPercentage = (float(WeedInfo[weedID][wProgress])/float(SeedInformation[slot][time])) * 100.0;
  356.     new percentage = floatround(fPercentage, floatround_floor);
  357.    
  358.     if(WeedInfo[weedID][Timer] == SeedInformation[slot][time]) stop WeedInfo[weedID][x];
  359.    
  360.     new Float:valIncr = (percentage*1.105)/100;
  361.    
  362.     printf("Weed ID: %i; Progress %i; valIncr %f",weedID, WeedInfo[weedID][wProgress], valIncr);
  363.    
  364.     if(WeedInfo[weedID][wProgress] < SeedInformation[slot][time])
  365.     {
  366.         WeedInfo[weedID][wProgress]++;
  367.         format(title, sizeof title, "{E1E858}[%s - %i%%]", SeedInformation[slot][SeedName], percentage);
  368.         SetDynamicObjectPos(WeedInfo[weedID][wObjectID], WeedInfo[weedID][oPosition][0], WeedInfo[weedID][oPosition][1], WeedInfo[weedID][oPosition][2]+valIncr);
  369.         UpdateDynamic3DTextLabelText(WeedInfo[weedID][wLabel], -1, title);
  370.     }
  371.     else
  372.     {
  373.         WeedInfo[weedID][wProgress] = SeedInformation[slot][time];
  374.         SetDynamicObjectPos(WeedInfo[weedID][wObjectID], WeedInfo[weedID][oPosition][0], WeedInfo[weedID][oPosition][1], WeedInfo[weedID][oPosition][2]+1.105);
  375.         format(title, sizeof title, "{E1E858}[%s - completed]", SeedInformation[slot][SeedName]);
  376.         UpdateDynamic3DTextLabelText(WeedInfo[weedID][wLabel], -1, title);
  377.     }
  378.     WeedInfo[weedID][Timer]++;
  379.     return 1;
  380. }
  381.  
  382.  
  383. CMD:collectweed(playerid, params[])
  384. {
  385.     new result = 0, prog=0, slot;
  386.     foreach(new i : Weeds)
  387.     {
  388.         if(IsPlayerInRangeOfPoint(playerid, 2, WeedInfo[i][wLocation][0], WeedInfo[i][wLocation][1], WeedInfo[i][wLocation][2]))
  389.         {
  390.             result = 1;
  391.             slot = WeedInfo[i][wSeed];
  392.             if(WeedInfo[i][wProgress] == SeedInformation[slot][time])
  393.             {
  394.                 PlayerInfo[playerid][Weed][slot] += SeedInformation[slot][GpS];
  395.                
  396.                 new string[128];
  397.                 format(string, sizeof string, "* {E1E858}You have collected %s plant and earned %i grams.", SeedInformation[slot][SeedName], SeedInformation[slot][GpS]);
  398.                 SendClientMessage(playerid, -1, string);
  399.                
  400.                 WeedInfo[i][wSeed] = -1;
  401.                 DestroyDynamic3DTextLabel(WeedInfo[i][wLabel]);
  402.                 DestroyDynamicObject(WeedInfo[i][wObjectID]);
  403.                 WeedInfo[i][Timer] = 0;
  404.  
  405.                 ApplyAnimation(playerid,"BOMBER","BOM_Plant",4.0,0 ,0,0,0,0,1);
  406.  
  407.                 Iter_Remove(Weeds, i);
  408.                 prog = 1;
  409.                 break;
  410.             }
  411.         }
  412.     }
  413.     if(result == 0) return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}You are not in range of any weed plant.");
  414.     if(prog == 0) return SendClientMessage(playerid, -1, "* {FF0000}ERROR: {FFFFFF}The plant is not fully grown yet and therefore cannot be collected.");
  415.     return 1;
  416. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement