traindrivers_pilots.pwn 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* ---------------------------------
  2. FCNPC Plugin traindrivers_pilots FS
  3. - File: traindrivers_pilots.pwn
  4. - Author: Freaksken
  5. - Description: converts the 3 traindriver NPCs and 3 pilot NPCs from the gl_npcs script to FCNPCs
  6. - Files: train_ls_to_sf.rec, train_sf_to_lv.rec, train_lv_to_ls.rec, at400_ls_to_lv.rec, at400_sf_to_ls.rec, at400_lv_to_sf.rec
  7. - Author: Kalcor
  8. - Description: the recording files needed for playback
  9. ---------------------------------*/
  10. #define FILTERSCRIPT
  11. #include <a_samp>
  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. #tryinclude "../FCNPC"
  20. #endif
  21. #if !defined _FCNPC_included
  22. #error Add FCNPC.inc to your scripts directory
  23. #endif
  24. #define COLOR_STANDARD_NPC 0xffffffff
  25. #define MAX_STANDARD_NPC_TRAINDRIVERS 3
  26. #define MAX_STANDARD_NPC_PILOTS 3
  27. new TrainDriverVehicles[MAX_STANDARD_NPC_TRAINDRIVERS] = {INVALID_VEHICLE_ID, ...};
  28. new PilotVehicles[MAX_STANDARD_NPC_PILOTS] = {INVALID_VEHICLE_ID, ...};
  29. new TrainDriverNPCs[MAX_STANDARD_NPC_TRAINDRIVERS] = {INVALID_PLAYER_ID, ...};
  30. new PilotNPCs[MAX_STANDARD_NPC_PILOTS] = {INVALID_PLAYER_ID, ...};
  31. new TrainDriverPlaybackCycle[MAX_STANDARD_NPC_TRAINDRIVERS] = {0, ...};
  32. new PilotPlaybackCycle[MAX_STANDARD_NPC_PILOTS] = {0, ...};
  33. #if defined FILTERSCRIPT
  34. public OnFilterScriptInit()
  35. {
  36. TrainDriverVehicles[0] = AddStaticVehicleEx(537, 1462.0745, 2630.8787, 10.8203, 270.0, -1, -1, 0); // freight
  37. TrainDriverVehicles[1] = AddStaticVehicleEx(537, -1942.7950, 168.4164, 27.0006, 270.0, -1, -1, 0); // freight
  38. TrainDriverVehicles[2] = AddStaticVehicleEx(537, 1700.7551, -1953.6531, 14.8756, 270.0, -1, -1, 0); // freight
  39. TrainDriverNPCs[0] = FCNPC_Create("TrainDriverLS");
  40. TrainDriverNPCs[1] = FCNPC_Create("TrainDriverSF");
  41. TrainDriverNPCs[2] = FCNPC_Create("TrainDriverLV");
  42. for(new traindriver = 0; traindriver < MAX_STANDARD_NPC_TRAINDRIVERS; traindriver++) {
  43. if(TrainDriverNPCs[traindriver] != INVALID_PLAYER_ID && TrainDriverVehicles[traindriver] != INVALID_VEHICLE_ID) {
  44. FCNPC_Spawn(TrainDriverNPCs[traindriver], 255, 0.0, 0.0, 0.0);
  45. //SetPlayerTeam(TrainDriverNPCs[traindriver], 69);
  46. FCNPC_SetInvulnerable(TrainDriverNPCs[traindriver], true);
  47. SetPlayerColor(TrainDriverNPCs[traindriver], COLOR_STANDARD_NPC);
  48. FCNPC_PutInVehicle(TrainDriverNPCs[traindriver], TrainDriverVehicles[traindriver], 0);
  49. TrainDriverPlaybackCycle[traindriver] = traindriver;
  50. TrainDriverNextPlayback(traindriver);
  51. }
  52. }
  53. PilotVehicles[0] = AddStaticVehicleEx(577, 0.0, 0.0, 0.0, 315.1902, -1, -1, 0); // at400
  54. PilotVehicles[1] = AddStaticVehicleEx(577, 0.0, 0.0, 0.0, 315.1902, -1, -1, 0); // at400
  55. PilotVehicles[2] = AddStaticVehicleEx(577, 0.0, 0.0, 0.0, 315.1902, -1, -1, 0); // at400
  56. PilotNPCs[0] = FCNPC_Create("PilotLS");
  57. PilotNPCs[1] = FCNPC_Create("PilotSF");
  58. PilotNPCs[2] = FCNPC_Create("PilotLV");
  59. for(new pilot = 0; pilot < MAX_STANDARD_NPC_PILOTS; pilot++) {
  60. if(PilotNPCs[pilot] != INVALID_PLAYER_ID && PilotVehicles[pilot] != INVALID_VEHICLE_ID) {
  61. FCNPC_Spawn(PilotNPCs[pilot], 61, 0.0, 0.0, 0.0);
  62. //SetPlayerTeam(PilotNPCs[pilot], 69);
  63. FCNPC_SetInvulnerable(PilotNPCs[pilot], true);
  64. SetPlayerColor(PilotNPCs[pilot], COLOR_STANDARD_NPC);
  65. FCNPC_PutInVehicle(PilotNPCs[pilot], PilotVehicles[pilot], 0);
  66. PilotPlaybackCycle[pilot] = pilot;
  67. PilotNextPlayback(pilot);
  68. }
  69. }
  70. return 1;
  71. }
  72. public OnFilterScriptExit()
  73. {
  74. for(new traindriver = 0; traindriver < MAX_STANDARD_NPC_TRAINDRIVERS; traindriver++) {
  75. FCNPC_StopPlayingPlayback(TrainDriverVehicles[traindriver]);
  76. DestroyVehicle(TrainDriverVehicles[traindriver]);
  77. TrainDriverVehicles[traindriver] = INVALID_VEHICLE_ID;
  78. FCNPC_Destroy(TrainDriverNPCs[traindriver]);
  79. TrainDriverNPCs[traindriver] = INVALID_PLAYER_ID;
  80. TrainDriverPlaybackCycle[traindriver] = 0;
  81. }
  82. for(new pilot = 0; pilot < MAX_STANDARD_NPC_PILOTS; pilot++) {
  83. FCNPC_StopPlayingPlayback(PilotNPCs[pilot]);
  84. DestroyVehicle(PilotVehicles[pilot]);
  85. PilotVehicles[pilot] = INVALID_VEHICLE_ID;
  86. FCNPC_Destroy(PilotNPCs[pilot]);
  87. PilotNPCs[pilot] = INVALID_PLAYER_ID;
  88. PilotPlaybackCycle[pilot] = 0;
  89. }
  90. return 1;
  91. }
  92. #endif
  93. public OnPlayerConnect(playerid)
  94. {
  95. //IMPORTANT:
  96. //This restricts NPCs connecting from an IP address outside this server.
  97. //If you need to connect NPCs externally you will need to modify the code in this callback.
  98. /*if(IsPlayerNPC(playerid)) {
  99. new ip_addr_npc[64 + 1];
  100. new ip_addr_server[64 + 1];
  101. GetServerVarAsString("bind", ip_addr_server, sizeof(ip_addr_server));
  102. GetPlayerIp(playerid, ip_addr_npc, sizeof(ip_addr_npc));
  103. if(!strlen(ip_addr_server)) {
  104. ip_addr_server = "127.0.0.1";
  105. }
  106. if(strcmp(ip_addr_npc, ip_addr_server, true) && strcmp(npcIP, "255.255.255.255", true)) { //255.255.255.255 happens with FCNPC on gmx
  107. printf("NPC: Got a remote NPC connecting from %s and I'm kicking it.", ip_addr_npc);
  108. Kick(playerid);
  109. return 0;
  110. }
  111. printf("NPC: Connection from %s is allowed.", ip_addr_npc);
  112. }*/
  113. return 1;
  114. }
  115. public FCNPC_OnFinishPlayback(npcid)
  116. {
  117. for(new traindriver = 0; traindriver < MAX_STANDARD_NPC_TRAINDRIVERS; traindriver++) {
  118. if(npcid == TrainDriverNPCs[traindriver]) {
  119. TrainDriverNextPlayback(traindriver);
  120. break;
  121. }
  122. }
  123. for(new pilot = 0; pilot < MAX_STANDARD_NPC_PILOTS; pilot++) {
  124. if(npcid == PilotNPCs[pilot]) {
  125. PilotNextPlayback(pilot);
  126. break;
  127. }
  128. }
  129. return 1;
  130. }
  131. public FCNPC_OnVehicleTakeDamage(npcid, issuerid, vehicleid, Float:amount, weaponid, Float:fX, Float:fY, Float:fZ)
  132. {
  133. for(new traindriver = 0; traindriver < MAX_STANDARD_NPC_TRAINDRIVERS; traindriver++) {
  134. if(npcid == TrainDriverNPCs[traindriver]) {
  135. return 0;
  136. }
  137. }
  138. for(new pilot = 0; pilot < MAX_STANDARD_NPC_PILOTS; pilot++) {
  139. if(npcid == PilotNPCs[pilot]) {
  140. return 0;
  141. }
  142. }
  143. return 1;
  144. }
  145. TrainDriverNextPlayback(index) {
  146. switch(TrainDriverPlaybackCycle[index]) {
  147. case 0: {
  148. FCNPC_StartPlayingPlayback(TrainDriverNPCs[index], "train_ls_to_sf");
  149. }
  150. case 1: {
  151. FCNPC_StartPlayingPlayback(TrainDriverNPCs[index], "train_sf_to_lv");
  152. }
  153. case 2: {
  154. FCNPC_StartPlayingPlayback(TrainDriverNPCs[index], "train_lv_to_ls");
  155. }
  156. }
  157. TrainDriverPlaybackCycle[index]++;
  158. if(TrainDriverPlaybackCycle[index] == 3) {
  159. TrainDriverPlaybackCycle[index] = 0;
  160. }
  161. }
  162. PilotNextPlayback(index) {
  163. switch(PilotPlaybackCycle[index]) {
  164. case 0: {
  165. FCNPC_StartPlayingPlayback(PilotNPCs[index], "at400_ls_to_lv");
  166. }
  167. case 1: {
  168. FCNPC_StartPlayingPlayback(PilotNPCs[index], "at400_lv_to_sf");
  169. }
  170. case 2: {
  171. FCNPC_StartPlayingPlayback(PilotNPCs[index], "at400_sf_to_ls");
  172. }
  173. }
  174. PilotPlaybackCycle[index]++;
  175. if(PilotPlaybackCycle[index] == 3) {
  176. PilotPlaybackCycle[index] = 0;
  177. }
  178. }