a_rnpc.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /* ARNPC Advanced Recordfree NPC - Created by TheArcher
  2. - Thanks to Mauzen, Joe Staff & Y_Less
  3. -Beta version
  4. */
  5. #include <a_samp>
  6. #include <rnpc>
  7. #if !defined _INC_y_hooks
  8. #include <YSI\y_hooks>
  9. #endif
  10. /* Fake natives
  11. // core
  12. native CreateRNPC(npcname[])
  13. native DestroyRNPC(npcid)
  14. native IsPlayerRNPC(npcid)
  15. native GetRNPCID(npcid)
  16. native GetRNPCState(npcid)
  17. native GetRNPCName(npcid)
  18. // vehicle controls
  19. native PutRNPCInVehicle(npcid, vehicleid, seatid) // not working with 0.2.1 plugin
  20. native RemoveRNPCFromVehicle(npcid) // not working with 0.2.1 plugin
  21. native SetRNPCVehicleSiren(npcid,vstate)
  22. native GetRNPCVehicleSiren(npcid)
  23. // on foot controls
  24. native SetRNPCPos(npcid, Float:x, Float:y, Float:z)
  25. native GetRNPCPos(npcid, &Float:x, &Float:y, &Float:z)
  26. native MoveRNPC(npcid, Float:x, Float:y, Float:z, Float:speed) // taken from the original rnpc include
  27. native SetRNPCFacingAngle(npcid, Float:angle)
  28. native SetRNPCHealth(npcid, health) // remember the health value must be an integer and not working with 0.3 plugin
  29. native GetRNPCHealth(npcid)
  30. native SetRNPCArmour(npcid, armour) // remember the armour value must be an integer and not working with 0.3 plugin
  31. native GetRNPCArmour(npcid)
  32. native SetRNPCWeapon(npcid, weaponid)
  33. native GetRNPCWeapon(npcid)
  34. native SetRNPCSkillLevel(npcid, skill, level)
  35. // npc actions
  36. native RNPCWalkTo(npcid,Float:X,Float:Y,Float:Z);
  37. native RNPCRunTo(npcid,Float:X,Float:Y,Float:Z);
  38. native RNPCSprintTo(npcid,Float:X,Float:Y,Float:Z);
  39. native RNPCAimAt(npcid,Float:X,Float:Y);
  40. native RNPCShotAt(npcid,Float:X,Float:Y);
  41. native RNPCStopUseWeapon(npcid);
  42. native RNPCDriveTo(npcid,Float:X,Float:Y,Float:Z,Float:speed);
  43. native RNPCFollowPlayer(npcid, targetid, movemode = RNPC_SPEED_SPRINT)
  44. // .rec part
  45. native RNPC_StartPlayback(npcid, rec[])
  46. native RNPC_StopPlayback(npcid)
  47. native RNPC_StartBuildPlayback(npcid, slot=0, vehicleid=0)
  48. */
  49. #if !defined MAX_RNPC
  50. #define MAX_RNPC (500) // Be sure that the value is the same as "maxnpc" from server.cfg file
  51. #endif
  52. #define RNPC_STATE_ONFOOT 1
  53. #define RNPC_STATE_DRIVER 2
  54. #define RNPC_STATE_PASSANGER 3 // bugged from the plugin
  55. #define RNPC_FOLLOWING_TIME (300) // rememeber its ms
  56. #define RNPC_SIREN_STATE_ON (1)
  57. #define RNPC_SIREN_STATE_OFF (0)
  58. forward OnRNPCCreated(npcid);
  59. forward OnRNPCDestroyed(npcid);
  60. forward OnRNPCSpawn(npcid);
  61. //forward OnRNPCPlaybackFinished(npcid); // it's usable but already called so DO NOT uncomment this
  62. forward OnRNPCDeath(npcid);
  63. //new bool:RNPC_Connected[MAX_RNPC] = false;
  64. // Here's is sightly Mauzen's include modified, credits goes to him :)
  65. enum RNPC_enum {
  66. bool:RNPC_Connected = false,
  67. RNPC_ID,
  68. RNPC_CONNECTION,
  69. RNPC_NAME[24],
  70. RNPC_SKIN, // Since GetPlayerSkin is not detected on NPC I will do it using this variable and storing a value on it.
  71. RNPC_HEALTH,
  72. RNPC_ARMOUR,
  73. Float:RNPC_ANGLE,
  74. RNPC_WEAPONID,
  75. RNPC_SIREN_STATE
  76. };
  77. // Initial data
  78. new rnpc_Data[MAX_RNPC][RNPC_enum];
  79. stock CreateRNPC(name[])
  80. {
  81. new slot = -1;
  82. for (new i = 0; i < MAX_RNPC; i++) {
  83. if (!IsPlayerConnected(i) && rnpc_Data[i][RNPC_Connected] == false) {
  84. slot = i;
  85. break;
  86. }
  87. }
  88. rnpc_Data[slot][RNPC_CONNECTION] = ConnectNPC(name, "RNPC");
  89. rnpc_Data[slot][RNPC_Connected] = true;
  90. rnpc_Data[slot][RNPC_ID] = slot;
  91. format(rnpc_Data[slot][RNPC_NAME], 24, "%s", name);
  92. SetTimerEx("Fix_RNPCConnect", 450, false, "i", slot); //
  93. return slot;
  94. }
  95. forward Fix_RNPCConnect(npcid);
  96. public Fix_RNPCConnect(npcid) CallLocalFunction("OnRNPCCreated", "i", npcid); // Fixes the issue when the script detects the NPC connected before it does
  97. stock DestroyRNPC(npcid)
  98. {
  99. if(IsPlayerRNPC(npcid)) {
  100. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  101. RNPC_FinishBuild();
  102. RNPC_StartBuildPlayback(npcid);
  103. rnpc_Data[npcid][RNPC_HEALTH] = 0;
  104. rnpc_Data[npcid][RNPC_ARMOUR] = 0;
  105. rnpc_Data[npcid][RNPC_ANGLE] = 0.0;
  106. rnpc_Data[npcid][RNPC_WEAPONID] = 0;
  107. rnpc_Data[npcid][RNPC_SIREN_STATE] = 0;
  108. Kick(rnpc_Data[npcid][RNPC_CONNECTION]);
  109. }
  110. }
  111. //stock IsPlayerRNPC(npcid) return rnpc_Data[npcid][RNPC_Connected] ? true : false;
  112. stock IsPlayerRNPC(npcid)
  113. return (IsPlayerConnected(npcid) && rnpc_Data[npcid][RNPC_Connected] == true && IsPlayerNPC(npcid));
  114. stock GetRNPCID(npcid) return rnpc_Data[npcid][RNPC_ID];
  115. stock GetRNPCState(npcid) {
  116. if(IsPlayerRNPC(npcid)) return GetPlayerState(npcid), \
  117. printf(" ARNPC Debug: npcid %d has the state %d", npcid, GetPlayerState(npcid));
  118. return -1;
  119. }
  120. stock PutRNPCInVehicle(npcid, vehicleid, seatid)
  121. {
  122. if(IsPlayerRNPC(npcid))
  123. SetTimerEx("PutRNPCInVehicle_Fix", 500, 0, "iii", npcid, vehicleid, seatid);
  124. printf(" ARNPC Debug: npcid %d was put in vehicleid %d and seatid %d ", npcid, vehicleid, seatid);
  125. }
  126. stock RemoveRNPCFromVehicle(npcid)
  127. {
  128. if(IsPlayerRNPC(npcid)) {
  129. if(IsPlayerInAnyVehicle(npcid)) {
  130. RemovePlayerFromVehicle(npcid);
  131. }
  132. }
  133. }
  134. forward PutRNPCInVehicle_Fix(npcid, vehicleid, seatid);
  135. public PutRNPCInVehicle_Fix(npcid, vehicleid, seatid) { //Thanks to Mauzen once again :3
  136. // Make him enter the vehicle again, this fixed some problems for me
  137. // when the vehicle is far away and not streamed in for the npc
  138. PutPlayerInVehicle(npcid, vehicleid, seatid);
  139. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
  140. RNPC_AddPause(250);
  141. RNPC_FinishBuild();
  142. RNPC_StartBuildPlayback(npcid);
  143. }
  144. stock SetRNPCPos(npcid, Float:x, Float:y, Float:z)
  145. {
  146. if(IsPlayerRNPC(npcid))
  147. SetPlayerPos(npcid, x,y,z);
  148. }
  149. stock GetRNPCPos(npcid, &Float:x, &Float:y, &Float:z)
  150. {
  151. if((IsPlayerRNPC(npcid)) GetPlayerPos(npcid, x,y,z);
  152. printf(" ARNPC Debug: npcid %d has the pos %f %f %f", npcid, x,y,z);
  153. }
  154. stock SetRNPCSkin(npcid, skin)
  155. {
  156. if(IsPlayerRNPC(npcid))
  157. {
  158. if(IsValidRNPCSkin(skin))
  159. {
  160. new temp_weapon = GetRNPCWeapon(npcid);
  161. if(IsPlayerInAnyVehicle(npcid)) {
  162. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
  163. SetPlayerSkin(npcid, skin);
  164. if(temp_weapon != 0) RNPC_SetWeaponID(temp_weapon);
  165. RNPC_FinishBuild();
  166. } else {
  167. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  168. SetPlayerSkin(npcid, skin);
  169. if(temp_weapon != 0) RNPC_SetWeaponID(temp_weapon);
  170. RNPC_FinishBuild();
  171. }
  172. RNPC_StartBuildPlayback(npcid);
  173. rnpc_Data[npcid][RNPC_SKIN] = skin;
  174. }
  175. }
  176. }
  177. stock GetRNPCSkin(npcid) return rnpc_Data[npcid][RNPC_SKIN];
  178. stock SetRNPCFacingAngle(npcid,Float:angle)
  179. {
  180. if(IsPlayerRNPC(npcid))
  181. {
  182. if(IsPlayerInAnyVehicle(npcid)) return false; // prevent unusable angle facing in vehicles
  183. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  184. RNPC_SetAngleQuats(0.0, angle, 0.0);
  185. RNPC_FinishBuild();
  186. RNPC_StartBuildPlayback(npcid);
  187. rnpc_Data[npcid][RNPC_ANGLE] = angle;
  188. printf(" ARNPC Debug: NPCID %d has set the angle %f ", npcid, angle);
  189. }
  190. return true;
  191. }
  192. stock Float:GetNPCFacingAngle(npcid) // not working well yet
  193. {
  194. if(rnpc_Data[npcid][RNPC_Connected] == true)
  195. return rnpc_Data[npcid][RNPC_ANGLE];
  196. //printf(" ARNPC Debug: NPCID %d has set the angle %f ", npcid, GetNPCFacingAngle(npcid));
  197. return 0.0;
  198. }
  199. // Took from a pastebin link (Idk who's original author :/ )
  200. stock IsValidRNPCSkin(skinid)
  201. {
  202. #define MAX_BAD_SKINS 22
  203. new badSkins[MAX_BAD_SKINS] =
  204. {
  205. 3, 4, 5, 6, 8, 42, 65, 74, 86,
  206. 119, 149, 208, 265, 266, 267,
  207. 268, 269, 270, 271, 272, 273, 289
  208. };
  209. if (skinid < 0 || skinid > 299) return false;
  210. for (new i = 0; i < MAX_BAD_SKINS; i++)
  211. {
  212. if (skinid == badSkins[i]) return false;
  213. }
  214. #undef MAX_BAD_SKINS
  215. return 1;
  216. }
  217. stock GetRNPCName(npcid) // Thanks to Lorenc_
  218. {
  219. static p_Name[24] = "Invalid_NPC_ID";
  220. format(p_Name, 24, "%s", rnpc_Data[npcid][RNPC_NAME]);
  221. return p_Name;
  222. }
  223. stock GetRNPCSurfingVehicle(npcid) // I just tried something but lol not working.
  224. {
  225. if(IsPlayerRNPC(npcid)) return GetPlayerSurfingVehicleID(npcid);
  226. return INVALID_PLAYER_ID;
  227. }
  228. stock SetRNPCHealth(npcid, hp) // Float is not support yet by rnpc plugin native yet
  229. {
  230. if(IsPlayerRNPC(npcid))
  231. {
  232. RNPC_StopPlayback(npcid);
  233. new State = GetRNPCState(npcid);
  234. if(State == RNPC_STATE_ONFOOT)
  235. {
  236. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  237. RNPC_SetHealth(hp);
  238. RNPC_FinishBuild();
  239. if(hp <= 0) CallLocalFunction("OnRNPCDeath", "i", npcid);
  240. }
  241. else
  242. if(State == RNPC_STATE_DRIVER || RNPC_STATE_PASSANGER)
  243. {
  244. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
  245. RNPC_SetDriverHealth(hp);
  246. RNPC_FinishBuild();
  247. if(hp <= 0) CallLocalFunction("OnRNPCDeath", "i", npcid);
  248. }
  249. rnpc_Data[npcid][RNPC_HEALTH] = hp;
  250. RNPC_StartBuildPlayback(npcid);
  251. }
  252. }
  253. stock SetRNPCArmour(npcid, armour) // Float is not support yet by rnpc plugin native yet
  254. {
  255. if(IsPlayerRNPC(npcid))
  256. {
  257. RNPC_StopPlayback(npcid);
  258. new State = GetRNPCState(npcid);
  259. if(State == RNPC_STATE_ONFOOT)
  260. {
  261. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  262. RNPC_SetArmour(armour);
  263. RNPC_FinishBuild();
  264. }
  265. else
  266. if(State == RNPC_STATE_DRIVER || RNPC_STATE_PASSANGER)
  267. {
  268. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
  269. RNPC_SetArmour(armour);
  270. RNPC_FinishBuild();
  271. }
  272. rnpc_Data[npcid][RNPC_ARMOUR] = armour;
  273. RNPC_StartBuildPlayback(npcid);
  274. }
  275. }
  276. stock GetRNPCHealth(npcid) return rnpc_Data[npcid][RNPC_HEALTH];
  277. stock GetRNPCArmour(npcid) return rnpc_Data[npcid][RNPC_ARMOUR];
  278. stock SetRNPCWeapon(npcid, weaponid)
  279. {
  280. if(IsPlayerRNPC(npcid))
  281. {
  282. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  283. RNPC_SetWeaponID(weaponid);
  284. RNPC_FinishBuild();
  285. RNPC_StartBuildPlayback(npcid);
  286. rnpc_Data[npcid][RNPC_WEAPONID] = weaponid;
  287. }
  288. }
  289. stock GetRNPCWeapon(npcid) return rnpc_Data[npcid][RNPC_WEAPONID];
  290. stock RNPCWalkTo(npcid,Float:X,Float:Y,Float:Z)
  291. {
  292. if(IsPlayerRNPC(npcid))
  293. {
  294. new Float:SPos[3];
  295. GetPlayerPos(npcid, SPos[0], SPos[1], SPos[2]);
  296. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  297. if(GetRNPCWeapon(npcid) != 0) RNPC_SetWeaponID(GetRNPCWeapon(npcid));
  298. RNPC_AddMovement(SPos[0], SPos[1], SPos[2], X, Y, Z, RNPC_SPEED_WALK);
  299. RNPC_FinishBuild();
  300. RNPC_StartBuildPlayback(npcid);
  301. }
  302. }
  303. stock RNPCRunTo(npcid,Float:X,Float:Y,Float:Z)
  304. {
  305. if(IsPlayerRNPC(npcid))
  306. {
  307. new Float:SPos[3];
  308. GetPlayerPos(npcid, SPos[0], SPos[1], SPos[2]);
  309. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  310. if(GetRNPCWeapon(npcid) != 0) RNPC_SetWeaponID(GetRNPCWeapon(npcid));
  311. RNPC_AddMovement(SPos[0], SPos[1], SPos[2], X, Y, Z, RNPC_SPEED_RUN);
  312. RNPC_FinishBuild();
  313. RNPC_StartBuildPlayback(npcid);
  314. }
  315. }
  316. stock RNPCSprintTo(npcid,Float:X,Float:Y,Float:Z)
  317. {
  318. if(IsPlayerRNPC(npcid))
  319. {
  320. new Float:SPos[3];
  321. GetPlayerPos(npcid, SPos[0], SPos[1], SPos[2]);
  322. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  323. if(GetRNPCWeapon(npcid) != 0) RNPC_SetWeaponID(GetRNPCWeapon(npcid));
  324. RNPC_AddMovement(SPos[0], SPos[1], SPos[2], X, Y, Z, RNPC_SPEED_SPRINT);
  325. RNPC_FinishBuild();
  326. RNPC_StartBuildPlayback(npcid);
  327. }
  328. }
  329. stock RNPCFollowPlayer(npcid, targetid, Float:movemode = RNPC_SPEED_SPRINT)
  330. {
  331. if(IsPlayerRNPC(npcid)) SetTimerEx("FollowPlayer", RNPC_FOLLOWING_TIME, true, "iif", npcid, targetid, movemode);
  332. }
  333. forward FollowPlayer(npcid, targetid, Float:movemode);
  334. public FollowPlayer(npcid, targetid, Float:movemode)
  335. {
  336. static Float:x, Float:y, Float:z;
  337. GetPlayerPos(targetid, x, y, z);
  338. switch(movemode)
  339. {
  340. case RNPC_SPEED_SPRINT: MoveRNPC(npcid, x, y, z, RNPC_SPEED_SPRINT);
  341. case RNPC_SPEED_RUN: MoveRNPC(npcid, x, y, z, RNPC_SPEED_RUN);
  342. case RNPC_SPEED_WALK: MoveRNPC(npcid, x, y, z, RNPC_SPEED_WALK);
  343. }
  344. }
  345. stock SetRNPCSkillLevel(npcid, skill, level)
  346. {
  347. if(IsPlayerRNPC(npcid))
  348. SetPlayerSkillLevel(npcid, skill, level);
  349. }
  350. stock SetRNPCVehicleSiren(npcid,vstate)
  351. {
  352. if(IsPlayerRNPC(npcid))
  353. {
  354. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
  355. switch(vstate) {
  356. case RNPC_SIREN_STATE_OFF: RNPC_SetSirenState(RNPC_SIREN_STATE_OFF), rnpc_Data[npcid][RNPC_SIREN_STATE] = 0;
  357. case RNPC_SIREN_STATE_ON: RNPC_SetSirenState(RNPC_SIREN_STATE_ON), rnpc_Data[npcid][RNPC_SIREN_STATE] = 1;
  358. }
  359. RNPC_FinishBuild();
  360. RNPC_StartBuildPlayback(npcid);
  361. }
  362. }
  363. stock GetRNPCVehicleSiren(npcid) return rnpc_Data[npcid][RNPC_SIREN_STATE];
  364. stock RNPCShotAt(npcid, Float:x, Float:y)
  365. {
  366. if(IsPlayerRNPC(npcid))
  367. {
  368. if(GetRNPCWeapon(npcid) != 0) {
  369. new Float:ox, Float:oy, Float:oz;
  370. GetPlayerPos(npcid, ox, oy, oz);
  371. new Float:angle = atan2(ox - x, oy - y) + randomNums(175, 180);
  372. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  373. RNPC_SetWeaponID(GetRNPCWeapon(npcid));
  374. RNPC_SetAngleQuats(0.0, angle, 0.0);
  375. RNPC_SetKeys(KEY_FIRE);
  376. RNPC_FinishBuild();
  377. RNPC_StartBuildPlayback(npcid);
  378. }
  379. }
  380. }
  381. stock RNPCAimAt(npcid, Float:x, Float:y)
  382. {
  383. if(IsPlayerRNPC(npcid))
  384. {
  385. if(GetRNPCWeapon(npcid) != 0) {
  386. new Float:ox, Float:oy, Float:oz;
  387. GetPlayerPos(npcid, ox, oy, oz);
  388. new Float:angle = atan2(ox - x, oy - y) + 177.0;
  389. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  390. RNPC_SetWeaponID(GetRNPCWeapon(npcid));
  391. RNPC_SetAngleQuats(0.0, angle, 0.0);
  392. RNPC_SetKeys(128);
  393. RNPC_FinishBuild();
  394. RNPC_StartBuildPlayback(npcid);
  395. }
  396. }
  397. }
  398. stock RNPCStopUseWeapon(npcid)
  399. {
  400. if(IsPlayerRNPC(npcid))
  401. {
  402. RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  403. RNPC_SetWeaponID(GetRNPCWeapon(npcid));
  404. RNPC_SetKeys(0);
  405. RNPC_FinishBuild();
  406. RNPC_StartBuildPlayback(npcid);
  407. }
  408. }
  409. // extra functions
  410. // Thanks Y_Less :)
  411. stock randomNums(min, max)
  412. {
  413. new rand = random(max-min)+min;
  414. return rand;
  415. }
  416. //took SuperViper version
  417. stock Float: GetDistanceBetweenRNPC(p1, p2)
  418. {
  419. new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  420. GetPlayerPos(p1,x1,y1,z1);
  421. GetPlayerPos(p2,x2,y2,z2);
  422. return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  423. }
  424. // sightly modify version of JernejL
  425. stock Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ)
  426. {
  427. new Float:TGTDistance;
  428. // get distance from camera to target
  429. TGTDistance = sqrt((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
  430. new Float:tmpX, Float:tmpY, Float:tmpZ;
  431. tmpX = FrX * TGTDistance + CamX;
  432. tmpY = FrY * TGTDistance + CamY;
  433. tmpZ = FrZ * TGTDistance + CamZ;
  434. return sqrt((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
  435. }
  436. //Hooking part
  437. forward OnPlayerConnect_Fix(playerid);
  438. public OnPlayerConnect_Fix(playerid)
  439. {
  440. RNPC_CreateBuild(playerid, PLAYER_RECORDING_TYPE_ONFOOT);
  441. RNPC_SetHealth(100);
  442. RNPC_SetArmour(100);
  443. RNPC_SetAngleQuats(0.0, 90.0, 0.0);
  444. RNPC_FinishBuild();
  445. RNPC_StartBuildPlayback(playerid);
  446. rnpc_Data[playerid][RNPC_HEALTH] = 100;
  447. rnpc_Data[playerid][RNPC_ARMOUR] = 100;
  448. rnpc_Data[playerid][RNPC_ANGLE] = 90.0;
  449. rnpc_Data[playerid][RNPC_WEAPONID] = 0;
  450. rnpc_Data[playerid][RNPC_SIREN_STATE] = 0;
  451. }
  452. //Fix the bug if the NPC is going to disconnect somehow
  453. hook: public OnPlayerConnect(playerid)
  454. {
  455. if(!IsPlayerRNPC(playerid)) return 0;
  456. SetTimerEx("OnPlayerConnect_Fix", 500, 0, "i", playerid);
  457. printf(" OnPlayerConnect hook has called ");
  458. return 1;
  459. }
  460. hook: public OnPlayerDisconnect(playerid, reason)
  461. {
  462. if(IsPlayerRNPC(playerid))
  463. {
  464. rnpc_Data[playerid][RNPC_Connected] = false;
  465. rnpc_Data[playerid][RNPC_HEALTH] = 0;
  466. rnpc_Data[playerid][RNPC_ARMOUR] = 0;
  467. rnpc_Data[playerid][RNPC_ANGLE] = 0.0;
  468. rnpc_Data[playerid][RNPC_WEAPONID] = 0;
  469. CallLocalFunction("OnRNPCDestroyed", "i", playerid);
  470. }
  471. print(" ARNPC Debug: OnPlayerDisconnect hook called for NPC");
  472. }
  473. hook: public OnPlayerSpawn(playerid)
  474. {
  475. if(IsPlayerRNPC(playerid)) CallLocalFunction("OnRNPCSpawn", "i", playerid);
  476. print(" ARNPC Debug: OnPlayerSpawn hook called");
  477. }
  478. // Not fully tested yet.
  479. hook: public OnRconCommand(cmd[])
  480. {
  481. if(strfind(cmd,"gmx",true) != -1)
  482. {
  483. for(new i = 0; i < MAX_RNPC; i++)
  484. {
  485. if(!IsPlayerRNPC(i)) continue;
  486. DestroyRNPC(i);
  487. }
  488. }
  489. return 0;
  490. }