Guest User

Hiddos

a guest
Dec 28th, 2010
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.10 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #if defined _weappick_included
  4.     #endinput
  5. #endif
  6. #define _weappick_included
  7.  
  8. #define COLOR 0x33ccffff
  9. #define DRAW_DISTANCE 20.0 //Drawing distance for the 3D text draw.
  10. #define RANGE 5.4 //The range for the player in which he needs to be to access the pickup
  11. #define PRIM_INTERVAL 750 //Primary interval for the first check
  12. #define SEC_INTERVAL 450 //When the player has bought a weapon, reduce the waiting time
  13. #define ARMOR 0 //Don't touch this
  14. enum wInfo
  15. {
  16.     pid,
  17.     weap,
  18.     ammu,
  19.     cost,
  20.     Text3D:label,
  21.     Float:X,
  22.     Float:Y,
  23.     Float:Z,
  24.     bool:created
  25. }
  26.  
  27. new wPick[MAX_PICKUPS][wInfo];
  28.  
  29. forward BuyItem(playerid, weappickid);
  30.  
  31. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  32. {
  33.     if(oldkeys & KEY_SECONDARY_ATTACK && !(newkeys & KEY_SECONDARY_ATTACK) && GetPVarInt(playerid, "HID_WeapTimer") != 0)
  34.     {
  35.         KillTimer(GetPVarInt(playerid, "HID_WeapTimer") - 1);
  36.         DeletePVar(playerid, "HID_WeapTimer");
  37.         return 1;
  38.     }
  39.    
  40.     if(newkeys & KEY_SECONDARY_ATTACK && !(oldkeys & KEY_SECONDARY_ATTACK))
  41.     {
  42.         for(new p; p < MAX_PICKUPS; p++)
  43.         {
  44.             if(!wPick[p][created]) continue;
  45.  
  46.             if(IsPlayerInRangeOfPoint(playerid, RANGE, wPick[p][X], wPick[p][Y], wPick[p][Z]))
  47.             {
  48.                 SetPVarInt(playerid, "HID_WeapTimer", SetTimerEx("BuyItem", PRIM_INTERVAL, 0, "ii", playerid, p) + 1);
  49.                 break;
  50.             }
  51.         }
  52.     }
  53.     CallLocalFunction("WEAPHID_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);
  54.     return 1;
  55. }
  56.  
  57. #if defined _ALS_OnPlayerKeyStateChange
  58.     #undef OnPlayerKeyStateChange
  59. #else
  60.     #define _ALS_OnPlayerKeyStateChange
  61. #endif
  62.  
  63. #define OnPlayerKeyStateChange WEAPHID_OnPlayerKeyStateChange
  64. forward WEAPHID_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  65.  
  66. public BuyItem(playerid, weappickid)
  67. {
  68.     if(!IsPlayerInRangeOfPoint(playerid, RANGE, wPick[weappickid][X], wPick[weappickid][Y], wPick[weappickid][Z])) return;
  69.  
  70.     if(GetPlayerMoney(playerid) < wPick[weappickid][cost])  PlayerPlaySound(playerid, 1055, 0, 0, 0);
  71.     else
  72.     {
  73.         new slot = RetrieveWeaponSlotFromWeaponID(wPick[weappickid][weap]);
  74.         new weapon, ammo;
  75.         GetPlayerWeaponData(playerid, slot, weapon, ammo);
  76.         if(IsNonStackingWeapon(weapon) && ammo != 0 && wPick[weappickid][weap] != ARMOR && weapon == wPick[weappickid][weap])
  77.         {
  78.             PlayerPlaySound(playerid, 1055, 0, 0, 0);
  79.         }
  80.         else if(wPick[weappickid][weap] == ARMOR)
  81.         {
  82.             new Float:AP;
  83.             GetPlayerArmour(playerid, AP);
  84.             if(AP >= 100) PlayerPlaySound(playerid, 1055, 0, 0, 0);
  85.             else if(AP + wPick[weappickid][ammu] < 100) SetPlayerArmour(playerid, AP + wPick[weappickid][ammu]);
  86.             else SetPlayerArmour(playerid, 100);
  87.         }
  88.         else
  89.         {
  90.             GivePlayerMoney(playerid, -wPick[weappickid][cost]);
  91.             if(wPick[weappickid][weap] != 0) GivePlayerWeapon(playerid, wPick[weappickid][weap], wPick[weappickid][ammu]);
  92.             else SetPlayerArmour(playerid, 100);
  93.             PlayerPlaySound(playerid, 1054, 0, 0, 0);
  94.         }
  95.     }
  96.  
  97.     if(!IsNonStackingWeapon(wPick[weappickid][weap]) || wPick[weappickid][weap] == ARMOR) SetPVarInt(playerid, "HID_WeapTimer", SetTimerEx("BuyItem", SEC_INTERVAL, 0, "ii", playerid, weappickid) + 1);
  98.     else DeletePVar(playerid, "HID_WeapTimer");
  99. }
  100.  
  101. stock CreateWeaponPickup(weaponid, ammo, money, Float:x, Float:y, Float:z)
  102. {
  103.     for(new p; p < MAX_PICKUPS; p++)
  104.     {
  105.         if(wPick[p][created] == false && !IsValidObject(p))
  106.         {
  107.             new string[128];
  108.             GetWeaponName(weaponid, string, sizeof string);
  109.             if(!IsNonStackingWeapon(weaponid) || weaponid == ARMOR) format(string, sizeof string, "%s\n%s: %i\nCost: $%i\nHold F to buy!", string, ((weaponid == ARMOR) ? ("Amount") : ("Ammo")), ammo, money);
  110.             else format(string, sizeof string, "%s\nCost: $%i\nHold F to buy!", string, money);
  111.             wPick[p][pid] = CreatePickup(RetrieveObjectModelFromWeaponID(weaponid), 1, x, y, z);
  112.             wPick[p][weap] = weaponid;
  113.             wPick[p][ammu] = ammo;
  114.             wPick[p][cost] = money;
  115.             wPick[p][label] = Create3DTextLabel(string, COLOR, x, y, z + 0.45, DRAW_DISTANCE, 0, 0);
  116.             wPick[p][X] = x;
  117.             wPick[p][Y] = y;
  118.             wPick[p][Z] = z;
  119.             wPick[p][created] = true;
  120.             return p;
  121.         }
  122.     }
  123.     return 0;
  124. }
  125.  
  126. stock DeleteWeaponPickup(weappickid)
  127. {
  128.     if(wPick[weappickid][created] == false) return 0;
  129.    
  130.     DestroyPickup(wPick[weappickid][pid]);
  131.     Delete3DTextLabel(wPick[weappickid][label]);
  132.     wPick[weappickid][created] = false;
  133.     return 1;
  134. }
  135.  
  136. stock SetWeaponPickupWeapon(weappickid, weaponid, ammo)
  137. {
  138.     if(wPick[weappickid][created] == false) return 0;
  139.  
  140.     wPick[weappickid][weap] = weaponid;
  141.     wPick[weappickid][ammu] = ammo;
  142.     DestroyPickup(wPick[weappickid][pid]);
  143.     wPick[weappickid][pid] = CreatePickup(RetrieveObjectModelFromWeaponID(weaponid), 1, wPick[weappickid][X], wPick[weappickid][Y], wPick[weappickid][Z]);
  144.     new string[128];
  145.     GetWeaponName(weaponid, string, sizeof string);
  146.  
  147.     if(!IsNonStackingWeapon(weaponid) || wPick[weappickid][weap] == ARMOR) format(string, sizeof string, "%s\n%s: %i\nCost: $%i\nHold F to buy!", string, ((weaponid == ARMOR) ? ("Amount") : ("Ammo")), ammo, wPick[weappickid][cost]);
  148.     else format(string, sizeof string, "%s\nCost: $%i\nHold F to buy!", string, wPick[weappickid][cost]);
  149.  
  150.     Update3DTextLabelText(wPick[weappickid][label], COLOR, string);
  151.     return 1;
  152. }
  153.  
  154. stock SetWeaponPickupCost(weappickid, money)
  155. {
  156.     if(wPick[weappickid][created] == false) return 0;
  157.    
  158.     wPick[weappickid][cost] = money;
  159.     new string[128];
  160.     GetWeaponName(wPick[weappickid][weap], string, sizeof string);
  161.  
  162.     if(!IsNonStackingWeapon(wPick[weappickid][weap]) || wPick[weappickid][weap] == ARMOR) format(string, sizeof string, "%s\n%s: %i\nCost: $%i\nHold F to buy!", string, ((wPick[weappickid][weap] == ARMOR) ? ("Amount") : ("Ammo")), wPick[weappickid][ammu], money);
  163.     else format(string, sizeof string, "%s\nCost: $%i\nHold F to buy!", string, money);
  164.  
  165.     Update3DTextLabelText(wPick[weappickid][label], COLOR, string);
  166.     return 1;
  167. }
  168.  
  169. stock GetWeaponPickupPos(weappickid, &Float:x, &Float:y, &Float:z)
  170. {
  171.     if(wPick[weappickid][created] == false) return 0;
  172.    
  173.     x = wPick[weappickid][X];
  174.     y = wPick[weappickid][Y];
  175.     z = wPick[weappickid][Z];
  176.     return 1;
  177. }
  178.  
  179. stock RetrieveObjectModelFromWeaponID(weaponid)
  180. {
  181.     switch(weaponid)
  182.     {
  183.         case 0: return 373;
  184.         case 1: return 331;
  185.         case 2: return 333;
  186.         case 3: return 334;
  187.         case 4: return 335;
  188.         case 5: return 336;
  189.         case 6: return 337;
  190.         case 7: return 338;
  191.         case 8: return 339;
  192.         case 9: return 341;
  193.         case 10: return 321;
  194.         case 11: return 322;
  195.         case 12: return 323;
  196.         case 13: return 324;
  197.         case 14: return 325;
  198.         case 15: return 326;
  199.         case 16: return 342;
  200.         case 17: return 343;
  201.         case 18: return 344;
  202.         case 22: return 346;
  203.         case 23: return 347;
  204.         case 24: return 348;
  205.         case 25: return 349;
  206.         case 26: return 350;
  207.         case 27: return 351;
  208.         case 28: return 352;
  209.         case 29: return 353;
  210.         case 30: return 355;
  211.         case 31: return 356;
  212.         case 32: return 372;
  213.         case 33: return 357;
  214.         case 34: return 358;
  215.         case 35: return 359;
  216.         case 36: return 360;
  217.         case 37: return 361;
  218.         case 38: return 362;
  219.         case 39: return 363;
  220.         case 40: return 364;
  221.         case 41: return 365;
  222.         case 42: return 366;
  223.         case 43: return 367;
  224.         case 44: return 368;
  225.         case 45: return 369;
  226.         case 46: return 371;
  227.     }
  228.     return 1486;
  229. }
  230.  
  231. stock IsNonStackingWeapon(weaponid)
  232. {
  233.     switch(weaponid)
  234.     {
  235.         case 0..15, 40, 44..46: return 1;
  236.         default: return 0;
  237.     }
  238.     return 0;
  239. }
  240.  
  241. stock RetrieveWeaponSlotFromWeaponID(weaponid)
  242. {
  243.     switch(weaponid)
  244.     {
  245.         case 0,1: return 0;
  246.         case 2..9: return 1;
  247.         case 22.24: return 2;
  248.         case 25..27: return 3;
  249.         case 28, 29, 32: return 4;
  250.         case 30, 31: return 5;
  251.         case 33, 34: return 6;
  252.         case 35..38: return 7;
  253.         case 16..18, 39: return 8;
  254.         case 41..43: return 9;
  255.         case 10..15: return 10;
  256.         case 44.46: return 11;
  257.         case 40: return 12;
  258.     }
  259.     return 0;
  260. }
  261.  
  262. /*
  263. native CreateWeaponPickup(weaponid, ammo, money, Float:x, Float:y, Float:z);
  264. native DeleteWeaponPickup(weappickid);
  265. native SetWeaponPickupWeapon(weappickid, weaponid, ammo);
  266. native SetWeaponPickupCost(weappickid, money);
  267. native GetWeaponPickupPos(weappickid, &Float:x, &Float:y, &Float:z);
  268. */
Advertisement
Add Comment
Please, Sign In to add comment