Guest User

dropgun

a guest
Feb 10th, 2017
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.23 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3.  
  4. // Podesavanja:
  5. #define MAX_OBJ 50 // Limit Oruzija koliko moze biti baceno
  6. #define SAVING // Oruzija se pamte nakon restarta ili restartovanja skripte
  7. // -----------------------------------------------------------------------------
  8. enum dGunEnum
  9. {
  10. Float:ObjPos[3],
  11. ObjID,
  12. ObjData[2]
  13. };
  14. new dGunData[MAX_OBJ][dGunEnum];
  15. // -----------------------------------------------------------------------------
  16. new GunNames[48][] = {
  17. "Nothink", "Brass Knuckles", "Golf Club", "Nitestick", "Knife", "Baseball Bat",
  18. "Showel", "Pool Cue", "Katana", "Chainsaw", "Purple Dildo", "Small White Dildo",
  19. "Long White Dildo", "Vibrator", "Flowers", "Cane", "Grenade", "Tear Gas", "Molotov",
  20. "Vehicle Missile", "Hydra Flare", "Jetpack", "Glock", "Silenced Colt", "Desert Eagle",
  21. "Shotgun", "Sawn Off", "Combat Shotgun", "Micro UZI", "MP5", "AK47", "M4", "Tec9",
  22. "Rifle", "Sniper Rifle", "Rocket Launcher", "HS Rocket Launcher", "Flamethrower", "Minigun",
  23. "Satchel Charge", "Detonator", "Spraycan", "Fire Extinguisher", "Camera", "Nightvision",
  24. "Infrared Vision", "Parachute", "Fake Pistol"
  25. };
  26. // -----------------------------------------------------------------------------
  27. new GunObjects[47] = {
  28. 0,331,333,334,335,336,337,338,339,341,321,322,323,324,325,326,342,343,344,
  29. 0,0,0,346,347,348,349,350,351,352,353,355,356,372,357,358,359,360,361,362,
  30. 363,364,365,366,367,368,368,371
  31. };
  32. // -----------------------------------------------------------------------------
  33. public OnFilterScriptInit()
  34. {
  35. for(new n = 0; n < MAX_OBJ; n++) dGunData[n][ObjID] = -1;
  36. print("\n");
  37. print(" [FS] Drop Gun By Cherlnos (c)");
  38. print(" Do not remove copyright!!!");
  39. print(" Version 1.0\n");
  40. #if defined SAVING
  41. new File:file = fopen("BacenaOruzja.ini", io_read);
  42. if(file)
  43. {
  44. new buffer[256], FileCoords[5][20];
  45. for(new g = 0; g < MAX_OBJ; g++)
  46. {
  47. fread(file, buffer);
  48. split(buffer, FileCoords, ',');
  49. dGunData[g][ObjPos][0] = floatstr(FileCoords[0]);
  50. dGunData[g][ObjPos][1] = floatstr(FileCoords[1]);
  51. dGunData[g][ObjPos][2] = floatstr(FileCoords[2]);
  52. dGunData[g][ObjData][0] = strval(FileCoords[3]);
  53. dGunData[g][ObjData][1] = strval(FileCoords[4]);
  54. if(dGunData[g][ObjData][0] > 0 && dGunData[g][ObjData][1] != 0 && dGunData[g][ObjPos][0] != 0)
  55. {
  56. dGunData[g][ObjID] = CreateObject(GunObjects[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1, 93.7, 120.0, 120.0);
  57. printf("* %s loaded: %f,%f,%f", GunNames[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1);
  58. }
  59. }
  60. }
  61. else print("ERROR: Problem sa otvaranjem \"BacenaOruzja.ini\"");
  62. #endif
  63. return 1;
  64. }
  65. // -----------------------------------------------------------------------------
  66. public OnFilterScriptExit()
  67. {
  68. #if defined SAVING
  69. new File:file = fopen("BacenaOruzja.ini", io_append);
  70. if(file)
  71. {
  72. fclose(file);
  73. for(new g = 0, buffer[50]; g < MAX_OBJ; g++)
  74. {
  75. format(buffer, sizeof(buffer), "%f,%f,%f,%d,%d\n",
  76. dGunData[g][ObjPos][0],
  77. dGunData[g][ObjPos][1],
  78. dGunData[g][ObjPos][2],
  79. dGunData[g][ObjData][0],
  80. dGunData[g][ObjData][1]);
  81. if(g == 0) file = fopen("BacenaOruzja.ini", io_write);
  82. else file = fopen("BacenaOruzja.ini", io_append);
  83. fwrite(file, buffer);
  84. fclose(file);
  85. if(dGunData[g][ObjData][0] > 0 && dGunData[g][ObjPos][1] != 0)
  86. {
  87. DestroyObject(dGunData[g][ObjID]);
  88. printf("* %s zapamceno: %f,%f,%f", GunNames[dGunData[g][ObjData][0]], dGunData[g][ObjPos][0], dGunData[g][ObjPos][1], dGunData[g][ObjPos][2]-1);
  89. }
  90. }
  91. }
  92. else print("ERROR: Problem sa otvaranjem \"BacenaOruzja.ini\"");
  93. #endif
  94. return 1;
  95. }
  96. // -----------------------------------------------------------------------------
  97. public OnPlayerCommandText(playerid, cmdtext[])
  98. {
  99. if(strcmp(cmdtext, "/dropgun", true) == 0
  100. || strcmp(cmdtext, "/dgun", true) == 0)
  101. {
  102. if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
  103. new GunID = GetPlayerWeapon(playerid);
  104. new GunAmmo = GetPlayerAmmo(playerid);
  105. if(GunID > 0 && GunAmmo != 0)
  106. {
  107. new f = MAX_OBJ+1;
  108. for(new a = 0; a < MAX_OBJ; a++)
  109. {
  110. if(dGunData[a][ObjPos][0] == 0.0)
  111. {
  112. f = a;
  113. break;
  114. }
  115. }
  116. if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "Ne mozete baciti oruzije u ovom trenutku, probajte kasnije!");
  117. RemovePlayerWeapon(playerid, GunID);
  118. dGunData[f][ObjData][0] = GunID;
  119. dGunData[f][ObjData][1] = GunAmmo;
  120. GetPlayerPos(playerid, dGunData[f][ObjPos][0], dGunData[f][ObjPos][1], dGunData[f][ObjPos][2]);
  121. dGunData[f][ObjID] = CreateObject(GunObjects[GunID], dGunData[f][ObjPos][0], dGunData[f][ObjPos][1], dGunData[f][ObjPos][2]-1, 93.7, 120.0, 120.0);
  122. new buffer[50];
  123. format(buffer, sizeof(buffer), "Bacio si %s", GunNames[dGunData[f][ObjData][0]]);
  124. SendClientMessage(playerid, 0x33AA3300, buffer);
  125. }
  126. return 1;
  127. }
  128. if(strcmp(cmdtext, "/pickupgun", true) == 0
  129. || strcmp(cmdtext, "/pgun", true) == 0)
  130. {
  131. if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
  132. new f = MAX_OBJ+1;
  133. for(new a = 0; a < MAX_OBJ; a++)
  134. {
  135. if(IsPlayerInRangeOfPoint(playerid, 5.0, dGunData[a][ObjPos][0], dGunData[a][ObjPos][1], dGunData[a][ObjPos][2]))
  136. {
  137. f = a;
  138. break;
  139. }
  140. }
  141. if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "[NC:RP]U blizini nema nijednog oruzija koje mozete pokupiti!");
  142. DestroyObject(dGunData[f][ObjID]);
  143. GivePlayerWeapon(playerid, dGunData[f][ObjData][0], dGunData[f][ObjData][1]);
  144. dGunData[f][ObjPos][0] = 0.0;
  145. dGunData[f][ObjPos][1] = 0.0;
  146. dGunData[f][ObjPos][2] = 0.0;
  147. dGunData[f][ObjID] = -1;
  148. //dGunData[f][ObjData][0] = 0;
  149. dGunData[f][ObjData][1] = 0;
  150. new buffer[50];
  151. format(buffer, sizeof(buffer), "[NC:RP]Pokupili Ste %s", GunNames[dGunData[f][ObjData][0]]);
  152. SendClientMessage(playerid, 0x33AA3300, buffer);
  153. return 1;
  154. }
  155. return 0;
  156. }
  157. // -----------------------------------------------------------------------------
  158. public OnPlayerDeath(playerid, killerid, reason)
  159. {
  160. new Float:pPosX, Float:pPosY, Float:pPosZ;
  161. GetPlayerPos(playerid, pPosX, pPosY, pPosZ);
  162. for(new i_slot = 0, gun, ammo; i_slot != 12; i_slot++)
  163. {
  164. GetPlayerWeaponData(playerid, i_slot, gun, ammo);
  165. if(gun != 0 && ammo != 0) CreateDroppedGun(gun, ammo, pPosX+random(2)-random(2), pPosY+random(2)-random(2), pPosZ);
  166. }
  167. return 1;
  168. }
  169. stock CreateDroppedGun(GunID, GunAmmo, Float:gPosX, Float:gPosY, Float:gPosZ)
  170. {
  171. new f = MAX_OBJ+1;
  172. for(new a = 0; a < MAX_OBJ; a++)
  173. {
  174. if(dGunData[a][ObjPos][0] == 0.0)
  175. {
  176. f = a;
  177. break;
  178. }
  179. }
  180. if(f > MAX_OBJ) return;
  181. dGunData[f][ObjData][0] = GunID;
  182. dGunData[f][ObjData][1] = GunAmmo;
  183. dGunData[f][ObjPos][0] = gPosX;
  184. dGunData[f][ObjPos][1] = gPosY;
  185. dGunData[f][ObjPos][2] = gPosZ;
  186. dGunData[f][ObjID] = CreateObject(GunObjects[GunID], dGunData[f][ObjPos][0], dGunData[f][ObjPos][1], dGunData[f][ObjPos][2]-1, 93.7, 120.0, random(360));
  187. return;
  188. }
  189. // -----------------------------------------------------------------------------
  190. stock RemovePlayerWeapon(playerid, weaponid)
  191. {
  192. new plyWeapons[12] = 0;
  193. new plyAmmo[12] = 0;
  194. for(new sslot = 0; sslot != 12; sslot++)
  195. {
  196. new wep, ammo;
  197. GetPlayerWeaponData(playerid, sslot, wep, ammo);
  198. if(wep != weaponid && ammo != 0) GetPlayerWeaponData(playerid, sslot, plyWeapons[sslot], plyAmmo[sslot]);
  199. }
  200. ResetPlayerWeapons(playerid);
  201. for(new sslot = 0; sslot != 12; sslot++) if(plyAmmo[sslot] != 0) GivePlayerWeapon(playerid, plyWeapons[sslot], plyAmmo[sslot]);
  202. return 1;
  203. }
  204. stock split(const strsrc[], strdest[][], delimiter)
  205. {
  206. new i, li;
  207. new aNum;
  208. new len;
  209. while(i <= strlen(strsrc))
  210. {
  211. if(strsrc[i]==delimiter || i==strlen(strsrc))
  212. {
  213. len = strmid(strdest[aNum], strsrc, li, i, 128);
  214. strdest[aNum][len] = 0;
  215. li = i+1;
  216. aNum++;
  217. }
  218. i++;
  219. }
  220. return 1;
  221. }
Advertisement
Add Comment
Please, Sign In to add comment