sample.pwn 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* ---------------------------------
  2. FCNPC Plugin sample FS
  3. - File: sample.pwn
  4. - Author: OrMisicL
  5. - Contributor: ziggi
  6. ---------------------------------*/
  7. #define FILTERSCRIPT
  8. #include <a_samp>
  9. #if !defined _FCNPC_included
  10. #tryinclude <FCNPC>
  11. #endif
  12. #if !defined _FCNPC_included
  13. #tryinclude "FCNPC"
  14. #endif
  15. #if !defined _FCNPC_included
  16. #tryinclude "../FCNPC"
  17. #endif
  18. #if !defined _FCNPC_included
  19. #error Add FCNPC.inc to your scripts directory
  20. #endif
  21. #define START_NPCS 25
  22. forward CreateNPC();
  23. forward DestroyNPC(npcid);
  24. enum E_NPC {
  25. bool:E_VALID,
  26. E_MOVE_STAGE,
  27. };
  28. new gNpc[MAX_PLAYERS][E_NPC];
  29. new Float:gSpawns[][3] = {
  30. {1697.2258, -1706.5187, 13.5419}
  31. };
  32. new Float:gMovements[][3] = {
  33. {1697.7418, -1600.1525, 13.5469},
  34. {1797.9518, -1619.9912, 13.5469},
  35. {1814.1798, -1645.9603, 13.5469},
  36. {1815.2373, -1724.6650, 13.5469},
  37. {1696.7618, -1725.9985, 13.5469}
  38. };
  39. new gNpcCount;
  40. public OnFilterScriptInit()
  41. {
  42. // Create NPCs
  43. for (new i = 0; i < START_NPCS; i++) {
  44. SetTimer("CreateNPC", 3000 * i + random(10000), 0);
  45. }
  46. return 1;
  47. }
  48. public CreateNPC()
  49. {
  50. new name[MAX_PLAYER_NAME + 1];
  51. format(name, sizeof(name), "NPC_%d", gNpcCount);
  52. new npcid = FCNPC_Create(name);
  53. gNpc[npcid][E_MOVE_STAGE] = 0;
  54. gNpc[npcid][E_VALID] = true;
  55. FCNPC_Spawn(npcid, random(312), gSpawns[0][0], gSpawns[0][1], gSpawns[0][2]);
  56. gNpcCount++;
  57. }
  58. stock MoveNPC(npcid)
  59. {
  60. new mstage = gNpc[npcid][E_MOVE_STAGE];
  61. FCNPC_GoTo(npcid, gMovements[mstage][0], gMovements[mstage][1], gMovements[mstage][2], FCNPC_MOVE_TYPE_RUN);
  62. }
  63. public FCNPC_OnDeath(npcid, killerid, reason)
  64. {
  65. if (!gNpc[npcid][E_VALID]) {
  66. return 1;
  67. }
  68. new name[MAX_PLAYER_NAME + 1];
  69. GetPlayerName(killerid, name, sizeof(name));
  70. new msg[144];
  71. format(msg, sizeof(msg), "NPC %d was killed by %d (%s) with weapon %d", npcid, killerid, name, reason);
  72. SendClientMessageToAll(0xFF00FF00, msg);
  73. SetTimerEx("DestroyNPC", 2000, 0, "i", npcid);
  74. return 1;
  75. }
  76. public DestroyNPC(npcid)
  77. {
  78. FCNPC_Destroy(npcid);
  79. gNpc[npcid][E_VALID] = false;
  80. }
  81. public FCNPC_OnSpawn(npcid)
  82. {
  83. if (!gNpc[npcid][E_VALID]) {
  84. return 1;
  85. }
  86. // Give him some weapons and ammo
  87. FCNPC_SetWeapon(npcid, random(11) + 22);
  88. FCNPC_SetAmmo(npcid, 500);
  89. // Move the NPC
  90. MoveNPC(npcid);
  91. return 1;
  92. }
  93. public FCNPC_OnReachDestination(npcid)
  94. {
  95. if (!gNpc[npcid][E_VALID]) {
  96. return 1;
  97. }
  98. // Increase the moving stage
  99. gNpc[npcid][E_MOVE_STAGE]++;
  100. if (gNpc[npcid][E_MOVE_STAGE] >= sizeof(gMovements)) {
  101. gNpc[npcid][E_MOVE_STAGE] = 0;
  102. }
  103. MoveNPC(npcid);
  104. return 1;
  105. }
  106. public OnRconCommand(cmd[])
  107. {
  108. if (!strcmp(cmd, "npc", true)) {
  109. CreateNPC();
  110. }
  111. return 1;
  112. }