citiziens.pwn 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* ---------------------------------
  2. FCNPC Plugin Sample FS
  3. - File: FCNPC.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 COLOR_GREY 0xAFAFAFAA
  22. #define COLOR_RED 0xB35959AA
  23. #define LOS_SANTOS
  24. forward Float:frandom(Float:max);
  25. new
  26. gMaxCitiziens,
  27. gCitizienID[MAX_PLAYERS] = {INVALID_PLAYER_ID, ...},
  28. gCars[] = {
  29. 401, 402, 404, 405, 409, 410, 411, 412, 415, 419, 420, 421, 426, 429,
  30. 434, 436, 438, 439, 442, 445, 451, 458, 466, 467, 474, 475, 477, 479,
  31. 480, 491, 492, 496, 506, 507, 516, 517, 518, 526, 527, 529, 533, 534,
  32. 535, 536, 540, 541, 542, 545, 546, 547, 549, 550, 551, 555, 558, 559,
  33. 560, 561, 562, 565, 566, 567, 575, 576, 580, 585, 587, 589, 596, 597,
  34. 598, 600, 602, 603
  35. };
  36. public OnFilterScriptInit()
  37. {
  38. printf("");
  39. printf("-------------------------------------------------");
  40. printf(" FCNPC - Fully Customizable NPC citiziens FS");
  41. printf("");
  42. printf("- Author: OrMisicL");
  43. printf("- Contributor: ziggi");
  44. printf("-------------------------------------------------");
  45. printf("");
  46. //
  47. gMaxCitiziens = GetConsoleVarAsInt("maxnpc");
  48. // Set the update rate
  49. FCNPC_SetUpdateRate(80);
  50. // Open all nodes
  51. for (new i = 0; i < MAX_NODES; i++) {
  52. if (!FCNPC_IsNodeOpen(i) && !FCNPC_OpenNode(i)) {
  53. printf("Error: Failed to open node %d from (scriptfiles/FCNPC/nodes/NODES%d.DAT)", i, i);
  54. return 0;
  55. }
  56. }
  57. // Create all the citiziens
  58. new
  59. name[MAX_PLAYER_NAME + 1],
  60. npcid,
  61. nodeid,
  62. point,
  63. Float:x, Float:y, Float:z,
  64. vehicleid,
  65. vehnodes, pednodes, navinodes;
  66. for (new i = 0; i < gMaxCitiziens; i++) {
  67. // Generate the citizien name
  68. format(name, sizeof(name), "citizien_%d", i + 1);
  69. // Create and spawn the NPC
  70. npcid = FCNPC_Create(name);
  71. if (npcid == INVALID_PLAYER_ID) {
  72. printf("Warning: Failed to create NPC ID %d (%s)", i, name);
  73. continue;
  74. }
  75. gCitizienID[i] = npcid;
  76. FCNPC_Spawn(npcid, random(299), 0, 0, 0);
  77. // Generate a random nodeid
  78. do {
  79. nodeid = random(MAX_NODES);
  80. } while (!IsValidZone(nodeid));
  81. // Get the nodeid info
  82. FCNPC_GetNodeInfo(nodeid, vehnodes, pednodes, navinodes);
  83. // Randomize type of path
  84. if (random(2) == 1 && pednodes != 0) {
  85. point = random(pednodes - 1) + vehnodes + 1;
  86. FCNPC_SetNodePoint(nodeid, point);
  87. FCNPC_PlayNode(npcid, nodeid, MOVE_TYPE_WALK, .UseMapAndreas = true);
  88. } else {
  89. point = random(vehnodes - 1);
  90. FCNPC_SetNodePoint(nodeid, point);
  91. FCNPC_GetNodePointPosition(nodeid, x, y, z);
  92. vehicleid = CreateVehicle(GetRandomCarModel(), x, y, z, 0, -1, -1, 1);
  93. FCNPC_PutInVehicle(npcid, vehicleid, 0);
  94. FCNPC_PlayNode(npcid, nodeid, .UseMapAndreas = true, .speed = 1.0 + frandom(1.0));
  95. }
  96. }
  97. return 1;
  98. }
  99. public OnFilterScriptExit()
  100. {
  101. // Delete all NPCs
  102. new vehicleid;
  103. for (new i = 0; i < MAX_PLAYERS; i++) {
  104. if (gCitizienID[i] != INVALID_PLAYER_ID) {
  105. vehicleid = FCNPC_GetVehicleID(gCitizienID[i]);
  106. if (vehicleid != 0) {
  107. DestroyVehicle(vehicleid);
  108. }
  109. FCNPC_Destroy(gCitizienID[i]);
  110. gCitizienID[i] = INVALID_PLAYER_ID;
  111. }
  112. }
  113. // Close all nodes
  114. for (new i = 0; i < MAX_NODES; i++) {
  115. if (FCNPC_IsNodeOpen(i)) {
  116. FCNPC_CloseNode(i);
  117. }
  118. }
  119. return 1;
  120. }
  121. public OnPlayerCommandText(playerid, cmdtext[])
  122. {
  123. // Test command
  124. if (strcmp(cmdtext, "/citizien", true, 9) == 0) {
  125. new
  126. param[4],
  127. npcid;
  128. strmid(param, cmdtext, 10, strlen(cmdtext));
  129. if (strlen(param) == 0) {
  130. SendClientMessage(playerid, 0xB35959AA, "Usage: /citizien <ID>");
  131. return 1;
  132. }
  133. npcid = strval(param);
  134. if (!FCNPC_IsValid(npcid)) {
  135. SendClientMessage(playerid, 0xB35959AA, "Invalid citizien ID");
  136. return 1;
  137. }
  138. new Float:x, Float:y, Float:z;
  139. FCNPC_GetPosition(npcid, x, y, z);
  140. SetPlayerPos(playerid, x + 4, y + 4, z);
  141. return 1;
  142. }
  143. if (strcmp(cmdtext, "/pause", true, 6) == 0) {
  144. for (new i = 0; i < MAX_PLAYERS; i++) {
  145. if (gCitizienID[i] != INVALID_PLAYER_ID) {
  146. FCNPC_PausePlayingNode(gCitizienID[i]);
  147. }
  148. }
  149. return 1;
  150. }
  151. if (strcmp(cmdtext, "/resume", true, 7) == 0) {
  152. for (new i = 0; i < MAX_PLAYERS; i++) {
  153. if (gCitizienID[i] != INVALID_PLAYER_ID) {
  154. FCNPC_ResumePlayingNode(gCitizienID[i]);
  155. }
  156. }
  157. return 1;
  158. }
  159. return 0;
  160. }
  161. public FCNPC_OnChangeNode(npcid, nodeid)
  162. {
  163. // Validate the node zone
  164. return IsValidZone(nodeid) ? 1 : 0;
  165. }
  166. stock GetRandomCarModel()
  167. {
  168. return gCars[ random( sizeof(gCars) ) ];
  169. }
  170. stock IsValidZone(zoneid)
  171. {
  172. #if defined SAN_ANDREAS
  173. return zoneid > 0 && zoneid < MAX_NODES;
  174. #elseif defined LOS_SANTOS
  175. return (zoneid >= 5 && zoneid <= 7) || (zoneid >= 12 && zoneid <= 15) || (zoneid >= 20 && zoneid <= 23);
  176. #elseif defined SAN_FIERRO
  177. return zoneid == 17 || (zoneid >= 24 && zoneid <= 26) || (zoneid >= 32 && zoneid <= 24) || (zoneid >= 40 && zoneid <= 41);
  178. #elseif defined LAS_VENTURAS
  179. return (zoneid >= 38 && zoneid <= 39) || (zoneid >= 45 && zoneid <= 47) || (zoneid >= 53 && zoneid <= 55) || (zoneid >= 61 && zoneid <= 63);
  180. #else
  181. return false;
  182. #endif
  183. }
  184. stock Float:frandom(Float:max)
  185. {
  186. return floatdiv(float(random(0)), floatdiv(float(cellmax), max));
  187. }