Advertisement
Guest User

RNPC 0.4.1 - PathFinder Fix

a guest
Apr 23rd, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.14 KB | None | 0 0
  1. /**
  2. * RNPC - Recordfile NPCs
  3. * Version 0.4.1
  4. * made by Mauzen
  5. */
  6. #define RNPC_VERSION "0.4.1"
  7. #define RNPC_BUILD 14
  8. #define RNPC_DATE "03.12.2014"
  9. #define RNPC_VERSION_DLPAGE "www.mauzen.org/rnpc"
  10. #define RNPC_VERSION_STARTURL "www.mauzen.org/rnpc/rnpc_start.php"
  11. #define RNPC_VERSION_UPDATEURL "www.mauzen.org/rnpc/rnpc_update.php"
  12.  
  13. // Identify messages as RNPC commands
  14. // (alternative communication protocol for future versions)
  15. #define RNPC_COMM_ID 520
  16.  
  17.  
  18. #define PLAYER_RECORDING_TYPE_NONE 0
  19. #define PLAYER_RECORDING_TYPE_DRIVER 1
  20. #define PLAYER_RECORDING_TYPE_ONFOOT 2
  21.  
  22. #define RNPC_SPEED_SPRINT (0.0095)
  23. #define RNPC_SPEED_RUN (0.0057)
  24. #define RNPC_SPEED_WALK (0.0015)
  25.  
  26. #define MAP_ANDREAS_MODE_NONE 0
  27. #define MAP_ANDREAS_MODE_MINIMAL 1
  28. #define MAP_ANDREAS_MODE_MEDIUM 2 // currently unused
  29. #define MAP_ANDREAS_MODE_FULL 3
  30. #define MAP_ANDREAS_MODE_NOBUFFER 4
  31.  
  32. // RNPC_PEND_ACTION defines (Connection relevant states)
  33. #define RNPC_ACTION_READY (-1)
  34. #define RNPC_NOT_EXISTING (0)
  35. #define RNPC_CONNECTION_PENDING (1)
  36. #define RNPC_CONNECTED (2)
  37. #define RNPC_STOPPING (4) // Stop-playback performed
  38.  
  39. // Adjustable stuff
  40. #define RNPC_VEHICLE_DMG_MOD (160.0) // velocity * this value = vehicle hit damage
  41.  
  42.  
  43. // AddPause compatibility mode
  44. #if defined RNPC_PAUSE_REALTIME
  45. #define RNPC_PAUSE_COMP 0
  46. #else
  47. #define RNPC_PAUSE_COMP 1
  48. #endif
  49.  
  50. // @since 0.2
  51. native RNPC_CreateBuild(npcid, type, slot=0);
  52. native RNPC_FinishBuild(clear=1);
  53. native RNPC_AddMovement(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN, use_zmap=0);
  54. native RNPC_ConcatMovement(Float:x, Float:y, Float:z, Float:speed=RNPC_SPEED_RUN, use_zmap=0);
  55. native RNPC_AddPause(time, comp=RNPC_PAUSE_COMP);
  56.  
  57. native RNPC_SetUpdateRate(rate);
  58.  
  59. native RNPC_SetLRKeys(lr);
  60. native RNPC_SetUDKeys(ud);
  61. native RNPC_SetKeys(keys);
  62. native RNPC_SetQuat1(Float:w);
  63. native RNPC_SetQuat2(Float:x);
  64. native RNPC_SetQuat3(Float:y);
  65. native RNPC_SetQuat4(Float:z);
  66. native RNPC_SetHealth(hp);
  67. native RNPC_SetArmour(arm);
  68. native RNPC_SetSpecialAction(sp);
  69. native RNPC_SetWeaponID(weaponid);
  70. native RNPC_SetAnimID(anim);
  71. native RNPC_SetAnimParams(params);
  72. native RNPC_SetAngleQuats(Float:a, Float:h, Float:b);
  73.  
  74. // @since 0.2.1
  75. native RNPC_GetBuildLength();
  76.  
  77. // @since 0.3
  78. native RNPC_SetSirenState(siren);
  79. native RNPC_SetDriverHealth(health);
  80. native RNPC_SetInternalPos(Float:x, Float:y, Float:z);
  81. native RNPC_SetAcceleration(Float:acc);
  82. native RNPC_SetDeceleration(Float:dec); // Unused yet
  83. native RNPC_AddMovementAlt(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN, bool:lock=true);
  84.  
  85. // @since 0.3.4
  86. native RNPC_CreateCustomBuild(type, name[]);
  87.  
  88. // fake-functions
  89. #define RNPC_SetAutorepeat(%1,%2) new rtxt[10]; format(rtxt, 10, "RNPC:%d", 110 + %2); SendClientMessage(%1, -1, rtxt)
  90. #define RNPC_PauseRecordingPlayback(%1) SendClientMessage(%1, -1, "RNPC:103")
  91. #define RNPC_ResumeRecordingPlayback(%1) SendClientMessage(%1, -1, "RNPC:104")
  92. #define RNPC_ToggleVehicleCollisionCheck(%1,%2) new rtxt[10]; format(rtxt, 10, "RNPC:%d", 115 - %2); SendClientMessage(%1, -1, rtxt)
  93. #define RNPC_StopPlayback(%1) SendClientMessage(%1, -1, "RNPC:102")
  94. #define RNPC_SetShootable(%1,%2) rnpcData[%1][RNPC_SHOOTABLE] = %2
  95. #define GetRNPCHealth(%1) rnpcData[%1][RNPC_HEALTH]
  96. #define IsPlayerRNPC(%1) (IsPlayerNPC(%1) && (rnpcPend{%1} != RNPC_NOT_EXISTING))
  97.  
  98.  
  99. // Redirecting SendClientMessage when debugmode is enabled
  100. #if defined RNPC_DEBUG
  101. stock RNPC_TEMP_SendClientMessage(playerid, color, text[], len=sizeof(text)) {
  102. #pragma unused len
  103. // if (IsPlayerRNPC(playerid))
  104. // not needed here as this include doesnt communicate with real players anyways
  105. printf("RNPC %d <-- [CMD] %s", playerid, text);
  106. SendClientMessage(playerid, color, text);
  107. }
  108. #define SendClientMessage RNPC_TEMP_SendClientMessage
  109. #endif
  110. // --------------------------------------------------------
  111.  
  112. // Custom callbacks
  113. forward OnRNPCPlaybackFinished(npcid);
  114. forward OnRNPCPlaybackStopped(npcid);
  115. forward OnRNPCDeath(npcid, killerid, reason);
  116. forward OnRNPCVehicleHit(npcid, driverid, vehicleid, times);
  117.  
  118.  
  119. // To store pending connections and actions
  120. new rnpcPend[MAX_PLAYERS char];
  121. // Currently played record slot
  122. new rnpcCurSlot[MAX_PLAYERS char];
  123.  
  124. /**
  125. * Connects a new RNPC, returning his predicted ID.
  126. * @since V0.1
  127. */
  128. stock ConnectRNPC(name[])
  129. {
  130. // Find the first free playerslot
  131. new slot = -1;
  132. for (new i = 0; i < MAX_PLAYERS; i++) {
  133. // Make sure theres no NPC connecting to that slot yet
  134. if (!IsPlayerConnected(i) && rnpcPend{i} == RNPC_NOT_EXISTING) {
  135. slot = i;
  136. rnpcPend{i} = RNPC_CONNECTION_PENDING;
  137. break;
  138. }
  139. }
  140. ConnectNPC(name, "RNPC");
  141.  
  142. return slot;
  143. }
  144.  
  145. /**
  146. * Moves a RNPC to the given position.
  147. * @since V0.1
  148. */
  149. stock MoveRNPC(npcid, Float:x, Float:y, Float:z, Float:speed, use_zmap=0)
  150. {
  151. if (!IsPlayerRNPC(npcid)) return false;
  152.  
  153. new Float:nx, Float:ny, Float:nz;
  154. new slot;
  155. if (IsPlayerInAnyVehicle(npcid)) {
  156. GetVehiclePos(GetPlayerVehicleID(npcid), nx, ny, nz);
  157. slot = RNPC_CreateBuild_s(npcid, PLAYER_RECORDING_TYPE_DRIVER, 95);
  158. RNPC_AddMovement(nx, ny, nz, x, y, z, speed, use_zmap);
  159. RNPC_FinishBuild();
  160. } else {
  161. GetPlayerPos(npcid, nx, ny, nz);
  162. slot = RNPC_CreateBuild_s(npcid, PLAYER_RECORDING_TYPE_ONFOOT, 95);
  163. RNPC_AddMovement(nx, ny, nz, x, y, z, speed, use_zmap);
  164. RNPC_FinishBuild();
  165. }
  166. RNPC_StartBuildPlayback(npcid, slot);
  167.  
  168. return true;
  169. }
  170.  
  171. /**
  172. * Prevents writing to currently active files.
  173. * IMPORTANT: consider the returned slot to be sure to play the correct one afterwards.
  174. */
  175. stock RNPC_CreateBuild_s(npcid, type, slot=0) {
  176. if (rnpcCurSlot{npcid} == slot) {
  177. slot = (slot + 1) % 100;
  178. }
  179. RNPC_CreateBuild(npcid, type, slot);
  180. return slot;
  181. }
  182.  
  183. /**
  184. * Tells the NPC to start playback of any rec file
  185. * @since V0.1.1
  186. */
  187. stock RNPC_StartPlayback(npcid, rec[])
  188. {
  189. if (!IsPlayerRNPC(npcid)) return false;
  190.  
  191. new form[40];
  192. format(form, 40, "RNPC:109:%s", rec);
  193. SendClientMessage(npcid, -1, form);
  194.  
  195. return true;
  196. }
  197.  
  198. /**
  199. * Tells the NPC to start playback of a RNPC build
  200. * @since V0.2
  201. */
  202. stock RNPC_StartBuildPlayback(npcid, slot=0, vehicleid=0)
  203. {
  204. // If enabled, wait a bit till the NPC actually entered the vehicle
  205. if (vehicleid) {
  206. PutPlayerInVehicle(npcid, vehicleid, 0);
  207. SetTimerEx("DelayStart", 100, 0, "iii", npcid, vehicleid, slot);
  208. }
  209. rnpcCurSlot{npcid} = slot;
  210. new cmd[16];
  211. format(cmd, 16, "RNPC:101:%d", slot);
  212. SendClientMessage(npcid, -1, cmd);
  213. }
  214.  
  215. /**
  216. * Delayed second start to fix vehicle playback problems
  217. * @since V0.3
  218. */
  219. forward DelayStart(npcid, vehicleid, slot);
  220. public DelayStart(npcid, vehicleid, slot)
  221. {
  222. PutPlayerInVehicle(npcid, vehicleid, 0);
  223. new cmd[16];
  224. format(cmd, 16, "RNPC:101:%d", slot);
  225. SendClientMessage(npcid, -1, cmd);
  226. }
  227.  
  228. /**
  229. *
  230. * @since V0.3
  231. */
  232. //stock RNPC_StopPlayback(npcid)
  233. //{
  234. // Moved to fake functions
  235. //}
  236.  
  237.  
  238. // Damage management ---------------------------------------------
  239.  
  240. enum RNPC_DATA_ENUM {
  241. Float: RNPC_HEALTH, // Stores a healthvalue for the NPC
  242. RNPC_DEAD, // Determines if the NPC is dead
  243. RNPC_LAST_DAMAGER, // Last guy who attacked the NPC
  244. RNPC_LAST_REASON, // Last damage reason
  245. RNPC_SHOOTABLE, // If true, the NPC will get default GTA damage from guns
  246. RNPC_VEHICLEHIT,
  247. RNPC_VEHICLEHIT_RESETTIMER // Timer to reset the vehiclehit status and resume playback
  248. };
  249.  
  250. new rnpcData[MAX_PLAYERS][RNPC_DATA_ENUM];
  251.  
  252.  
  253. stock SetRNPCHealth(npcid, Float:health, issuer=INVALID_PLAYER_ID, reason=53) {
  254. rnpcData[npcid][RNPC_HEALTH] = health;
  255.  
  256. rnpcData[npcid][RNPC_LAST_DAMAGER] = issuer;
  257. rnpcData[npcid][RNPC_LAST_REASON] = reason;
  258.  
  259. if (rnpcData[npcid][RNPC_HEALTH] <= 0.0) {
  260. // Kill the NPC if hes not already dead
  261.  
  262. if (!rnpcData[npcid][RNPC_DEAD]) {
  263. // Stop playback
  264. RNPC_StopPlayback(npcid);
  265. }
  266. // --> When stopped, apply death animation
  267. }
  268. }
  269.  
  270.  
  271. // Exact runover check, called after proximity alert by a NPC
  272. // TODO: Move that calculation to the plugin for better speed
  273. stock IsVehicleOnPlayer(playerid, vehicleid) {
  274. static Float:ro_xs, Float:ro_ys, Float:ro_zs;
  275. static Float:ro_xn, Float:ro_yn, Float:ro_zn;
  276. static Float:ro_xv, Float:ro_yv, Float:ro_zv, Float:ro_av;
  277. static Float:ro_tx, Float:ro_ty;
  278. // Gather position and size data
  279. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, ro_xs, ro_ys, ro_zs);
  280. GetPlayerPos(playerid, ro_xn, ro_yn, ro_zn);
  281. GetVehiclePos(vehicleid, ro_xv, ro_yv, ro_zv);
  282. GetVehicleZAngle(vehicleid, ro_av);
  283. //ro_av = 360 - ro_av;
  284.  
  285. // Transform coordinate system
  286. ro_tx = floatabs((ro_xn - ro_xv) * floatcos(ro_av,degrees) + (ro_yn - ro_yv) * floatsin(ro_av,degrees));
  287. ro_ty = floatabs(-(ro_xn - ro_xv) * floatsin(ro_av,degrees) + (ro_yn - ro_yv) * floatcos(ro_av,degrees));
  288.  
  289. return ((ro_zn - ro_zv) < 0.5) && (ro_tx < ro_xs / 2 && ro_ty < ro_ys / 2);
  290. }
  291.  
  292. // Used for timed respawn
  293. forward RespawnRNPC(npcid);
  294. public RespawnRNPC(npcid) {
  295. SpawnPlayer(npcid);
  296. }
  297.  
  298.  
  299. forward ResetVehicleHit(npcid);
  300. public ResetVehicleHit(npcid) {
  301. // Reset hitstate and continue playbck
  302. rnpcData[npcid][RNPC_VEHICLEHIT] = 0;
  303. rnpcData[npcid][RNPC_VEHICLEHIT_RESETTIMER] = -1;
  304. RNPC_ResumeRecordingPlayback(npcid);
  305. }
  306.  
  307.  
  308. // Hooked callbacks ---------------------------------------------------
  309.  
  310. /**
  311. * Serverside interface for RNPC communication
  312. */
  313. // Support for ZCMD, modified version of Lorenc_'s experimental update
  314. #if defined _zcmd_included
  315. #define OPCT_HOOKNAME "RNPC_OnPlayerCommandReceived"
  316. public OnPlayerCommandReceived(playerid, cmdtext[])
  317. #else
  318. #define OPCT_HOOKNAME "RNPC_OnPlayerCommandText"
  319. public OnPlayerCommandText(playerid, cmdtext[])
  320. #endif
  321. {
  322. if (!IsPlayerRNPC(playerid)) return CallLocalFunction(OPCT_HOOKNAME, "is", playerid, cmdtext);
  323.  
  324. #if defined RNPC_DEBUG
  325. printf("RNPC %d --> [CMD] %s", playerid, cmdtext);
  326. #endif
  327.  
  328. // NPC finished playback
  329. if (!strcmp("RNPC:002", cmdtext, true, 8)) {
  330. // Reset current slot for RNPC_CreateBuild_s
  331. rnpcCurSlot{playerid} = -1;
  332. if (rnpcPend{playerid} == RNPC_STOPPING) {
  333. // Call OnRNPCPlaybackStopped instead and reset state
  334. rnpcPend{playerid} = RNPC_CONNECTED;
  335. // Check if it was a stop caused by NPC death
  336. if (rnpcData[playerid][RNPC_HEALTH] <= 0.0 && !rnpcData[playerid][RNPC_DEAD]) {
  337. // Mark as finally dead in include
  338. rnpcData[playerid][RNPC_DEAD] = true;
  339. // Tell NPC hes dead so he wont execute playbacks anymore
  340. SendClientMessage(playerid, -1, "RNPC:112");
  341. if (CallLocalFunction("OnRNPCDeath", "iii", playerid, rnpcData[playerid][RNPC_LAST_DAMAGER], rnpcData[playerid][RNPC_LAST_REASON]) == 0) {
  342. // Default behaviour
  343. SetTimerEx("RespawnRNPC", 4000, 0, "i", playerid);
  344. if (rnpcData[playerid][RNPC_LAST_REASON] != 49) {
  345. // If killed by vehicle, animation is already played
  346. switch(random(4)) {
  347. case 0: ApplyAnimation(playerid, "PED", "KO_skid_back", 4.1, 0, 1, 1, 1, 0, 1);
  348. case 1: ApplyAnimation(playerid, "PED", "KO_skid_front", 4.1, 0, 1, 1, 1, 0, 1);
  349. case 2: ApplyAnimation(playerid, "PED", "KO_spin_L", 4.1, 0, 1, 1, 1, 0, 1);
  350. case 3: ApplyAnimation(playerid, "PED", "KO_spin_R", 4.1, 0, 1, 1, 1, 0, 1);
  351. }
  352. }
  353. CallLocalFunction("OnPlayerDeath", "iii", playerid, rnpcData[playerid][RNPC_LAST_DAMAGER], rnpcData[playerid][RNPC_LAST_REASON]);
  354. }
  355. } else {
  356. // Dont call this for death-stops
  357. CallLocalFunction("OnRNPCPlaybackStopped", "i", playerid);
  358. }
  359. } else CallLocalFunction("OnRNPCPlaybackFinished", "i", playerid);
  360. return 1;
  361. }
  362.  
  363. // NPC stopped playback (manual abort)
  364. if (!strcmp("RNPC:003", cmdtext, true, 8)) {
  365. // Reset onfoot movements after manual playback stop
  366. if (!IsPlayerInAnyVehicle(playerid)) {
  367. // Keep visible, static attirbutes to restore them later
  368. new Float:x, Float:y, Float:z, Float:ang, weapon, spec;
  369. GetPlayerPos(playerid, x, y, z);
  370. GetPlayerFacingAngle(playerid, ang);
  371. spec = GetPlayerSpecialAction(playerid);
  372. weapon = GetPlayerWeapon(playerid);
  373. // Create "blank" build and restore old static attributes
  374. RNPC_CreateBuild(playerid, PLAYER_RECORDING_TYPE_ONFOOT, 95);
  375. RNPC_SetWeaponID(weapon);
  376. RNPC_SetSpecialAction(spec);
  377. RNPC_SetAngleQuats(0.0, 360.0 - ang, 0.0);
  378. RNPC_AddPause(5);
  379. RNPC_FinishBuild();
  380. // OnRNPCPlaybackStopped is called when the stop-playback is finished
  381. rnpcPend{playerid} = RNPC_STOPPING;
  382. RNPC_StartBuildPlayback(playerid, 95);
  383. }
  384. return 1;
  385. }
  386.  
  387. // NPC reports possible run-over vehicle
  388. // Do exact check and handle run-over
  389. if (!strcmp("RNPC:301", cmdtext, true, 8)) {
  390. new driverid = strval(cmdtext[9]),
  391. vehicleid = GetPlayerVehicleID(driverid);
  392.  
  393. if (IsVehicleOnPlayer(playerid, vehicleid)) {
  394. #if !defined RNPC_DONT_PAUSE_ON_VEHICLEHIT
  395. // On the first hit, pause playback
  396. if (rnpcData[playerid][RNPC_VEHICLEHIT] == 0) {
  397. RNPC_PauseRecordingPlayback(playerid);
  398. }
  399. // Reset the reset timer
  400. if (rnpcData[playerid][RNPC_VEHICLEHIT_RESETTIMER] > 0) {
  401. KillTimer(rnpcData[playerid][RNPC_VEHICLEHIT_RESETTIMER]);
  402. }
  403. // Resets the vehicle hit status, even if the vehicle already is out of range
  404. rnpcData[playerid][RNPC_VEHICLEHIT_RESETTIMER] = SetTimerEx("ResetVehicleHit", 2200, 0, "i", playerid);
  405. #endif
  406.  
  407. if (!CallLocalFunction("OnRNPCVehicleHit", "iiii", playerid, driverid, vehicleid, rnpcData[playerid][RNPC_VEHICLEHIT])) {
  408. // Default behaviour
  409. if (!rnpcData[playerid][RNPC_VEHICLEHIT]) {
  410. // Initial hit damage
  411. new Float:vx, Float:vy, Float:vz;
  412. GetVehicleVelocity(vehicleid, vx, vy, vz);
  413. SetRNPCHealth(playerid, GetRNPCHealth(playerid) - floatsqroot(vx*vx + vy*vy + vz*vz) * RNPC_VEHICLE_DMG_MOD, driverid, 49);
  414. } else {
  415. // Constant standing damage
  416. SetRNPCHealth(playerid, GetRNPCHealth(playerid) - 1.0, driverid, 49);
  417. }
  418.  
  419. }
  420. rnpcData[playerid][RNPC_VEHICLEHIT]++;
  421. } /*else {
  422. // If vehicle just left the player, resume reset hitstate instantly
  423. // also setting up the stand-up resume timer
  424. if (rnpcData[playerid][RNPC_VEHICLEHIT] > 0) {
  425. // Reset the reset timer
  426. if ((rnpcData[playerid][RNPC_VEHICLEHIT_RESETTIMER] > 0) && 0) {
  427. KillTimer(rnpcData[playerid][RNPC_VEHICLEHIT_RESETTIMER]);
  428. }
  429. //ResetVehicleHit(playerid, RNPC_RESETVH_RESET);
  430. }
  431. }*/
  432.  
  433. return 1;
  434. }
  435.  
  436. // Ignore other unhandled RNPC messages
  437. if (!strcmp("RNPC:", cmdtext, true, 5)) return 1;
  438.  
  439. return CallLocalFunction(OPCT_HOOKNAME, "is", playerid, cmdtext);
  440. }
  441. // Hook to either zcmd or default
  442. #if defined _zcmd_included
  443. #if defined _ALS_OnPlayerCommandReceived
  444. #undef OnPlayerCommandReceived
  445. #else
  446. #define _ALS_OnPlayerCommandReceived
  447. #endif
  448. #define OnPlayerCommandReceived RNPC_OnPlayerCommandReceived
  449. forward RNPC_OnPlayerCommandReceived(playerid, cmdtext[]);
  450. #else
  451. #if defined _ALS_OnPlayerCommandText
  452. #undef OnPlayerCommandText
  453. #else
  454. #define _ALS_OnPlayerCommandText
  455. #endif
  456. #define OnPlayerCommandText RNPC_OnPlayerCommandText
  457. forward RNPC_OnPlayerCommandText(playerid, cmdtext[]);
  458. #endif
  459.  
  460.  
  461. /**
  462. * Updating the data when the bot connected.
  463. */
  464. public OnPlayerConnect(playerid) {
  465. if (!IsPlayerRNPC(playerid)) return CallLocalFunction("RNPC_OnPlayerConnect", "i", playerid);
  466.  
  467. rnpcPend{playerid} = RNPC_CONNECTED;
  468. rnpcCurSlot{playerid} = -1;
  469.  
  470. rnpcData[playerid][RNPC_SHOOTABLE] = 0;
  471. rnpcData[playerid][RNPC_HEALTH] = 100.0;
  472. rnpcData[playerid][RNPC_DEAD] = 0;
  473.  
  474. return CallLocalFunction("RNPC_OnPlayerConnect", "i", playerid);
  475. }
  476. #if defined _ALS_OnPlayerConnect
  477. #undef OnPlayerConnect
  478. #else
  479. #define _ALS_OnPlayerConnect
  480. #endif
  481. #define OnPlayerConnect RNPC_OnPlayerConnect
  482. forward RNPC_OnPlayerConnect(playerid);
  483.  
  484.  
  485. /**
  486. * Clearing the data when the bot disconnects.
  487. */
  488. public OnPlayerDisconnect(playerid, reason) {
  489. if (!IsPlayerRNPC(playerid)) return CallLocalFunction("RNPC_OnPlayerDisconnect", "ii", playerid, reason);
  490.  
  491. rnpcPend{playerid} = RNPC_NOT_EXISTING;
  492. rnpcCurSlot{playerid} = -1;
  493. rnpcData[playerid][RNPC_SHOOTABLE] = 0;
  494.  
  495. return CallLocalFunction("RNPC_OnPlayerDisconnect", "ii", playerid, reason);
  496. }
  497. #if defined _ALS_OnPlayerDisconnect
  498. #undef OnPlayerDisconnect
  499. #else
  500. #define _ALS_OnPlayerDisconnect
  501. #endif
  502. #define OnPlayerDisconnect RNPC_OnPlayerDisconnect
  503. forward RNPC_OnPlayerDisconnect(playerid, reason);
  504.  
  505.  
  506. /**
  507. * Setting spawn-related data (health etc)
  508. */
  509. public OnPlayerSpawn(playerid) {
  510. if (IsPlayerRNPC(playerid)) {
  511.  
  512. rnpcData[playerid][RNPC_HEALTH] = 100.0;
  513. rnpcData[playerid][RNPC_DEAD] = 0;
  514.  
  515. }
  516.  
  517. #if defined RNPC_OnPlayerSpawn
  518. return RNPC_OnPlayerSpawn(playerid);
  519. #else
  520. return 1;
  521. #endif
  522. }
  523. #if defined _ALS_OnPlayerSpawn
  524. #undef OnPlayerSpawn
  525. #else
  526. #define _ALS_OnPlayerSpawn
  527. #endif
  528. #define OnPlayerSpawn RNPC_OnPlayerSpawn
  529. forward RNPC_OnPlayerSpawn(playerid);
  530.  
  531.  
  532. public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
  533. {
  534. if (rnpcData[damagedid][RNPC_SHOOTABLE] && IsPlayerRNPC(damagedid)) {
  535. SetRNPCHealth(damagedid, GetRNPCHealth(damagedid) - amount, playerid, weaponid);
  536. }
  537. return CallLocalFunction("RNPC_OnPlayerGiveDamage", "iifii", playerid, damagedid, amount, weaponid, bodypart);
  538. }
  539. #if defined _ALS_OnPlayerGiveDamage
  540. #undef OnPlayerGiveDamage
  541. #else
  542. #define _ALS_OnPlayerGiveDamage
  543. #endif
  544. #define OnPlayerGiveDamage RNPC_OnPlayerGiveDamage
  545. forward RNPC_OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart);
  546.  
  547. #if !defined RNPC_DONT_USE_DEAD_STREAMIN_FIX
  548. public OnPlayerStreamIn(playerid, forplayerid)
  549. {
  550. if (IsPlayerRNPC(playerid)) {
  551. if (rnpcData[playerid][RNPC_DEAD] > 0) {
  552. ApplyAnimation(playerid, "PED", "KO_skid_back", 4.1, 0, 1, 1, 1, 0, 1);
  553. }
  554. }
  555.  
  556. return CallLocalFunction("RNPC_OnPlayerStreamIn", "ii", playerid, forplayerid);
  557. }
  558. #if defined _ALS_OnPlayerStreamIn
  559. #undef OnPlayerStreamIn
  560. #else
  561. #define _ALS_OnPlayerStreamIn
  562. #endif
  563. #define OnPlayerStreamIn RNPC_OnPlayerStreamIn
  564. forward RNPC_OnPlayerStreamIn(playerid, forplayerid);
  565. #endif
  566.  
  567.  
  568. // End of user functions ---------------------------------------------------
  569.  
  570. // Version checker and stats collector
  571. #if !defined RNPC_NO_VERSION_CHECK
  572. #include <a_http>
  573. public OnGameModeInit() {
  574. printf(" RNPC versionchecker: checking for updates...");
  575. new url[72];
  576. format(url, sizeof(url), "version=%d&port=%d", RNPC_BUILD, GetServerVarAsInt("port"));
  577. HTTP(9000, HTTP_POST, RNPC_VERSION_STARTURL, url, "RNPC_http_versioncheck");
  578.  
  579. return CallLocalFunction("RNPC_OnGameModeInit", "");
  580. }
  581. #if defined _ALS_OnGameModeInit
  582. #undef OnGameModeInit
  583. #else
  584. #define _ALS_OnGameModeInit
  585. #endif
  586. #define OnGameModeInit RNPC_OnGameModeInit
  587. forward RNPC_OnGameModeInit();
  588.  
  589. forward RNPC_http_versioncheck(index, response_code, data[]);
  590. public RNPC_http_versioncheck(index, response_code, data[]) {
  591. if (index != 9000) return;
  592.  
  593. if (response_code != 200) {
  594. printf(" RNPC versionchecker: Connection problem.");
  595. return;
  596. }
  597.  
  598. if (strlen(data) > 1) {
  599. printf("------------------------------------------------------------------");
  600. printf(" RNPC versionchecker: New version available!", data);
  601. printf(" RNPC versionchecker: Your version: "RNPC_VERSION" ("RNPC_DATE")");
  602. printf(" RNPC versionchecker: New version: %s", data);
  603. printf(" RNPC versionchecker: Check "RNPC_VERSION_DLPAGE" for downloads");
  604. printf("------------------------------------------------------------------");
  605. }
  606.  
  607. #if !defined RNPC_NO_STATUPDATES
  608. SetTimer("RNPC_http_statupdater", 60000 * 15, 1);
  609. #endif
  610. }
  611.  
  612. #if !defined RNPC_NO_STATUPDATES
  613. forward RNPC_http_statupdater();
  614. public RNPC_http_statupdater() {
  615. new url[64];
  616. format(url, sizeof(url), "version=%d&port=%d", RNPC_BUILD, GetServerVarAsInt("port"));
  617. HTTP(0, HTTP_POST, RNPC_VERSION_UPDATEURL, url, "RNPC_http_versioncheck");
  618. }
  619. #endif
  620. #endif
  621.  
  622.  
  623. // EOF -------------------------------------------- Revoke SendClientMessge redirection
  624. #if defined RNPC_DEBUG
  625. #undef SendClientMessage
  626. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement