Advertisement
Guest User

Cops.inc

a guest
Jan 23rd, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.60 KB | None | 0 0
  1. //Made by lokii.
  2.  
  3. #if !defined _inc_a_samp
  4. #error COPS.inc: Please include a_samp before COPS
  5. #endif
  6.  
  7. #if !defined _inc_fcnpc
  8. #error COPS.inc: Please include FCNPC before COPS
  9. #endif
  10.  
  11. #if FCNPC_INCLUDE_VERSION < 200
  12. #error COPS.inc: Please download fcnpc 2.0.0
  13. #endif
  14.  
  15. #if !defined MAX_COPS
  16. #define MAX_COPS (50)
  17. #endif
  18.  
  19. /*
  20. native Natives();
  21. native
  22. native CreateCop(skinid, name[], Float:detection_area, Float:health, Float:x, Float:y, Float:z, Float:angle, weapon, Float:accuracy);
  23. native IsCopDead(cop_id);
  24. native IsCopInvulnerable(cop_id);
  25. native IsCopMoving(cop_id);
  26. native IsCopValid(cop_id);
  27. native GetCopHealth(cop_id);
  28. native GetCopTarget(cop_id);
  29. native GetClosestPlayerToCop(cop_id);
  30. native GetCopDetectionArea(cop_id);
  31. native GetCopPos(cop_id, &Float:x, &Float:y, &Float:z);
  32. native GetCopAngle(cop_id, &Float:angle);
  33. native GetCopCreationPos(cop_id, &Float:x, &Float:y, &Float:z);
  34. native GetCopCreationAngle(cop_id, &Float:angle);
  35. native GetCopInterior(cop_id);
  36. native GetCopVirtualWorld(cop_id);
  37. native GetCopSkin(cop_id);
  38. native GetCopCustomSkin(cop_id);
  39. native GetCopWeapon(cop_id);
  40. native SetCopWeapon(cop_id, weaponid);
  41. native SetCopInvulnerable(cop_id, bool:invulnerable);
  42. native SetCopSkin(cop_id, skinid);
  43. native SetCopInterior(cop_id, interiorid);
  44. native SetCopVirtualWorld(cop_id, worldid);
  45. native SetCopHealth(cop_id, Float:health);
  46. native RespawnCop(cop_id);
  47. native DestroyCop(cop_id);
  48. native DestroyAllCops();
  49. native
  50. native Callbacks();
  51. native
  52. native OnCopDeath(cop_id, killerid, weaponid);
  53. native OnCopTakeDamage(cop_id, damagerid, weaponid, bodypart, Float:health_loss);
  54. native OnCopKillPlayer(cop_id, playerid);
  55. native OnCrimeHappenNearCop(playerid, crime);
  56. */
  57.  
  58. #define CRIME_KILL 0
  59. #define CRIME_SHOOT 1
  60. #define CRIME_DAMAGE 2
  61.  
  62. enum ee_cops
  63. {
  64. bool:cop_exist,
  65. cop_time,
  66. copid,
  67. cop_target,
  68. Float:cop_detection,
  69. Float:cop_pos_x,
  70. Float:cop_pos_y,
  71. Float:cop_pos_z,
  72. Float:cop_angle
  73. }
  74. new e_cops[MAX_COPS][ee_cops];
  75.  
  76. stock SetCopInterior(cop_id, interiorid)
  77. {
  78. if(IsCopValid(cop_id))
  79. {
  80. FCNPC_SetInterior(e_cops[cop_id][copid], interiorid);
  81. return 1;
  82. }
  83. return 0;
  84. }
  85.  
  86. stock GetCopInterior(cop_id)
  87. {
  88. if(IsCopValid(cop_id))
  89. {
  90. return FCNPC_GetInterior(e_cops[cop_id][copid]);
  91. }
  92. return 0;
  93. }
  94.  
  95. stock SetCopVirtualWorld(cop_id, worldid)
  96. {
  97. if(IsCopValid(cop_id))
  98. {
  99. FCNPC_SetVirtualWorld(e_cops[cop_id][copid], worldid);
  100. return 1;
  101. }
  102. return 0;
  103. }
  104.  
  105. stock GetCopVirtualWorld(cop_id)
  106. {
  107. if(IsCopValid(cop_id))
  108. {
  109. return FCNPC_GetVirtualWorld(e_cops[cop_id][copid]);
  110. }
  111. return 0;
  112. }
  113.  
  114. stock GetCopCreationPos(cop_id, &Float:x, &Float:y, &Float:z)
  115. {
  116. if(IsCopValid(cop_id))
  117. {
  118. x = e_cops[cop_id][cop_pos_x];
  119. y = e_cops[cop_id][cop_pos_y];
  120. z = e_cops[cop_id][cop_pos_z];
  121. }
  122. return 0;
  123. }
  124.  
  125. stock GetCopCreationAngle(cop_id, &Float:angle)
  126. {
  127. if(IsCopValid(cop_id))
  128. {
  129. angle = e_cops[cop_id][cop_angle];
  130. }
  131. return 0;
  132. }
  133.  
  134. stock GetCopAngle(cop_id, &Float:angle)
  135. {
  136. if(IsCopValid(cop_id))
  137. {
  138. angle = FCNPC_GetAngle(e_cops[cop_id][copid]);
  139. }
  140. return 0;
  141. }
  142.  
  143. stock bool:IsCopMoving(cop_id)
  144. {
  145. if(IsCopValid(cop_id))
  146. {
  147. return FCNPC_IsMoving(e_cops[cop_id][copid]);
  148. }
  149. return false;
  150. }
  151.  
  152. Float:GetCopDetectionArea(cop_id)
  153. {
  154. return e_cops[cop_id][cop_detection];
  155. }
  156.  
  157. IsCopValid(cop_id)
  158. {
  159. if(cop_id < 0 || cop_id >= MAX_COPS) return 0;
  160. return e_cops[cop_id][cop_exist];
  161. }
  162.  
  163. stock CreateCop(skinid, name[], Float:detection_area, Float:health, Float:x, Float:y, Float:z, Float:angle, weapon, Float:accuracy)
  164. {
  165. for(new i = 0; i < MAX_COPS; i++)
  166. {
  167. if(IsCopValid(i)) continue;
  168. e_cops[i][copid] = FCNPC_Create(name);
  169. FCNPC_Spawn(e_cops[i][copid], skinid, x, y, z);
  170. FCNPC_SetHealth(e_cops[i][copid], health);
  171. FCNPC_SetAngle(e_cops[i][copid], angle);
  172. FCNPC_SetWeaponAccuracy(e_cops[i][copid], weapon, accuracy);
  173. FCNPC_SetWeapon(e_cops[i][copid], weapon);
  174. FCNPC_UseInfiniteAmmo(e_cops[i][copid], true);
  175. e_cops[i][cop_pos_x] = x;
  176. e_cops[i][cop_pos_y] = y;
  177. e_cops[i][cop_pos_z] = z;
  178. e_cops[i][cop_angle] = angle;
  179. e_cops[i][cop_detection] = detection_area;
  180. e_cops[i][cop_target] = 0xFFFF;
  181. e_cops[i][cop_exist] = true;
  182. if(FCNPC_IsValid(e_cops[i][copid]))
  183. {
  184. return i;
  185. }
  186. else
  187. {
  188. DestroyCop(i);
  189. return 0xFFFF;
  190. }
  191. }
  192. return 0xFFFF;
  193. }
  194.  
  195. stock SetCopWeapon(cop_id, weaponid)
  196. {
  197. if(IsCopValid(cop_id))
  198. {
  199. FCNPC_SetWeapon(e_cops[cop_id][copid], weaponid);
  200. return 1;
  201. }
  202. return 0;
  203. }
  204.  
  205. stock GetCopWeapon(cop_id)
  206. {
  207. if(IsCopValid(cop_id))
  208. {
  209. return FCNPC_GetWeapon(e_cops[cop_id][copid]);
  210. }
  211. return 0;
  212. }
  213.  
  214. stock GetCopPos(cop_id, &Float:x, &Float:y, &Float:z)
  215. {
  216. if(IsCopValid(cop_id))
  217. {
  218. FCNPC_GetPosition(e_cops[cop_id][copid], x, y, z);
  219. }
  220. return 0;
  221. }
  222.  
  223. stock Float:GetCopHealth(cop_id)
  224. {
  225. if(IsCopValid(cop_id))
  226. {
  227. return FCNPC_GetHealth(e_cops[cop_id][copid]);
  228. }
  229. return 0.0;
  230. }
  231.  
  232. stock bool:IsCopDead(cop_id)
  233. {
  234. if(IsCopValid(cop_id))
  235. {
  236. return FCNPC_IsDead(e_cops[cop_id][copid]);
  237. }
  238. return false;
  239. }
  240.  
  241. stock RespawnCop(cop_id)
  242. {
  243. if(IsCopValid(cop_id))
  244. {
  245. FCNPC_Respawn(e_cops[cop_id][copid]);
  246. FCNPC_SetPosition(e_cops[cop_id][copid], e_cops[cop_id][cop_pos_x], e_cops[cop_id][cop_pos_y], e_cops[cop_id][cop_pos_z]);
  247. FCNPC_SetAngle(e_cops[cop_id][copid], e_cops[cop_id][cop_angle]);
  248. return 1;
  249. }
  250. return 0;
  251. }
  252.  
  253. stock DestroyCop(cop_id)
  254. {
  255. if(IsCopValid(cop_id))
  256. {
  257. FCNPC_Destroy(e_cops[cop_id][copid]);
  258. e_cops[cop_id][cop_pos_x] = 0.0;
  259. e_cops[cop_id][cop_pos_y] = 0.0;
  260. e_cops[cop_id][cop_pos_z] = 0.0;
  261. e_cops[cop_id][cop_angle] = 0.0;
  262. e_cops[cop_id][cop_detection] = 0.0;
  263. e_cops[cop_id][cop_target] = 0xFFFF;
  264. e_cops[cop_id][cop_exist] = false;
  265. return 1;
  266. }
  267. return 0;
  268. }
  269.  
  270. CopAttackPlayer(cop_id, playerid)
  271. {
  272. if(IsCopValid(cop_id) && IsPlayerConnected(playerid))
  273. {
  274. FCNPC_AimAtPlayer(e_cops[cop_id][copid], playerid, true, -1, true, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  275. e_cops[cop_id][cop_target] = playerid;
  276. return playerid;
  277. }
  278. return 0xFFFF;
  279. }
  280.  
  281. stock SetCopHealth(cop_id, Float:health)
  282. {
  283. if(IsCopValid(cop_id))
  284. {
  285. FCNPC_SetHealth(e_cops[cop_id][copid], health);
  286. }
  287. return 0;
  288. }
  289.  
  290. GetCopTarget(cop_id)
  291. {
  292. return e_cops[cop_id][cop_target];
  293. }
  294.  
  295. forward OnCopDeath(cop_id, killerid, weaponid);
  296.  
  297. public FCNPC_OnDeath(npcid, killerid, reason)
  298. {
  299. if(killerid == 0xFFFF) return 1;
  300. for(new i = 0; i < MAX_COPS; i++)
  301. {
  302. if(!IsCopValid(i) || e_cops[i][copid] != npcid) continue;
  303. CallLocalFunction("OnCopDeath", "iii", i, killerid, reason);
  304. }
  305.  
  306. #if defined cops_FCNPC_OnDeath
  307. return cops_FCNPC_OnDeath(npcid, killerid, weaponid);
  308. #else
  309. return 1;
  310. #endif
  311. }
  312. #if defined _ALS_FCNPC_OnDeath
  313. #undef FCNPC_OnDeath
  314. #else
  315. #define _ALS_FCNPC_OnDeath
  316. #endif
  317. #define FCNPC_OnDeath cops_FCNPC_OnDeath
  318. #if defined cops_FCNPC_OnDeath
  319. forward cops_FCNPC_OnDeath(npcid, killerid, weaponid);
  320. #endif
  321.  
  322. stock GetClosestPlayerToCop(cop_id)
  323. {
  324. new id = -1, Float:last = 99999, Float:x, Float:y, Float:z;
  325. if(IsCopValid(cop_id))
  326. {
  327. FCNPC_GetPosition(e_cops[copid][copid], x, y, z);
  328. for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  329. {
  330. if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
  331. if(GetPlayerDistanceFromPoint(i, x, y, z) >= last) continue;
  332. last = GetPlayerDistanceFromPoint(i, x, y, z);
  333. id = i;
  334. }
  335. }
  336. return id;
  337. }
  338.  
  339. public FCNPC_OnUpdate(npcid)
  340. {
  341. new Float:x, Float:y, Float:z;
  342. for(new k = 0; k < MAX_COPS; k++)
  343. {
  344. if(e_cops[k][copid] != npcid) continue;
  345. if(IsCopDead(k)) break;
  346. if(e_cops[k][cop_time] != gettime())
  347. {
  348. FCNPC_GetPosition(e_cops[k][copid], x, y, z);
  349. for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  350. {
  351. if(!IsPlayerConnected(i) || IsPlayerNPC(i) || GetPlayerInterior(i) != GetCopInterior(k) || GetPlayerVirtualWorld(i) != GetCopVirtualWorld(k)) continue;
  352. if(GetCopTarget(k) == i && GetPlayerWantedLevel(i) == 0 || GetCopTarget(k) == i && GetPlayerDistanceFromPoint(i, x, y, z) > GetCopDetectionArea(k))
  353. {
  354. FCNPC_Stop(e_cops[k][copid]);
  355. FCNPC_StopAim(e_cops[k][copid]);
  356. e_cops[k][cop_target] = 0xFFFF;
  357. e_cops[k][cop_time] = gettime();
  358. }
  359. else
  360. {
  361. if(GetPlayerWantedLevel(i) >= 1 && GetPlayerDistanceFromPoint(i, x, y, z) <= GetCopDetectionArea(k))
  362. {
  363. CopAttackPlayer(k, i);
  364. if(GetPlayerDistanceFromPoint(i, x, y, z) >= GetCopDetectionArea(k)/2)
  365. {
  366. FCNPC_GoToPlayer(e_cops[k][copid], i, FCNPC_MOVE_TYPE_AUTO, FCNPC_MOVE_SPEED_AUTO, FCNPC_MOVE_MODE_COLANDREAS, FCNPC_MOVE_PATHFINDING_RAYCAST, 5.0, true, 3.0, 1.5, 250);
  367. e_cops[k][cop_time] = gettime();
  368. }
  369. e_cops[k][cop_time] = gettime();
  370. }
  371. }
  372. }
  373. }
  374. }
  375.  
  376. #if defined cops_FCNPC_OnUpdate
  377. return cops_FCNPC_OnUpdate(npcid);
  378. #else
  379. return 1;
  380. #endif
  381. }
  382. #if defined _ALS_FCNPC_OnUpdate
  383. #undef FCNPC_OnUpdate
  384. #else
  385. #define _ALS_FCNPC_OnUpdate
  386. #endif
  387. #define FCNPC_OnUpdate cops_FCNPC_OnUpdate
  388. #if defined cops_FCNPC_OnUpdate
  389. forward cops_FCNPC_OnUpdate(npcid);
  390. #endif
  391.  
  392. forward OnCopTakeDamage(cop_id, damagerid, weaponid, bodypart, Float:health_loss);
  393.  
  394. public FCNPC_OnTakeDamage(npcid, issuerid, Float:amount, weaponid, bodypart)
  395. {
  396. if(issuerid == 0xFFFF) return 1;
  397. for(new i = 0; i < MAX_COPS; i++)
  398. {
  399. if(!IsCopValid(i) || e_cops[i][copid] != npcid) continue;
  400. CallLocalFunction("OnCopTakeDamage", "iiiif", i, issuerid, weaponid, bodypart, amount);
  401. }
  402.  
  403. #if defined cops_FCNPC_OnTakeDamage
  404. return cops_FCNPC_OnTakeDamage(npcid, issuerid, Float:amount, weaponid, bodypart);
  405. #else
  406. return 1;
  407. #endif
  408. }
  409. #if defined _ALS_FCNPC_OnTakeDamage
  410. #undef FCNPC_OnTakeDamage
  411. #else
  412. #define _ALS_FCNPC_OnTakeDamage
  413. #endif
  414. #define FCNPC_OnTakeDamage cops_FCNPC_OnTakeDamage
  415. #if defined cops_FCNPC_OnTakeDamage
  416. forward cops_FCNPC_OnTakeDamage(npcid, issuerid, Float:amount, weaponid, bodypart);
  417. #endif
  418.  
  419. forward OnCopKillPlayer(cop_id, playerid);
  420.  
  421. public OnPlayerDeath(playerid, killerid, reason)
  422. {
  423. new Float:x, Float:y, Float:z;
  424. if(killerid == 0xFFFF) return 1;
  425. for(new i = 0; i < MAX_COPS; i ++)
  426. {
  427. if(!IsCopValid(i)) continue;
  428. if(!IsPlayerNPC(killerid))
  429. {
  430. GetCopPos(i, x, y, z);
  431. if(!IsPlayerInRangeOfPoint(playerid, GetCopDetectionArea(i), x, y, z)) continue;
  432. CallLocalFunction("OnCrimeHappenNearCop", "ii", killerid, CRIME_KILL);
  433. break;
  434. }
  435. if(IsPlayerNPC(killerid))
  436. {
  437. CallLocalFunction("OnCopKillPlayer", "ii", i, playerid);
  438. break;
  439. }
  440. }
  441.  
  442. #if defined cops_OnPlayerDeath
  443. return cops_OnPlayerDeath(playerid, killerid, reason);
  444. #else
  445. return 1;
  446. #endif
  447. }
  448. #if defined _ALS_OnPlayerDeath
  449. #undef OnPlayerDeath
  450. #else
  451. #define _ALS_OnPlayerDeath
  452. #endif
  453. #define OnPlayerDeath cops_OnPlayerDeath
  454. #if defined cops_OnPlayerDeath
  455. forward cops_OnPlayerDeath(playerid, killerid, reason);
  456. #endif
  457.  
  458. forward OnCrimeHappenNearCop(playerid, crime);
  459.  
  460. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  461. {
  462. new Float:x, Float:y, Float:z;
  463. for(new i = 0; i < MAX_COPS; i ++)
  464. {
  465. if(!IsCopValid(i)) continue;
  466. GetCopPos(i, x, y, z);
  467. if(!IsPlayerInRangeOfPoint(playerid, GetCopDetectionArea(i), x, y, z)) continue;
  468. CallLocalFunction("OnCrimeHappenNearCop", "ii", playerid, CRIME_SHOOT);
  469. break;
  470. }
  471.  
  472. #if defined cops_OnPlayerWeaponShot
  473. return cops_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  474. #else
  475. return 1;
  476. #endif
  477. }
  478. #if defined _ALS_OnPlayerWeaponShot
  479. #undef OnPlayerWeaponShot
  480. #else
  481. #define _ALS_OnPlayerWeaponShot
  482. #endif
  483. #define OnPlayerWeaponShot cops_OnPlayerWeaponShot
  484. #if defined cops_OnPlayerWeaponShot
  485. forward cops_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  486. #endif
  487.  
  488. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
  489. {
  490. new Float:x, Float:y, Float:z;
  491. if(issuerid == 0xFFFF || IsPlayerNPC(issuerid)) return 0;
  492. for(new i = 0; i < MAX_COPS; i ++)
  493. {
  494. if(!IsCopValid(i)) continue;
  495. GetCopPos(i, x, y, z);
  496. if(!IsPlayerInRangeOfPoint(playerid, GetCopDetectionArea(i), x, y, z)) continue;
  497. CallLocalFunction("OnCrimeHappenNearCop", "ii", issuerid, CRIME_DAMAGE);
  498. break;
  499. }
  500.  
  501. #if defined cops_OnPlayerTakeDamage
  502. return cops_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart);
  503. #else
  504. return 0;
  505. #endif
  506. }
  507. #if defined _ALS_OnPlayerTakeDamage
  508. #undef OnPlayerTakeDamage
  509. #else
  510. #define _ALS_OnPlayerTakeDamage
  511. #endif
  512. #define OnPlayerTakeDamage cops_OnPlayerTakeDamage
  513. #if defined cops_OnPlayerTakeDamage
  514. forward cops_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart);
  515. #endif
  516.  
  517. DestroyAllCops()
  518. {
  519. for(new i = 0; i < MAX_COPS; i++)
  520. {
  521. if(!IsCopValid(i)) continue;
  522. DestroyCop(i);
  523. }
  524. return 1;
  525. }
  526.  
  527. stock SetCopInvulnerable(cop_id, bool:invulnerable)
  528. {
  529. if(IsCopValid(cop_id))
  530. {
  531. FCNPC_SetInvulnerable(e_cops[cop_id][copid], invulnerable);
  532. return 1;
  533. }
  534. return 0;
  535. }
  536.  
  537. stock bool:IsCopInvulnerable(cop_id)
  538. {
  539. if(IsCopValid(cop_id))
  540. {
  541. return FCNPC_IsInvulnerable(e_cops[cop_id][copid]);
  542. }
  543. return false;
  544. }
  545.  
  546. stock SetCopSkin(cop_id, skinid)
  547. {
  548. if(IsCopValid(cop_id))
  549. {
  550. FCNPC_SetSkin(e_cops[cop_id][copid], skinid);
  551. return 1;
  552. }
  553. return 0;
  554. }
  555.  
  556. stock GetCopSkin(cop_id)
  557. {
  558. if(IsCopValid(cop_id))
  559. {
  560. return FCNPC_GetSkin(e_cops[cop_id][copid]);
  561. }
  562. return -1;
  563. }
  564.  
  565. stock GetCopCustomSkin(cop_id)
  566. {
  567. if(IsCopValid(cop_id))
  568. {
  569. return FCNPC_GetCustomSkin(e_cops[cop_id][copid]);
  570. }
  571. return -1;
  572. }
  573.  
  574. #if defined FILTERSCRIPT
  575.  
  576. public OnFilterScriptExit()
  577. {
  578. DestroyAllCops();
  579.  
  580. #if defined cops_OnFilterScriptExit
  581. return cops_OnFilterScriptExit();
  582. #else
  583. return 1;
  584. #endif
  585. }
  586. #if defined _ALS_OnFilterScriptExit
  587. #undef OnFilterScriptExit
  588. #else
  589. #define _ALS_OnFilterScriptExit
  590. #endif
  591. #define OnFilterScriptExit cops_OnFilterScriptExit
  592. #if defined cops_OnFilterScriptExit
  593. forward cops_OnFilterScriptExit();
  594. #endif
  595.  
  596. #else
  597.  
  598. public OnGameModeExit()
  599. {
  600. DestroyAllCops();
  601.  
  602. #if defined cops_OnGameModeExit
  603. return cops_OnGameModeExit();
  604. #else
  605. return 1;
  606. #endif
  607. }
  608. #if defined _ALS_OnGameModeExit
  609. #undef OnGameModeExit
  610. #else
  611. #define _ALS_OnGameModeExit
  612. #endif
  613. #define OnGameModeExit cops_OnGameModeExit
  614. #if defined cops_OnGameModeExit
  615. forward cops_OnGameModeExit();
  616. #endif
  617.  
  618. #endif
  619.  
  620.  
  621. //EOF.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement