Guest User

MOBTr1viUm

a guest
Apr 2nd, 2009
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.00 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define RV_MAX_PICKUPS 400 // MAXIMAL PICKUPS OF SA:MP
  4. #define RV_CHECK_TIME 5000 // IN MS
  5.  
  6. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  7.  
  8. enum PICKUP_DATA
  9. {
  10.     Float:Range,
  11.     Float:PX,
  12.     Float:PY,
  13.     Float:PZ,
  14.     Float:Healing,
  15.     Float:MaxHealing,
  16.     RespawnTime,
  17.     Price,
  18.     PickupID,
  19.     bool:created,
  20.     bool:spawned,
  21. };
  22.  
  23. new Pickups[RV_MAX_PICKUPS][PICKUP_DATA];
  24. new TotalPickups;
  25.  
  26. forward SpawnPickup(arrayid);
  27. forward RepairLocCheck();
  28.  
  29. // SCRIPT BELOW
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     print("\n********************************\n[R&V] Repair & Vehicle -- LOADED\n********************************\n  BY [MOB]TR1VIUM\n");
  34.     SendClientMessageToAll(0xF0F0F0AA, "_______________________________");
  35.     SendClientMessageToAll(0xF0F0F0AA, "[R&V] Repair & Vehicle -- LOADED");
  36.     SendClientMessageToAll(0xF0F0F0AA, "  BY [MOB]TR1VIUM");
  37.    
  38.     LoadPickupVars();
  39.     SetTimer("RepairLocCheck", RV_CHECK_TIME, 1);
  40.     return 1;
  41. }
  42.  
  43. public OnFilterScriptExit()
  44. {
  45.     for(new i = 0; i < RV_MAX_PICKUPS; i++)
  46.         if(Pickups[i][created])
  47.             DestroyPickup(Pickups[i][PickupID]);
  48.     return 1;
  49. }
  50.  
  51. dcmd_createrepair(playerid, params[])
  52. {
  53.     if(!IsPlayerAdmin(playerid))
  54.         return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Admin only.");
  55.     if(IsPlayerInAnyVehicle(playerid))
  56.         return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] You have to be on foot.");
  57.     if (sscanf(params, "fffii", Pickups[TotalPickups][Range], Pickups[TotalPickups][Healing], Pickups[TotalPickups][MaxHealing], Pickups[TotalPickups][RespawnTime], Pickups[TotalPickups][Price])) return SendClientMessage(playerid, 0x1EE443AA, "[R&V] /createrepair [range] [healing] [maxhealing] [respawntime] [price]");
  58.     else
  59.     {
  60.         if(Pickups[TotalPickups][Range] <= 0.0)
  61.             return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0.0 || range.");
  62.  
  63.         if(Pickups[TotalPickups][Healing] <= 0.0)
  64.             return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0.0 || healing.");
  65.  
  66.         if(Pickups[TotalPickups][MaxHealing] <= 0.0)
  67.             return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0.0 || maxhealing.");
  68.  
  69.         if(Pickups[TotalPickups][RespawnTime] < 0)
  70.             return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0 || respawn time");
  71.  
  72.         if(Pickups[TotalPickups][Price] < 0)
  73.             return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Don't go below 0 || Price");
  74.  
  75.         GetPlayerPos(playerid, Pickups[TotalPickups][PX], Pickups[TotalPickups][PY], Pickups[TotalPickups][PZ]);
  76.         Pickups[TotalPickups][PickupID] = CreatePickup(3096, 1, Pickups[TotalPickups][PX], Pickups[TotalPickups][PY], Pickups[TotalPickups][PZ]);
  77.         Pickups[TotalPickups][created] = true;
  78.         Pickups[TotalPickups][spawned] = true;
  79.         TotalPickups++;
  80.         SendClientMessage(playerid, 0x1EE443AA, "[R&V] Created repair pickup.");
  81.         SavePickupVars();
  82.     }
  83.     return 1;
  84. }
  85.  
  86. dcmd_deleterepair(playerid, params[])
  87. {
  88.     if(!IsPlayerAdmin(playerid))
  89.         return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Admin only.");
  90.     for(new i = 0; i < TotalPickups; i++)
  91.     {
  92.         if(PlayerToPoint(Pickups[i][Range], playerid, Pickups[i][PX], Pickups[i][PY], Pickups[i][PZ]))
  93.         {
  94.             DestroyPickup(Pickups[i][PickupID]);
  95.             Pickups[i][created] = false;
  96.             Pickups[i][spawned] = false;
  97.             SendClientMessage(playerid, 0x1EE443AA, "[R&V] Deleted repair pickup.");
  98.             SavePickupVars();
  99.             return 1;
  100.         }
  101.     }
  102.     SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Not at any repair pickup.");
  103.     #pragma unused params
  104.     return 1;
  105. }
  106.  
  107. dcmd_reloadrepair(playerid, params[])
  108. {
  109.     if(!IsPlayerAdmin(playerid))
  110.         return SendClientMessage(playerid, 0xE41E1EAA, "[R&V] Admin only.");
  111.     SavePickupVars();
  112.     LoadPickupVars();
  113.     SendClientMessage(playerid, 0x1EE443AA, "[R&V] Reloaded repair pickups.");
  114.     #pragma unused params
  115.     return 1;
  116. }
  117.  
  118. public OnPlayerCommandText(playerid, cmdtext[])
  119. {
  120.     dcmd(createrepair, 12, cmdtext);
  121.     dcmd(deleterepair, 12, cmdtext);
  122.     dcmd(reloadrepair, 12, cmdtext);
  123.     return 0;
  124. }
  125.  
  126. public SpawnPickup(arrayid)
  127. {
  128.     Pickups[arrayid][PickupID] = CreatePickup(3096, 1, Pickups[arrayid][PX], Pickups[arrayid][PY], Pickups[arrayid][PZ]);
  129.     Pickups[arrayid][created] = true;
  130.     Pickups[arrayid][spawned] = true;
  131.     return 1;
  132. }
  133.  
  134. public RepairLocCheck()
  135. {
  136.     for(new i = 0; i < MAX_PLAYERS; i++)
  137.     {
  138.         if(!IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))
  139.             continue;
  140.         for(new int = 0; int < TotalPickups; int++)
  141.         {
  142.             if(Pickups[int][spawned] && PlayerVehicleToPoint(Pickups[int][Range], i, Pickups[int][PX], Pickups[int][PY], Pickups[int][PZ]))
  143.             {
  144.                 if(GetPlayerMoney(i) >= Pickups[int][Price])
  145.                 {
  146.                     new vehicleid = GetPlayerVehicleID(i), Float:hp;
  147.                     GetVehicleHealth(vehicleid, hp);
  148.                     if(hp >= Pickups[int][MaxHealing])
  149.                     {
  150.                         GameTextForPlayer(i, "~w~MORE ~r~DAMAGE ~w~NEEDED", 5000, 3);
  151.                         break;
  152.                     }
  153.                     if(hp + Pickups[int][Healing] > Pickups[int][MaxHealing])
  154.                         SetVehicleHealth(vehicleid, Pickups[int][MaxHealing]);
  155.                     else
  156.                         SetVehicleHealth(vehicleid, hp+Pickups[int][Healing]);
  157.                     GivePlayerMoney(i, -Pickups[int][Price]);
  158.                     GameTextForPlayer(i, "~w~VEHICLE ~g~REPAIRED", 5000, 3);
  159.                     if(Pickups[int][RespawnTime] > 0)
  160.                     {
  161.                         SetTimerEx("SpawnPickup", Pickups[int][RespawnTime], 0, "i", int);
  162.                         DestroyPickup(Pickups[int][PickupID]);
  163.                         Pickups[int][spawned] = false;
  164.                     }
  165.                     break;
  166.                 }
  167.                 else
  168.                 {
  169.                     new string[126];
  170.                     format(string, 126, "~w~YOU NEED ~r~$%i", Pickups[int][Price]);
  171.                     GameTextForPlayer(i, string, 5000, 3);
  172.                 }
  173.             }
  174.         }
  175.     }
  176.     return 1;
  177. }
  178.  
  179. LoadPickupVars()
  180. {
  181.     if(!fexist("repairpickups.txt"))
  182.     {
  183.         new File:File = fopen("repairpickups.txt", io_write);
  184.         fclose(File);
  185.         return 1;
  186.     }
  187.     new i = 0, dude[256], idx, value[64];
  188.     new File:File = fopen("repairpickups.txt", io_read);
  189.     while(fread(File, dude))
  190.     {
  191.         value = strtok(dude, idx);
  192.         Pickups[i][Range] = floatstr(value);
  193.         value = strtok(dude, idx);
  194.         Pickups[i][PX] = floatstr(value);
  195.         value = strtok(dude, idx);
  196.         Pickups[i][PY] = floatstr(value);
  197.         value = strtok(dude, idx);
  198.         Pickups[i][PZ] = floatstr(value);
  199.         value = strtok(dude, idx);
  200.         Pickups[i][Healing] = floatstr(value);
  201.         value = strtok(dude, idx);
  202.         Pickups[i][MaxHealing] = floatstr(value);
  203.         value = strtok(dude, idx);
  204.         Pickups[i][RespawnTime] = strval(value);
  205.         value = strtok(dude, idx);
  206.         Pickups[i][Price] = strval(value);
  207.         Pickups[i][PickupID] = CreatePickup(3096, 1, Pickups[i][PX], Pickups[i][PY], Pickups[i][PZ]);
  208.         Pickups[i][created] = true;
  209.         Pickups[i][spawned] = true;
  210.         i++;
  211.         idx = 0;
  212.     }
  213.     fclose(File);
  214.     TotalPickups = i;
  215.     return 1;
  216. }
  217.  
  218. SavePickupVars()
  219. {
  220.     new dude[256], File:File = fopen("repairpickups.txt", io_write);
  221.     for(new i = 0; i < TotalPickups; i++)
  222.     {
  223.         if(Pickups[i][created])
  224.         {
  225.             format(dude, 256, "%f %f %f %f %f %f %i %i\r\n", Pickups[i][Range], Pickups[i][PX], Pickups[i][PY], Pickups[i][PZ], Pickups[i][Healing], Pickups[i][MaxHealing], Pickups[i][RespawnTime], Pickups[i][Price]);
  226.             fwrite(File, dude);
  227.         }
  228.     }
  229.     fclose(File);
  230.     return 1;
  231. }
  232.  
  233. PlayerVehicleToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  234. {
  235.     new Float:oldposx, Float:oldposy, Float:oldposz;
  236.     new Float:tempposx, Float:tempposy, Float:tempposz;
  237.     GetVehiclePos(GetPlayerVehicleID(playerid), oldposx, oldposy, oldposz);
  238.     tempposx = (oldposx -x);
  239.     tempposy = (oldposy -y);
  240.     tempposz = (oldposz -z);
  241.     if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  242.         return true;
  243.  
  244.     return false;
  245. }
  246.  
  247. PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  248. {
  249.     if(IsPlayerConnected(playerid))
  250.     {
  251.         new Float:oldposx, Float:oldposy, Float:oldposz;
  252.         new Float:tempposx, Float:tempposy, Float:tempposz;
  253.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  254.         tempposx = (oldposx -x);
  255.         tempposy = (oldposy -y);
  256.         tempposz = (oldposz -z);
  257.         //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
  258.         if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  259.         {
  260.             return 1;
  261.         }
  262.     }
  263.     return 0;
  264. }
  265.  
  266. sscanf(string[], format[], {Float,_}:...)
  267. {
  268.     #if defined isnull
  269.         if (isnull(string))
  270.     #else
  271.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  272.     #endif
  273.         {
  274.             return format[0];
  275.         }
  276.     #pragma tabsize 4
  277.     new
  278.         formatPos = 0,
  279.         stringPos = 0,
  280.         paramPos = 2,
  281.         paramCount = numargs(),
  282.         delim = ' ';
  283.     while (string[stringPos] && string[stringPos] <= ' ')
  284.     {
  285.         stringPos++;
  286.     }
  287.     while (paramPos < paramCount && string[stringPos])
  288.     {
  289.         switch (format[formatPos++])
  290.         {
  291.             case '\0':
  292.             {
  293.                 return 0;
  294.             }
  295.             case 'i', 'd':
  296.             {
  297.                 new
  298.                     neg = 1,
  299.                     num = 0,
  300.                     ch = string[stringPos];
  301.                 if (ch == '-')
  302.                 {
  303.                     neg = -1;
  304.                     ch = string[++stringPos];
  305.                 }
  306.                 do
  307.                 {
  308.                     stringPos++;
  309.                     if ('0' <= ch <= '9')
  310.                     {
  311.                         num = (num * 10) + (ch - '0');
  312.                     }
  313.                     else
  314.                     {
  315.                         return -1;
  316.                     }
  317.                 }
  318.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  319.                 setarg(paramPos, 0, num * neg);
  320.             }
  321.             case 'h', 'x':
  322.             {
  323.                 new
  324.                     ch,
  325.                     num = 0;
  326.                 while ((ch = string[stringPos]) > ' ' && ch != delim)
  327.                 {
  328.                     switch (ch)
  329.                     {
  330.                         case 'x', 'X':
  331.                         {
  332.                             num = 0;
  333.                             continue;
  334.                         }
  335.                         case '0' .. '9':
  336.                         {
  337.                             num = (num << 4) | (ch - '0');
  338.                         }
  339.                         case 'a' .. 'f':
  340.                         {
  341.                             num = (num << 4) | (ch - ('a' - 10));
  342.                         }
  343.                         case 'A' .. 'F':
  344.                         {
  345.                             num = (num << 4) | (ch - ('A' - 10));
  346.                         }
  347.                         default:
  348.                         {
  349.                             return -1;
  350.                         }
  351.                     }
  352.                 }
  353.                 setarg(paramPos, 0, num);
  354.             }
  355.             case 'c':
  356.             {
  357.                 setarg(paramPos, 0, string[stringPos++]);
  358.             }
  359.             case 'f':
  360.             {
  361.                 setarg(paramPos, 0, _:floatstr(string[stringPos]));
  362.             }
  363.             case 'p':
  364.             {
  365.                 delim = format[formatPos++];
  366.                 continue;
  367.             }
  368.             case '\'':
  369.             {
  370.                 new
  371.                     end = formatPos - 1,
  372.                     ch;
  373.                 while ((ch = format[++end]) && ch != '\'') {}
  374.                 if (!ch)
  375.                 {
  376.                     return -1;
  377.                 }
  378.                 format[end] = '\0';
  379.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  380.                 {
  381.                     if (format[end + 1])
  382.                     {
  383.                         return -1;
  384.                     }
  385.                     return 0;
  386.                 }
  387.                 format[end] = '\'';
  388.                 stringPos = ch + (end - formatPos);
  389.                 formatPos = end + 1;
  390.             }
  391.             case 'u':
  392.             {
  393.                 new
  394.                     end = stringPos - 1,
  395.                     id = 0,
  396.                     bool:num = true,
  397.                     ch;
  398.                 while ((ch = string[++end]) && ch != delim)
  399.                 {
  400.                     if (num)
  401.                     {
  402.                         if ('0' <= ch <= '9')
  403.                         {
  404.                             id = (id * 10) + (ch - '0');
  405.                         }
  406.                         else
  407.                         {
  408.                             num = false;
  409.                         }
  410.                     }
  411.                 }
  412.                 if (num && IsPlayerConnected(id))
  413.                 {
  414.                     setarg(paramPos, 0, id);
  415.                 }
  416.                 else
  417.                 {
  418.                     #if !defined foreach
  419.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  420.                         #define __SSCANF_FOREACH__
  421.                     #endif
  422.                     string[end] = '\0';
  423.                     num = false;
  424.                     new
  425.                         name[MAX_PLAYER_NAME];
  426.                     id = end - stringPos;
  427.                     foreach (Player, playerid)
  428.                     {
  429.                         GetPlayerName(playerid, name, sizeof (name));
  430.                         if (!strcmp(name, string[stringPos], true, id))
  431.                         {
  432.                             setarg(paramPos, 0, playerid);
  433.                             num = true;
  434.                             break;
  435.                         }
  436.                     }
  437.                     if (!num)
  438.                     {
  439.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  440.                     }
  441.                     string[end] = ch;
  442.                     #if defined __SSCANF_FOREACH__
  443.                         #undef foreach
  444.                         #undef __SSCANF_FOREACH__
  445.                     #endif
  446.                 }
  447.                 stringPos = end;
  448.             }
  449.             case 's', 'z':
  450.             {
  451.                 new
  452.                     i = 0,
  453.                     ch;
  454.                 if (format[formatPos])
  455.                 {
  456.                     while ((ch = string[stringPos++]) && ch != delim)
  457.                     {
  458.                         setarg(paramPos, i++, ch);
  459.                     }
  460.                     if (!i)
  461.                     {
  462.                         return -1;
  463.                     }
  464.                 }
  465.                 else
  466.                 {
  467.                     while ((ch = string[stringPos++]))
  468.                     {
  469.                         setarg(paramPos, i++, ch);
  470.                     }
  471.                 }
  472.                 stringPos--;
  473.                 setarg(paramPos, i, '\0');
  474.             }
  475.             default:
  476.             {
  477.                 continue;
  478.             }
  479.         }
  480.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  481.         {
  482.             stringPos++;
  483.         }
  484.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  485.         {
  486.             stringPos++;
  487.         }
  488.         paramPos++;
  489.     }
  490.     do
  491.     {
  492.         if ((delim = format[formatPos++]) > ' ')
  493.         {
  494.             if (delim == '\'')
  495.             {
  496.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  497.             }
  498.             else if (delim != 'z')
  499.             {
  500.                 return delim;
  501.             }
  502.         }
  503.     }
  504.     while (delim > ' ');
  505.     return 0;
  506. }
  507.  
  508. strtok(const string[], &index)
  509. {
  510.     new length = strlen(string);
  511.     while ((index < length) && (string[index] <= ' '))
  512.     {
  513.         index++;
  514.     }
  515.  
  516.     new offset = index;
  517.     new result[20];
  518.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  519.     {
  520.         result[index - offset] = string[index];
  521.         index++;
  522.     }
  523.     result[index - offset] = EOS;
  524.     return result;
  525. }
Advertisement
Add Comment
Please, Sign In to add comment