Advertisement
Guest User

Drop weapon system

a guest
Feb 16th, 2017
3,520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.30 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3. #define COLOR_PICK 0xFFC2C2FF
  4. #define function%0(%1) forward %0(%1); public %0(%1)
  5.  
  6. new activeHeal = 0;
  7. enum dInfo {
  8.     ID,
  9.     Type,
  10.     Weapon,
  11.     Ammo,
  12.     Text3D: Label
  13. }
  14. new DropInfo[MAX_PICKUPS][dInfo];
  15. #if defined FILTERSCRIPT
  16. public OnFilterScriptInit() print("Drop weapons system loaded..."), ResetPickups();
  17. public OnFilterScriptExit() DestroyPickups(), ResetPickups();
  18. #else
  19. main() { }
  20. #endif
  21. public OnPlayerDeath(playerid, killerid, reason) drop_player_weapons(playerid, 0);
  22.  
  23. public OnPlayerPickUpPickup(playerid, pickupid) {
  24.     new string[128];
  25.     for(new i = 0; i < MAX_PICKUPS; i++) {     
  26.         if(pickupid == DropInfo[i][ID] && DropInfo[i][ID] != -1) { 
  27.             if(DropInfo[i][Type] == 1) {
  28.                 SendClientMessage(playerid, COLOR_PICK, "You picked up medic kit. (+10 hp)");
  29.                 new Float: HP;
  30.                 GetPlayerHealth(playerid, HP);
  31.                 if(HP < 90) SetPlayerHealth(playerid, HP+10);
  32.                 else SetPlayerHealth(playerid, 100);
  33.             }
  34.             else {
  35.                 new gunname[32];
  36.                 GetWeaponName(DropInfo[i][Weapon], gunname, sizeof(gunname));
  37.                 format(string, sizeof(string), "You picked up weapon %s (%d ammo).", gunname, DropInfo[i][Ammo]);
  38.                 SendClientMessage(playerid, COLOR_PICK, string);
  39.                 GivePlayerWeapon(playerid, DropInfo[i][Weapon], DropInfo[i][Ammo]);
  40.             }          
  41.             DestroyPickup(DropInfo[i][ID]);
  42.             Delete3DTextLabel(DropInfo[i][Label]);
  43.             DropInfo[i][Type] = 0;
  44.             DropInfo[i][ID] = -1;
  45.             PlayerPlaySound(playerid, 1150, 0.0, 0.0, 10.0);   
  46.         }  
  47.     }
  48.     return 1;
  49. }  
  50.  
  51. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  52.     if(newkeys == KEY_WALK) drop_player_weapons(playerid, 1);
  53.     return 1;
  54. }
  55.  
  56. function ResetPickups() {
  57.     for(new i = 0; i < MAX_PICKUPS; i++) {
  58.         if(DropInfo[i][ID] != -1) DropInfo[i][ID] = -1;
  59.     }
  60.     return 1;
  61. }
  62.  
  63. function DestroyPickups() {
  64.     for(new i = 0; i < MAX_PICKUPS; i++) {
  65.         if(DropInfo[i][ID] != -1) {
  66.             DestroyPickup(DropInfo[i][ID]);
  67.             Delete3DTextLabel(DropInfo[i][Label]);
  68.             DropInfo[i][Type] = 0;
  69.             DropInfo[i][ID] = -1;
  70.         }
  71.     }
  72.     return 1;
  73. }
  74.  
  75. function drop_player_weapons(playerid, type) {
  76.     new Float: Pos[3], string[128], gunname[32], sweapon, sammo, idd, result;
  77.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  78.  
  79.     for(new i = 0; i < 12; i++) {
  80.         GetPlayerWeaponData(playerid, i, sweapon, sammo);
  81.         if(sweapon != 0) {
  82.             result++;
  83.             idd = CheckIDEmpty();
  84.             DropInfo[idd][ID] = CreatePickup(WeaponObject(sweapon), 23, Pos[0]+result, Pos[1]+2, Pos[2], -1);
  85.             DropInfo[idd][Type] =  0;
  86.             DropInfo[idd][Weapon] = sweapon;
  87.             DropInfo[idd][Ammo] = sammo;
  88.             GetWeaponName(sweapon, gunname, sizeof(gunname));          
  89.             format(string, sizeof(string), "{90F037}%s\n{FFFFFF}%d bullets", gunname, sammo);          
  90.             DropInfo[idd][Label] = Create3DTextLabel(string, 0xFFFFFFAA, Pos[0]+result, Pos[1]+2, Pos[2], 10.0, 0, 0);
  91.         }
  92.     }
  93.     if(activeHeal == 1 && type == 0) {
  94.         result++;
  95.         idd = CheckIDEmpty();
  96.         DropInfo[idd][ID] = CreatePickup(1240, 23, Pos[0]+result, Pos[1]+2, Pos[2], -1);
  97.         DropInfo[idd][Type] = 1;
  98.         DropInfo[idd][Weapon] = 0;
  99.         DropInfo[idd][Ammo] = 0;
  100.         DropInfo[idd][Label] = Create3DTextLabel("{DE1212}Medic kit", 0xFFFFFFFF, Pos[0]+result, Pos[1]+2, Pos[2], 10.0, 0, 0);
  101.     }  
  102.     ResetPlayerWeapons(playerid);
  103.     return 1;
  104. }
  105.  
  106. function CheckIDEmpty() {
  107.     for(new i = 0; i < MAX_PICKUPS; i++) {
  108.         if(DropInfo[i][ID] == -1) return i;
  109.     }
  110.     return 0;
  111. }
  112.  
  113. function WeaponObject(wid) {
  114.     if(wid == 1) return 331;
  115.     else if(wid == 2) return 332;
  116.     else if(wid == 3) return 333;
  117.     else if(wid == 5) return 334;
  118.     else if(wid == 6) return 335;
  119.     else if(wid == 7) return 336;
  120.     else if(wid == 10) return 321;
  121.     else if(wid == 11) return 322;
  122.     else if(wid == 12) return 323;
  123.     else if(wid == 13) return 324;
  124.     else if(wid == 14) return 325;
  125.     else if(wid == 15) return 326;
  126.     else if(wid == 23) return 347;
  127.     else if(wid == 24) return 348;
  128.     else if(wid == 25) return 349;
  129.     else if(wid == 26) return 350;
  130.     else if(wid == 27) return 351;
  131.     else if(wid == 28) return 352;
  132.     else if(wid == 29) return 353;
  133.     else if(wid == 30) return 355;
  134.     else if(wid == 31) return 356;
  135.     else if(wid == 32) return 372;
  136.     else if(wid == 33) return 357;
  137.     else if(wid == 4) return 335;
  138.     else if(wid == 34) return 358;
  139.     else if(wid == 41) return 365;
  140.     else if(wid == 42) return 366;
  141.     else if(wid == 43) return 367;
  142.     return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement