Advertisement
Hanger

Better server sided weapons

Feb 15th, 2015
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 27.87 KB | None | 0 0
  1. #if defined _weaponsac_included
  2.     #endinput
  3. #endif 
  4. #define _weaponsac_included
  5.  
  6. #include    <YSI\y_hooks>
  7.  
  8.  
  9. #define     MAX_PLAYER_CLASSES      (300)
  10. #define     MAX_WEAPON_AMMO         (32767)
  11.  
  12. forward OnPlayerPurchaseWeapon(playerid, weaponid, totalammo);
  13.  
  14. enum E_CLASS_DATA
  15. {
  16.     E_CLASS_WEAPON1,
  17.     E_CLASS_WEAPON2,
  18.     E_CLASS_WEAPON3,
  19.     E_CLASS_AMMO1,
  20.     E_CLASS_AMMO2,
  21.     E_CLASS_AMMO3
  22. };
  23.  
  24. enum E_SPAWNI_DATA
  25. {
  26.     E_SPAWNI_WEAPON1,
  27.     E_SPAWNI_WEAPON2,
  28.     E_SPAWNI_WEAPON3,
  29.     E_SPAWNI_AMMO1,
  30.     E_SPAWNI_AMMO2,
  31.     E_SPAWNI_AMMO3
  32. };
  33.  
  34. new
  35.         PlayerClassData         [MAX_PLAYER_CLASSES]        [E_CLASS_DATA],
  36.         PlayerSpawnInfo         [MAX_PLAYERS]               [E_SPAWNI_DATA],
  37.        
  38.         PlayerWeapons           [MAX_PLAYERS]   [12],
  39.         PlayerWepAmmo           [MAX_PLAYERS]   [12],
  40.        
  41.         PlayerClassID           [MAX_PLAYERS],
  42.        
  43.         PickupModelID           [MAX_PICKUPS],
  44.         PickupType              [MAX_PICKUPS    char],
  45.    
  46. bool:   FallingWithParachute    [MAX_PLAYERS],
  47.         LastPlayerWeapon        [MAX_PLAYERS],
  48.         LastPlayerAmmo          [MAX_PLAYERS];
  49.  
  50. new
  51.     interiorsturnedoff = 0;
  52.  
  53. public OnPlayerConnect(playerid)
  54. {
  55.     for(new slot = 0; slot < 12; slot++)
  56.     {
  57.         PlayerWeapons[playerid][slot] = 0;
  58.         PlayerWepAmmo[playerid][slot] = 0;
  59.     }
  60.    
  61.     PlayerClassID       [playerid]  =   -1;
  62.     LastPlayerWeapon    [playerid]  =   0;
  63.     LastPlayerAmmo      [playerid]  =   0;
  64.     for(new i; E_SPAWNI_DATA:i < E_SPAWNI_DATA; i++)
  65.     {
  66.         PlayerSpawnInfo[playerid][E_SPAWNI_DATA:i] = 0;
  67.     }
  68.    
  69.     FallingWithParachute[playerid] = false;
  70.    
  71.     #if defined weapons_OnPlayerConnect
  72.         return weapons_OnPlayerConnect(playerid);
  73.     #else
  74.         return 1;
  75.     #endif
  76. }
  77. #if defined _ALS_OnPlayerConnect
  78.     #undef OnPlayerConnect
  79. #else
  80.     #define _ALS_OnPlayerConnect
  81. #endif
  82. #define OnPlayerConnect weapons_OnPlayerConnect
  83. #if defined weapons_OnPlayerConnect
  84.     forward weapons_OnPlayerConnect(playerid);
  85. #endif
  86.  
  87. public OnPlayerRequestClass(playerid, classid)
  88. {
  89.     PlayerClassID[playerid] = classid;
  90.    
  91.     #if defined weapons_OnPlayerRequestClass
  92.         return weapons_OnPlayerRequestClass(playerid, classid);
  93.     #else
  94.         return 1;
  95.     #endif
  96. }
  97. #if defined _ALS_OnPlayerRequestClass
  98.     #undef OnPlayerRequestClass
  99. #else
  100.     #define _ALS_OnPlayerRequestClass
  101. #endif
  102. #define OnPlayerRequestClass weapons_OnPlayerRequestClass
  103. #if defined weapons_OnPlayerRequestClass
  104.     forward weapons_OnPlayerRequestClass(playerid, classid);
  105. #endif
  106.  
  107. public OnPlayerSpawn(playerid)
  108. {
  109.     SetClassWeapons(playerid);
  110.    
  111.     #if defined weapons_OnPlayerSpawn
  112.         return weapons_OnPlayerSpawn(playerid);
  113.     #else
  114.         return 1;
  115.     #endif
  116. }
  117. #if defined _ALS_OnPlayerSpawn
  118.     #undef OnPlayerSpawn
  119. #else
  120.     #define _ALS_OnPlayerSpawn
  121. #endif
  122. #define OnPlayerSpawn weapons_OnPlayerSpawn
  123. #if defined weapons_OnPlayerSpawn
  124.     forward weapons_OnPlayerSpawn(playerid);
  125. #endif
  126.  
  127. public OnPlayerDeath(playerid, killerid, reason)
  128. {
  129.     weapons_ResetPlayerWeapons(playerid);
  130.    
  131.     FallingWithParachute    [playerid]  =   false;
  132.     LastPlayerWeapon        [playerid]  =   0;
  133.     LastPlayerAmmo          [playerid]  =   0;
  134.    
  135.     #if defined weapons_OnPlayerDeath
  136.         return weapons_OnPlayerDeath(playerid, killerid, reason);
  137.     #else
  138.         return 1;
  139.     #endif
  140. }
  141. #if defined _ALS_OnPlayerDeath
  142.     #undef OnPlayerDeath
  143. #else
  144.     #define _ALS_OnPlayerDeath
  145. #endif
  146. #define OnPlayerDeath weapons_OnPlayerDeath
  147. #if defined weapons_OnPlayerDeath
  148.     forward weapons_OnPlayerDeath(playerid, killerid, reason);
  149. #endif
  150.  
  151. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  152. {  
  153.     if(46 >= weaponid > 0)
  154.     {
  155.         static ammo, slot;
  156.         ammo    = GetPlayerAmmo(playerid),
  157.         slot    = GetWeaponSlotID(weaponid);
  158.        
  159.         if(ammo < 1 && PlayerWeapons[playerid][slot] == weaponid)
  160.         {
  161.             PlayerWeapons[playerid][slot] = 0;
  162.             PlayerWepAmmo[playerid][slot] = 0;
  163.             return 1;
  164.         }
  165.         if(IsValidPlayerWeapon(playerid, slot) != weaponid)
  166.         {
  167.             SetPlayerLegitWeapons(playerid);
  168.             SetPlayerArmedWeapon(playerid, 0);
  169.             return 0;
  170.         }
  171.     }
  172.     #if defined weapons_OnPlayerWeaponShot
  173.         return weapons_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, fX, fY, fZ);
  174.     #else
  175.         return 1;
  176.     #endif
  177. }
  178. #if defined _ALS_OnPlayerWeaponShot
  179.     #undef OnPlayerWeaponShot
  180. #else
  181.     #define _ALS_OnPlayerWeaponShot
  182. #endif
  183. #define OnPlayerWeaponShot weapons_OnPlayerWeaponShot
  184. #if defined weapons_OnPlayerWeaponShot
  185.     forward weapons_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  186. #endif
  187.  
  188. public OnPlayerUpdate(playerid)
  189. {
  190.     if(!(GetPlayerWeaponState(playerid) == -1 && !IsPlayerInAnyVehicle(playerid)))
  191.     {
  192.         static
  193.             weaponid,
  194.             ammo,
  195.             slot;
  196.  
  197.         weaponid = GetPlayerWeapon(playerid);
  198.        
  199.         if(46 >= weaponid > 0 && weaponid != WEAPON_BOMB)
  200.         {
  201.             ammo        = GetPlayerAmmo(playerid),
  202.             slot        = GetWeaponSlotID(weaponid);
  203.            
  204.             if(PlayerWepAmmo[playerid][slot] < 1 && PlayerWeapons[playerid][slot] == weaponid)
  205.             {
  206.                 PlayerWeapons[playerid][slot] = 0;
  207.                 PlayerWepAmmo[playerid][slot] = 0;
  208.                 return 1;
  209.             }
  210.             else if(!IsPlayerUsingParachute(playerid) && FallingWithParachute[playerid])
  211.             {
  212.                 if(PlayerWeapons[playerid][11] == WEAPON_PARACHUTE)
  213.                 {
  214.                     FallingWithParachute[playerid] = false;
  215.                     PlayerWeapons[playerid][slot] = 0;
  216.                     PlayerWepAmmo[playerid][slot] = 0;
  217.                     return 1;
  218.                 }
  219.             }
  220.            
  221.             if(IsValidPlayerWeapon(playerid, slot) != weaponid)
  222.             {
  223.                 if(IsPlayerBuyingInAmmunation(playerid))
  224.                 {
  225.                     if(funcidx("OnPlayerPurchaseWeapon") != -1)
  226.                     {
  227.                         if(!CallLocalFunction("OnPlayerPurchaseWeapon", "iii", playerid, weaponid, ammo))
  228.                         {
  229.                             SetPlayerLegitWeapons(playerid);
  230.                             return 0;
  231.                         }
  232.                     }
  233.                     PlayerWeapons[playerid][slot] = weaponid;
  234.                     PlayerWepAmmo[playerid][slot] = ammo;
  235.                     LastPlayerAmmo[playerid] = ammo;
  236.                     SetPlayerArmedWeapon(playerid, weaponid);
  237.                 }
  238.                 else
  239.                 {
  240.                     if(GetPlayerAnimationIndex(playerid) == 645 || GetPlayerAnimationIndex(playerid) == 646)
  241.                     {
  242.                         if(GetWeaponSlotID(LastPlayerWeapon[playerid]) == 8 && LastPlayerAmmo[playerid] == 2)
  243.                         {
  244.                             return 1;
  245.                         }
  246.                     }
  247.                     else if(GetPlayerWeaponState(playerid) == WEAPONSTATE_NO_BULLETS)
  248.                     {
  249.                         return 1;
  250.                     }
  251.                     else
  252.                     {
  253.                         SetPlayerLegitWeapons(playerid);
  254.                         SetPlayerArmedWeapon(playerid, 0);
  255.                         return 0;
  256.                     }
  257.                 }
  258.             }
  259.            
  260.             static keys, ud, lr;
  261.             GetPlayerKeys(playerid, keys, ud, lr);
  262.            
  263.             if(ammo > PlayerWepAmmo[playerid][slot] || MAX_WEAPON_AMMO < ammo < 1)
  264.             {
  265.                 if(IsPlayerBuyingInAmmunation(playerid))
  266.                 {
  267.                     if(funcidx("OnPlayerPurchaseWeapon") != -1)
  268.                     {
  269.                         if(!CallLocalFunction("OnPlayerPurchaseWeapon", "iii", playerid, weaponid, ammo))
  270.                         {
  271.                             SetPlayerLegitWeapons(playerid);
  272.                             return 0;
  273.                         }
  274.                     }
  275.                     PlayerWepAmmo[playerid][slot] = ammo;
  276.                     LastPlayerAmmo[playerid] = ammo;
  277.                 }
  278.                 else
  279.                 {
  280.                     SetPlayerLegitWeapons(playerid);
  281.                     SetPlayerArmedWeapon(playerid, weaponid);
  282.                     return 0;
  283.                 }
  284.             }
  285.             else
  286.             {
  287.                 PlayerWepAmmo[playerid][slot] = ammo;
  288.                
  289.                 switch(slot)
  290.                 {
  291.                     case 2..9:
  292.                     {
  293.                         if(IsPlayerUsingWeapon(playerid) || GetPlayerAnimationIndex(playerid) == 644)
  294.                         {
  295.                             if((keys & KEY_FIRE))
  296.                             {
  297.                                 if(LastPlayerWeapon[playerid] != weaponid)
  298.                                 {
  299.                                     LastPlayerAmmo[playerid] = ammo;
  300.                                 }
  301.                                
  302.                                 if(slot == 8 && ammo == 1)
  303.                                 {
  304.                                     if(GetPlayerAnimationIndex(playerid) == 644)
  305.                                     {
  306.                                         PlayerWepAmmo[playerid][slot] --;
  307.                                     }
  308.                                 }
  309.                                 else if(slot == 9 && ammo == 1)
  310.                                 {
  311.                                     PlayerWepAmmo[playerid][slot] --;
  312.                                 }
  313.                                 else if(LastPlayerAmmo[playerid] < ammo)
  314.                                 {
  315.                                     PlayerWepAmmo[playerid][slot] --;
  316.                                     LastPlayerAmmo[playerid] = ammo;
  317.                                 }
  318.                             }
  319.                         }
  320.                     }
  321.                     case 11:
  322.                     {
  323.                         if(GetPlayerAnimationIndex(playerid) == 638)
  324.                         {
  325.                             if(!IsPlayerInAnyVehicle(playerid))
  326.                                 return 0;
  327.                         }
  328.                         else if(IsPlayerUsingParachute(playerid) && !FallingWithParachute[playerid])
  329.                         {
  330.                             FallingWithParachute[playerid] = true;
  331.                         }
  332.                     }
  333.                 }
  334.             }
  335.         }
  336.     }
  337.     #if defined weapons_OnPlayerUpdate
  338.         return weapons_OnPlayerUpdate(playerid);
  339.     #else
  340.         return 1;
  341.     #endif
  342. }
  343. #if defined _ALS_OnPlayerUpdate
  344.     #undef OnPlayerUpdate
  345. #else
  346.     #define _ALS_OnPlayerUpdate
  347. #endif
  348. #define OnPlayerUpdate weapons_OnPlayerUpdate
  349. #if defined weapons_OnPlayerUpdate
  350.     forward weapons_OnPlayerUpdate(playerid);
  351. #endif
  352.  
  353. public OnPlayerPickUpPickup(playerid, pickupid)
  354. {
  355.     if(pickupid != -1)
  356.     {
  357.         static weaponid;
  358.         weaponid = GetWeaponIDFromModel(PickupModelID[pickupid]);
  359.         if(weaponid)
  360.         {
  361.             static slot;
  362.             slot = GetWeaponSlotID(weaponid);
  363.             if(PickupType{pickupid} == 2 || PickupType{pickupid} == 3 || PickupType{pickupid} == 15 || PickupType{pickupid} == 22)
  364.             {
  365.                 PlayerWeapons[playerid][slot] = weaponid;
  366.                 PlayerWepAmmo[playerid][slot] += GetWeaponPickupAmmoDifference(weaponid);
  367.                 SetPlayerArmedWeapon(playerid, weaponid);
  368.             }
  369.         }
  370.     }
  371.     #if defined weapons_OnPlayerPickUpPickup
  372.         return weapons_OnPlayerPickUpPickup(playerid, pickupid);
  373.     #else
  374.         return 1;
  375.     #endif
  376. }
  377. #if defined _ALS_OnPlayerPickUpPickup
  378.     #undef OnPlayerPickUpPickup
  379. #else
  380.     #define _ALS_OnPlayerPickUpPickup
  381. #endif
  382. #define OnPlayerPickUpPickup weapons_OnPlayerPickUpPickup
  383. #if defined weapons_OnPlayerPickUpPickup
  384.     forward weapons_OnPlayerPickUpPickup(playerid, pickupid);
  385. #endif
  386.  
  387. stock acwep_DisableInteriorEnterExits()
  388. {
  389.     interiorsturnedoff = 1;
  390.     return DisableInteriorEnterExits();
  391. }
  392.  
  393. stock weapons_AddPlayerClass(skin, Float:x, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
  394. {
  395.     static classid;
  396.     classid = AddPlayerClass(skin, x, y, z, Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  397.     if(weapon1 > 0 && weapon1_ammo > 0)
  398.     {
  399.         PlayerClassData[classid][E_CLASS_WEAPON1] = weapon1;
  400.         PlayerClassData[classid][E_CLASS_AMMO1] = weapon1_ammo;
  401.     }
  402.     if(weapon2 > 0 && weapon2_ammo > 0)
  403.     {
  404.         PlayerClassData[classid][E_CLASS_WEAPON2] = weapon2;
  405.         PlayerClassData[classid][E_CLASS_AMMO2] = weapon2_ammo;
  406.     }
  407.     if(weapon3 > 0 && weapon3_ammo > 0)
  408.     {
  409.         PlayerClassData[classid][E_CLASS_WEAPON3] = weapon3;
  410.         PlayerClassData[classid][E_CLASS_AMMO3] = weapon3_ammo;
  411.     }
  412. }
  413.  
  414. stock weapons_AddPlayerClassEx(teamid, skin, Float:x, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
  415. {
  416.     static classid;
  417.     classid = AddPlayerClassEx(teamid, skin, x, y, z, Angle, weapon, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  418.     if(weapon1 > 0 && weapon1_ammo > 0)
  419.     {
  420.         PlayerClassData[classid][E_CLASS_WEAPON1] = weapon1;
  421.         PlayerClassData[classid][E_CLASS_AMMO1] = weapon1_ammo;
  422.     }
  423.     if(weapon2 > 0 && weapon2_ammo > 0)
  424.     {
  425.         PlayerClassData[classid][E_CLASS_WEAPON2] = weapon2;
  426.         PlayerClassData[classid][E_CLASS_AMMO2] = weapon2_ammo;
  427.     }
  428.     if(weapon3 > 0 && weapon3_ammo > 0)
  429.     {
  430.         PlayerClassData[classid][E_CLASS_WEAPON3] = weapon3;
  431.         PlayerClassData[classid][E_CLASS_AMMO3] = weapon3_ammo;
  432.     }
  433. }
  434.  
  435. stock weapons_SetSpawnInfo(playerid, team, skin, Float:x, Float:y, Float:z, rotation, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
  436. {
  437.     if(weapon1 > 0 && weapon1_ammo > 0)
  438.     {
  439.         PlayerClassData[playerid][E_SPAWNI_WEAPON1] = weapon1;
  440.         PlayerClassData[playerid][E_SPAWNI_AMMO1]   = weapon1_ammo;
  441.     }
  442.     if(weapon2 > 0 && weapon2_ammo > 0)
  443.     {
  444.         PlayerClassData[playerid][E_SPAWNI_WEAPON2] = weapon2;
  445.         PlayerClassData[playerid][E_SPAWNI_AMMO2]   = weapon2_ammo;
  446.     }
  447.     if(weapon3 > 0 && weapon3_ammo > 0)
  448.     {
  449.         PlayerClassData[playerid][E_SPAWNI_WEAPON3] = weapon3;
  450.         PlayerClassData[playerid][E_SPAWNI_AMMO3]   = weapon3_ammo;
  451.     }
  452.     return SetSpawnInfo(playerid, team, skin, x, y, z, rotation, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  453. }
  454.  
  455. stock SetClassWeapons(playerid)
  456. {
  457.     if(PlayerClassID[playerid] != -1)
  458.     {
  459.         if(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON1])
  460.         {
  461.             PlayerWeapons[playerid][GetWeaponSlotID(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON1])] = PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON1];
  462.             PlayerWepAmmo[playerid][GetWeaponSlotID(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON1])] = PlayerClassData[PlayerClassID[playerid]][E_CLASS_AMMO1];
  463.         }
  464.         if(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON2])
  465.         {
  466.             PlayerWeapons[playerid][GetWeaponSlotID(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON2])] = PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON2];
  467.             PlayerWepAmmo[playerid][GetWeaponSlotID(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON2])] = PlayerClassData[PlayerClassID[playerid]][E_CLASS_AMMO2];
  468.         }
  469.         if(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON3])
  470.         {
  471.             PlayerWeapons[playerid][GetWeaponSlotID(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON3])] = PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON3];
  472.             PlayerWepAmmo[playerid][GetWeaponSlotID(PlayerClassData[PlayerClassID[playerid]][E_CLASS_WEAPON3])] = PlayerClassData[PlayerClassID[playerid]][E_CLASS_AMMO3];
  473.         }
  474.     }
  475.     if(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON1] && PlayerSpawnInfo[playerid][E_SPAWNI_AMMO1])
  476.     {
  477.         PlayerWeapons[playerid][GetWeaponSlotID(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON1])] = PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON1];
  478.         PlayerWepAmmo[playerid][GetWeaponSlotID(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON1])] = PlayerSpawnInfo[playerid][E_SPAWNI_AMMO1];
  479.     }
  480.     if(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON2] && PlayerSpawnInfo[playerid][E_SPAWNI_AMMO2])
  481.     {
  482.         PlayerWeapons[playerid][GetWeaponSlotID(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON2])] = PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON2];
  483.         PlayerWepAmmo[playerid][GetWeaponSlotID(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON2])] = PlayerSpawnInfo[playerid][E_SPAWNI_AMMO2];
  484.     }
  485.     if(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON3] && PlayerSpawnInfo[playerid][E_SPAWNI_AMMO3])
  486.     {
  487.         PlayerWeapons[playerid][GetWeaponSlotID(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON3])] = PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON3];
  488.         PlayerWepAmmo[playerid][GetWeaponSlotID(PlayerSpawnInfo[playerid][E_SPAWNI_WEAPON3])] = PlayerSpawnInfo[playerid][E_SPAWNI_AMMO3];
  489.     }
  490.     return 1;
  491. }
  492.  
  493. stock weapons_AddStaticPickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
  494. {
  495.     static pickupid;
  496.     pickupid = CreatePickup(model, type, X, Y, Z, Virtualworld);
  497.     if(pickupid != -1)
  498.     {
  499.         PickupModelID   [pickupid] = model;
  500.         PickupType      {pickupid} = type;
  501.     }
  502.     return pickupid;
  503. }
  504.  
  505. stock weapons_CreatePickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
  506. {
  507.     static pickupid;
  508.     pickupid = CreatePickup(model, type, X, Y, Z, Virtualworld);
  509.     if(pickupid != -1)
  510.     {
  511.         PickupModelID   [pickupid] = model;
  512.         PickupType      {pickupid} = type;
  513.     }
  514.     return pickupid;
  515. }
  516.  
  517. stock GetWeaponIDFromModel(model)
  518. {
  519.     switch(model)
  520.     {
  521.         case 331: return WEAPON_BRASSKNUCKLE;
  522.         case 333: return WEAPON_GOLFCLUB;
  523.         case 334: return WEAPON_NITESTICK;
  524.         case 335: return WEAPON_KNIFE;
  525.         case 336: return WEAPON_BAT;
  526.         case 337: return WEAPON_SHOVEL;
  527.         case 338: return WEAPON_POOLSTICK;
  528.         case 339: return WEAPON_KATANA;
  529.         case 341: return WEAPON_CHAINSAW;
  530.         case 321: return WEAPON_DILDO;
  531.         case 322: return WEAPON_DILDO2;
  532.         case 323: return WEAPON_VIBRATOR;
  533.         case 324: return WEAPON_VIBRATOR2;
  534.         case 325: return WEAPON_FLOWER;
  535.         case 326: return WEAPON_CANE;
  536.         case 342: return WEAPON_GRENADE;
  537.         case 343: return WEAPON_TEARGAS;
  538.         case 344: return WEAPON_MOLTOV;
  539.         case 346: return WEAPON_COLT45;
  540.         case 347: return WEAPON_SILENCED;
  541.         case 348: return WEAPON_DEAGLE;
  542.         case 349: return WEAPON_SHOTGUN;
  543.         case 350: return WEAPON_SAWEDOFF;
  544.         case 351: return WEAPON_SHOTGSPA;
  545.         case 352: return WEAPON_UZI;
  546.         case 353: return WEAPON_MP5;
  547.         case 355: return WEAPON_AK47;
  548.         case 356: return WEAPON_M4;
  549.         case 372: return WEAPON_TEC9;
  550.         case 357: return WEAPON_RIFLE;
  551.         case 358: return WEAPON_SNIPER;
  552.         case 359: return WEAPON_ROCKETLAUNCHER;
  553.         case 360: return WEAPON_HEATSEEKER;
  554.         case 361: return WEAPON_FLAMETHROWER;
  555.         case 362: return WEAPON_MINIGUN;
  556.         case 363: return WEAPON_SATCHEL;
  557.         case 364: return WEAPON_BOMB;
  558.         case 365: return WEAPON_SPRAYCAN;
  559.         case 366: return WEAPON_FIREEXTINGUISHER;
  560.         case 367: return WEAPON_CAMERA;
  561.         case 368: return 44;
  562.         case 369: return 45;
  563.         case 371: return WEAPON_PARACHUTE;
  564.         default:  return 0;
  565.     }
  566.     return 0;
  567. }
  568. stock GetWeaponModel(weaponid)
  569. {
  570.     switch(weaponid)
  571.     {
  572.         case WEAPON_BRASSKNUCKLE:       return 331;
  573.         case WEAPON_GOLFCLUB:           return 333;
  574.         case WEAPON_NITESTICK:          return 334;
  575.         case WEAPON_KNIFE:              return 335;
  576.         case WEAPON_BAT:                return 336;
  577.         case WEAPON_SHOVEL:             return 337;
  578.         case WEAPON_POOLSTICK:          return 338;
  579.         case WEAPON_KATANA:             return 339;
  580.         case WEAPON_CHAINSAW:           return 341;
  581.         case WEAPON_DILDO:              return 321;
  582.         case WEAPON_DILDO2:             return 322;
  583.         case WEAPON_VIBRATOR:           return 323;
  584.         case WEAPON_VIBRATOR2:          return 324;
  585.         case WEAPON_FLOWER:             return 325;
  586.         case WEAPON_CANE:               return 326;
  587.         case WEAPON_GRENADE:            return 342;
  588.         case WEAPON_TEARGAS:            return 343;
  589.         case WEAPON_MOLTOV:             return 344;
  590.         case WEAPON_COLT45:             return 346;
  591.         case WEAPON_SILENCED:           return 347;
  592.         case WEAPON_DEAGLE:             return 348;
  593.         case WEAPON_SHOTGUN:            return 349;
  594.         case WEAPON_SAWEDOFF:           return 350;
  595.         case WEAPON_SHOTGSPA:           return 351;
  596.         case WEAPON_UZI:                return 352;
  597.         case WEAPON_MP5:                return 353;
  598.         case WEAPON_AK47:               return 355;
  599.         case WEAPON_M4:                 return 356;
  600.         case WEAPON_TEC9:               return 372;
  601.         case WEAPON_RIFLE:              return 357;
  602.         case WEAPON_SNIPER:             return 358;
  603.         case WEAPON_ROCKETLAUNCHER:     return 359;
  604.         case WEAPON_HEATSEEKER:         return 360;
  605.         case WEAPON_FLAMETHROWER:       return 361;
  606.         case WEAPON_MINIGUN:            return 362;
  607.         case WEAPON_SATCHEL:            return 363;
  608.         case WEAPON_BOMB:               return 364;
  609.         case WEAPON_SPRAYCAN:           return 365;
  610.         case WEAPON_FIREEXTINGUISHER:   return 366;
  611.         case WEAPON_CAMERA:             return 367;
  612.         case 44:                        return 368;
  613.         case 45:                        return 369;
  614.         case WEAPON_PARACHUTE:          return 371;
  615.         default: return 0;
  616.     }
  617.     return 0;
  618. }
  619. stock GetWeaponPickupAmmoDifference(weaponid)
  620. {
  621.     switch(weaponid)
  622.     {
  623.         case WEAPON_CAMERA: return 36;
  624.         case WEAPON_FIREEXTINGUISHER: return 500;
  625.         case WEAPON_SPRAYCAN: return 500;
  626.         case WEAPON_SATCHEL: return 5;
  627.         case WEAPON_MINIGUN: return 500;
  628.         case WEAPON_FLAMETHROWER: return 100;
  629.         case WEAPON_HEATSEEKER: return 3;
  630.         case WEAPON_ROCKETLAUNCHER: return 4;
  631.         case WEAPON_SNIPER: return 10;
  632.         case WEAPON_RIFLE: return 20;
  633.         case WEAPON_TEC9: return 60;
  634.         case WEAPON_M4: return 80;
  635.         case WEAPON_AK47: return 80;
  636.         case WEAPON_MP5: return 60;
  637.         case WEAPON_UZI: return 60;
  638.         case WEAPON_SHOTGSPA: return 10;
  639.         case WEAPON_SAWEDOFF: return 10;
  640.         case WEAPON_SHOTGUN: return 15;
  641.         case WEAPON_DEAGLE: return 10;
  642.         case WEAPON_SILENCED: return 10;
  643.         case WEAPON_COLT45: return 30;
  644.         case WEAPON_MOLTOV: return 8;
  645.         case WEAPON_TEARGAS: return 8;
  646.         case WEAPON_GRENADE: return 8;
  647.         default: return 1;
  648.     }
  649.     return 1;
  650. }
  651. stock GetWeaponAmmunationPrice(weaponid)
  652. {
  653.     switch(weaponid)
  654.     {
  655.         case WEAPON_GRENADE: return 300;
  656.         case WEAPON_COLT45: return 200;
  657.         case WEAPON_SILENCED: return 600;
  658.         case WEAPON_DEAGLE: return 1200;
  659.         case WEAPON_SHOTGUN: return 600;
  660.         case WEAPON_SAWEDOFF: return 800;
  661.         case WEAPON_SHOTGSPA: return 1200;
  662.         case WEAPON_UZI: return 500;
  663.         case WEAPON_MP5: return 2000;
  664.         case WEAPON_AK47: return 3500;
  665.         case WEAPON_M4: return 4500;
  666.         case WEAPON_TEC9: return 300;
  667.         case WEAPON_RIFLE: return 1000;
  668.         case WEAPON_SNIPER: return 5000;
  669.         case WEAPON_SATCHEL: return 2000;
  670.         default: return 0;
  671.     }
  672.     return 0;
  673. }
  674.  
  675. #if !defined Distance
  676. stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
  677.     return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));
  678. #endif
  679.  
  680. stock IsPlayerBuyingInAmmunation(playerid)
  681. {
  682.     if(interiorsturnedoff)
  683.         return 0;
  684.    
  685.     if(GetPlayerCameraMode(playerid) != 15)
  686.         return 0;
  687.    
  688.     if(!GetWeaponAmmunationPrice(GetPlayerWeapon(playerid)))
  689.         return 0;
  690.        
  691.     static interiorid;
  692.     interiorid = GetPlayerInterior(playerid);
  693.    
  694.     static  
  695.         Float:CameraPositions[3];
  696.    
  697.     GetPlayerCameraPos(playerid, CameraPositions[0], CameraPositions[1], CameraPositions[2]);
  698.    
  699.     if(interiorid == 1)
  700.     {
  701.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], 296.584991, -38.345001, 1002.236022) > 0.5)
  702.             return 0;
  703.            
  704.         GetPlayerCameraFrontVector(playerid, CameraPositions[0], CameraPositions[1], CameraPositions[2]);
  705.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], -0.083937, -0.952462, -0.292864) > 0.3)
  706.             return 0;
  707.     }
  708.     else if(interiorid == 4)
  709.     {
  710.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], 295.819976, -80.656005, 1002.223022) > 0.5)
  711.             return 0;
  712.            
  713.         GetPlayerCameraFrontVector(playerid, CameraPositions[0], CameraPositions[1], CameraPositions[2]);
  714.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], -0.083937, -0.952462, -0.292865) > 0.3)
  715.             return 0;
  716.     }
  717.     else if(interiorid == 6)
  718.     {
  719.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], 290.320983, -109.684997, 1002.234008) > 0.5 &&
  720.             Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], 312.869995, -166.126007, 1000.307006) > 0.5 )
  721.             return 0;
  722.            
  723.         GetPlayerCameraFrontVector(playerid, CameraPositions[0], CameraPositions[1], CameraPositions[2]);
  724.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], -0.083936, -0.952462, -0.292863) > 0.3 &&
  725.             Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], -0.083938, -0.952461, -0.292867))
  726.             return 0;
  727.     }
  728.     else if(interiorid == 7)
  729.     {
  730.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], 308.226989, -141.281005, 1000.307006) > 0.5)
  731.             return 0;
  732.            
  733.         GetPlayerCameraFrontVector(playerid, CameraPositions[0], CameraPositions[1], CameraPositions[2]);
  734.         if(Distance(CameraPositions[0], CameraPositions[1], CameraPositions[2], -0.083938, -0.952461, -0.292867) > 0.3)
  735.             return 0;
  736.     }
  737.     else
  738.     {
  739.         return 0;
  740.     }
  741.     return 1;
  742. }
  743.  
  744. stock IsPlayerThrowingGrenade(playerid)
  745. {
  746.     static animid;
  747.     animid = GetPlayerAnimationIndex(playerid);
  748.     if(animid == 644 || animid == 645 || animid == 646)
  749.         return 1;
  750.        
  751.     return 0;
  752. }
  753. stock IsPlayerUsingWeapon(playerid)
  754. {
  755.     static animid;
  756.     animid = GetPlayerAnimationIndex(playerid);
  757.     if(1167 >= animid >= 1158)
  758.         return 1;
  759.        
  760.     return 0;
  761. }
  762. stock IsPlayerUsingParachute(playerid)
  763. {
  764.     static animid;
  765.     animid = GetPlayerAnimationIndex(playerid);
  766.     if(979 >= animid >= 958)
  767.         return 1;
  768.        
  769.     return 0;
  770. }
  771. stock GetWeaponSlotID(weaponid)
  772. {
  773.     switch(weaponid)
  774.     {
  775.         case 0, 1:          return 0;
  776.         case 2..9:          return 1;
  777.         case 10..15:        return 10;
  778.         case 16, 17, 18, 39:return 8;
  779.         case 22..24:        return 2;
  780.         case 25..27:        return 3;
  781.         case 28,29,32:      return 4;
  782.         case 30,31:         return 5;
  783.         case 33,34:         return 6;
  784.         case 35..38:        return 7;
  785.         case 40:            return 12;
  786.         case 41..43:        return 9;
  787.         case 44..46:        return 11;
  788.         default: return -1;
  789.     }
  790.     return -1;
  791. }
  792.  
  793. stock IsPlayerWeaponSlotTaken(playerid, slot)
  794. {
  795.     static weaponid, ammo;
  796.     GetPlayerWeaponData(playerid, slot, weaponid, ammo);
  797.     if(weaponid || ammo)
  798.         return weaponid;
  799.    
  800.     return 0;
  801. }
  802.  
  803. stock IsValidPlayerWeapon(playerid, weaponslot)
  804. {
  805.     if(!PlayerWeapons[playerid][weaponslot])
  806.         return 0;
  807.     if(PlayerWepAmmo[playerid][weaponslot] < 1)
  808.         return 0;
  809.        
  810.     return PlayerWeapons[playerid][weaponslot];
  811. }
  812.  
  813. stock SetPlayerLegitWeapons(playerid)
  814. {
  815.     ResetPlayerWeapons(playerid);
  816.     for(new wslot = 0; wslot < 12; wslot++)
  817.     {
  818.         if(!IsValidPlayerWeapon(playerid, wslot))
  819.             continue;
  820.                            
  821.         GivePlayerWeapon(
  822.             playerid,
  823.             PlayerWeapons[playerid][wslot],
  824.             PlayerWepAmmo[playerid][wslot]);
  825.     }
  826.     return 1;
  827. }
  828.  
  829. stock weapons_GivePlayerWeapon(playerid, weaponid, ammo)
  830. {
  831.     if(!weaponid)
  832.         return 0;
  833.        
  834.     if(ammo > MAX_WEAPON_AMMO) { ammo = MAX_WEAPON_AMMO; }
  835.    
  836.     static slot;
  837.     slot = GetWeaponSlotID(weaponid);
  838.    
  839.     if(IsPlayerWeaponSlotTaken(playerid, slot) == weaponid)
  840.     {
  841.         PlayerWepAmmo[playerid][slot]   +=  ammo;
  842.         if(PlayerWepAmmo[playerid][slot] > MAX_WEAPON_AMMO) { PlayerWepAmmo[playerid][slot] = MAX_WEAPON_AMMO; }
  843.     }
  844.     else
  845.     {
  846.         PlayerWeapons[playerid][slot]   =   weaponid;
  847.         PlayerWepAmmo[playerid][slot]   =   ammo;
  848.     }
  849.     LastPlayerAmmo[playerid] = ammo;
  850.     return GivePlayerWeapon(playerid, weaponid, ammo);
  851. }
  852.  
  853. stock RemovePlayerWeapon(playerid, weaponslot)
  854. {
  855.     ResetPlayerWeapons(playerid);
  856.     PlayerWeapons[playerid][weaponslot] = 0;
  857.     PlayerWepAmmo[playerid][weaponslot] = 0;
  858.    
  859.     SetPlayerLegitWeapons(playerid);
  860.     return 1;
  861. }
  862.  
  863. stock weapons_GetPlayerWeapon(playerid)
  864. {
  865.     static weaponid;
  866.     weaponid = GetPlayerWeapon(playerid);
  867.     if(IsValidPlayerWeapon(playerid, GetWeaponSlotID(weaponid)) == weaponid)
  868.     {
  869.         return weaponid;
  870.     }
  871.     return 0;
  872. }
  873.  
  874. stock weapons_GetPlayerAmmo(playerid)
  875. {
  876.     static weaponid;
  877.     weaponid = weapons_GetPlayerWeapon(playerid);
  878.        
  879.     if(weaponid)
  880.     {
  881.         return PlayerWepAmmo[playerid][GetWeaponSlotID(weaponid)];
  882.     }
  883.    
  884.     return 0;
  885. }
  886.  
  887. stock weapons_SetPlayerAmmo(playerid, weaponslot, ammo)
  888. {
  889.     if(IsValidPlayerWeapon(playerid, weaponslot))
  890.     {
  891.         if(GetPlayerWeapon(playerid) == PlayerWepAmmo[playerid][weaponslot])
  892.         {
  893.             LastPlayerAmmo  [playerid]  =   0;
  894.         }
  895.         PlayerWepAmmo[playerid][weaponslot] = ammo;
  896.         SetPlayerAmmo(playerid, weaponslot, ammo);
  897.         return 1;
  898.     }
  899.     return 0;
  900. }
  901.  
  902. stock weapons_ResetPlayerWeapons(playerid)
  903. {
  904.     ResetPlayerWeapons(playerid);
  905.     for(new slot = 0; slot < 12; slot++)
  906.     {
  907.         PlayerWeapons[playerid][slot] = 0;
  908.         PlayerWepAmmo[playerid][slot] = 0;
  909.     }
  910.     return 1;
  911. }
  912.  
  913. /*
  914.     I forgot the original creator for this code but it's very useful.
  915.     Effectively abstracts the basic checking for tick count intervals with some
  916.     extra code that compensates for integer overflowing from GetTickCount if the
  917.     server machine has been on for over 2,147,483,647 milliseconds.
  918. */
  919.  
  920. stock intdiffabs(tick1, tick2)
  921. {
  922.     if(tick1 > tick2)
  923.     {
  924.         new value = (tick1 - tick2);
  925.  
  926.         return value < 0 ? -value : value;
  927.     }
  928.  
  929.     else
  930.     {
  931.         new value = (tick1 - tick2);
  932.  
  933.         return value < 0 ? -value : value;
  934.     }
  935. }
  936.  
  937. stock GetTickCountDifference(a, b)
  938. {
  939.     if ((a < 0) && (b > 0))
  940.     {
  941.  
  942.         new dist;
  943.  
  944.         dist = intdiffabs(a, b);
  945.  
  946.         if(dist > 2147483647)
  947.             return intdiffabs(a - 2147483647, b - 2147483647);
  948.  
  949.         else
  950.             return dist;
  951.     }
  952.  
  953.     return intdiffabs(a, b);
  954. }
  955.  
  956. #if defined _ALS_DisableInteriorEnterExits
  957.     #undef DisableInteriorEnterExits
  958. #else
  959.     #define _ALS_DisableInteriorEnterExits
  960. #endif
  961. #define DisableInteriorEnterExits acwep_DisableInteriorEnterExits
  962.  
  963. #if defined _ALS_AddStaticPickup
  964.     #undef AddStaticPickup
  965. #else
  966.     #define _ALS_AddStaticPickup
  967. #endif
  968. #define AddStaticPickup weapons_AddStaticPickup
  969.  
  970. #if defined _ALS_CreatePickup
  971.     #undef CreatePickup
  972. #else
  973.     #define _ALS_CreatePickup
  974. #endif
  975. #define CreatePickup weapons_CreatePickup
  976.  
  977. #if defined _ALS_AddPlayerClass
  978.     #undef AddPlayerClass
  979. #else
  980.     #define _ALS_AddPlayerClass
  981. #endif
  982. #define AddPlayerClass weapons_AddPlayerClass
  983.  
  984. #if defined _ALS_AddPlayerClassEx
  985.     #undef AddPlayerClassEx
  986. #else
  987.     #define _ALS_AddPlayerClassEx
  988. #endif
  989. #define AddPlayerClassEx weapons_AddPlayerClassEx
  990.  
  991. #if defined _ALS_SetSpawnInfo
  992.     #undef SetSpawnInfo
  993. #else
  994.     #define _ALS_SetSpawnInfo
  995. #endif
  996. #define SetSpawnInfo weapons_SetSpawnInfo
  997.  
  998. #if defined _ALS_GivePlayerWeapon
  999.     #undef GivePlayerWeapon
  1000. #else
  1001.     #define _ALS_GivePlayerWeapon
  1002. #endif
  1003. #define GivePlayerWeapon weapons_GivePlayerWeapon
  1004.  
  1005. #if defined _ALS_GetPlayerWeapon
  1006.     #undef GetPlayerWeapon
  1007. #else
  1008.     #define _ALS_GetPlayerWeapon
  1009. #endif
  1010. #define GetPlayerWeapon weapons_GetPlayerWeapon
  1011.  
  1012. #if defined _ALS_GetPlayerAmmo
  1013.     #undef GetPlayerAmmo
  1014. #else
  1015.     #define _ALS_GetPlayerAmmo
  1016. #endif
  1017. #define GetPlayerAmmo weapons_GetPlayerAmmo
  1018.  
  1019. #if defined _ALS_SetPlayerAmmo
  1020.     #undef SetPlayerAmmo
  1021. #else
  1022.     #define _ALS_SetPlayerAmmo
  1023. #endif
  1024. #define SetPlayerAmmo weapons_SetPlayerAmmo
  1025.  
  1026. #if defined _ALS_ResetPlayerWeapons
  1027.     #undef ResetPlayerWeapons
  1028. #else
  1029.     #define _ALS_ResetPlayerWeapons
  1030. #endif
  1031. #define ResetPlayerWeapons weapons_ResetPlayerWeapons
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement