Advertisement
EnzoMetlc

[Include] RNPC Updated - EnzoMetlc.

Jan 22nd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.90 KB | None | 0 0
  1. /**
  2.  *  RNPC - Recordfile NPCs
  3.  *  Version 0.3
  4.  *  made by Mauzen, parts based on Joe Staffs code
  5.  */
  6.  
  7. #include <a_samp>
  8.  
  9. #define PLAYER_RECORDING_TYPE_NONE      0
  10. #define PLAYER_RECORDING_TYPE_DRIVER    1
  11. #define PLAYER_RECORDING_TYPE_ONFOOT    2
  12.  
  13. #define RNPC_SPEED_SPRINT               (0.0095)
  14. #define RNPC_SPEED_RUN                  (0.0057)
  15. #define RNPC_SPEED_WALK                 (0.0015)
  16. #define RNPC_SPEED_FASTWALK             (0.0040)
  17.  
  18. #define MAP_ANDREAS_MODE_NONE           0
  19. #define MAP_ANDREAS_MODE_MINIMAL        1
  20. #define MAP_ANDREAS_MODE_MEDIUM         2   // currently unused
  21. #define MAP_ANDREAS_MODE_FULL           3
  22. #define MAP_ANDREAS_MODE_NOBUFFER       4
  23.  
  24. // @since 0.3.2 - by Pamdex
  25. native RNPC_PathFinderMovement(Float:start_x, Float:start_y, Float:start_z, nodes_array[], nodes_array_size, Float:speed=RNPC_SPEED_RUN);
  26.  
  27. // @since 0.2
  28. native RNPC_CreateBuild(npcid, type, slot=0);
  29. native RNPC_FinishBuild(clear=1);
  30. native RNPC_AddMovement(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN);
  31. native RNPC_AddAutoMovement(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN, maxsteps=1000);
  32. native RNPC_ConcatMovement(Float:x, Float:y, Float:z, Float:speed=RNPC_SPEED_RUN);
  33. native RNPC_AddPause(time);
  34.  
  35. native RNPC_SetUpdateRate(rate);
  36.  
  37. native RNPC_SetLRKeys(lr);
  38. native RNPC_SetUDKeys(ud);
  39. native RNPC_SetKeys(keys);
  40. native RNPC_SetQuat1(Float:w);
  41. native RNPC_SetQuat2(Float:x);
  42. native RNPC_SetQuat3(Float:y);
  43. native RNPC_SetQuat4(Float:z);
  44. native RNPC_SetArmour(arm);
  45. native RNPC_SetSpecialAction(sp);
  46. native RNPC_SetWeaponID(weaponid);
  47. native RNPC_SetAnimID(anim);
  48. native RNPC_SetAnimParams(params);
  49. native RNPC_SetAngleQuats(Float:a, Float:h, Float:b);
  50.  
  51. native MapAndreas_Init(mode);
  52. native MapAndreas_FindZ_For2DCoord(Float:X, Float:Y, &Float:Z);
  53. native MapAndreas_FindAverageZ(Float:X, Float:Y, &Float:Z);
  54. native MapAndreas_Unload();
  55.  
  56. // @since 0.2.1
  57. native RNPC_GetBuildLength();
  58.  
  59. // @since 0.3
  60. native RNPC_SetSirenState(siren);
  61. native RNPC_SetDriverHealth(health);
  62. native RNPC_SetInternalPos(Float:x, Float:y, Float:z);
  63. native RNPC_SetAcceleration(Float:acc);
  64. native RNPC_SetDeceleration(Float:dec);     // Unused yet
  65. native RNPC_AddMovementAlt(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN, bool:lock=true);
  66.  
  67. // Fake communication functions
  68. #define RNPC_SetAutorepeat(%1,%2)       new rtxt[10]; format(rtxt, 10, "RNPC:%d", 110 + %2); SendClientMessage(%1, -1, rtxt)
  69.  
  70. forward OnRNPCPlaybackFinished(npcid);
  71.  
  72. /**
  73.  *  Connects a new RNPC, returning his ID.
  74.  *  @since  V0.1
  75.  */
  76. stock ConnectRNPC(name[])
  77. {
  78.     new slot = -1;
  79.     for (new i = 0; i < GetMaxPlayers(); i++)
  80.     {
  81.         if(!IsPlayerConnected(i))
  82.         {
  83.             slot = i;
  84.             break;
  85.         }
  86.     }
  87.     ConnectNPC(name, "RNPC");
  88.     return slot;
  89. }
  90.  
  91. /**
  92.  *  Moves a RNPC to the given position.
  93.  *  @since  V0.1
  94.  */
  95. stock MoveRNPC(npcid, Float:x, Float:y, Float:z, Float:speed)
  96. {
  97.     if (!IsPlayerNPC(npcid)) return false;
  98.  
  99.     new Float:nx, Float:ny, Float:nz;
  100.     if(IsPlayerInAnyVehicle(npcid))
  101.     {
  102.         GetVehiclePos(GetPlayerVehicleID(npcid), nx, ny, nz);
  103.         RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
  104.         RNPC_AddMovement(nx, ny, nz, x, y, z, speed);
  105.         RNPC_FinishBuild();
  106.     }
  107.     else
  108.     {
  109.         GetPlayerPos(npcid, nx, ny, nz);
  110.         RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  111.         RNPC_AddMovement(nx, ny, nz, x, y, z, speed);
  112.         RNPC_FinishBuild();
  113.     }
  114.     RNPC_StartBuildPlayback(npcid);
  115.  
  116.     SendClientMessage(npcid, -1, "RNPC:101:0");
  117.     return true;
  118. }
  119.  
  120.  
  121. /**
  122.  *
  123.  *  @since  V0.1.1
  124.  */
  125. stock RNPC_StartPlayback(npcid, rec[])
  126. {
  127.     if (!IsPlayerNPC(npcid)) return false;
  128.  
  129.     new form[40];
  130.     format(form, 40, "RNPC:109:%s", rec);
  131.     SendClientMessage(npcid, -1, form);
  132.     return true;
  133. }
  134.  
  135. /**
  136.  *
  137.  *  @since V0.2
  138.  */
  139. stock RNPC_StartBuildPlayback(npcid, slot=0, vehicleid=0)
  140. {
  141.     if(vehicleid)
  142.     {
  143.         PutPlayerInVehicle(npcid, vehicleid, 0);
  144.         SetTimerEx("DelayStart", 100, 0, "iii", npcid, vehicleid, slot);
  145.     }
  146.     new cmd[16];
  147.     format(cmd, 16, "RNPC:101:%d", slot);
  148.     SendClientMessage(npcid, -1, cmd);
  149. }
  150.  
  151. /**
  152.  * Delayed second start to fix vehicle playback problems
  153.  * @since V0.3
  154.  */
  155. forward DelayStart(npcid, vehicleid, slot);
  156. public DelayStart(npcid, vehicleid, slot)
  157. {
  158.     PutPlayerInVehicle(npcid, vehicleid, 0);
  159.     new cmd[16];
  160.     format(cmd, 16, "RNPC:101:%d", slot);
  161.     SendClientMessage(npcid, -1, cmd);
  162. }
  163.  
  164. /**
  165.  *
  166.  * @since V0.3
  167.  */
  168. stock RNPC_StopPlayback(npcid)
  169. {
  170.     //new Float:x, Float:y, Float:z;
  171.     //if (IsPlayerInAnyVehicle(npcid)) GetVehiclePos(GetPlayerVehicleID(npcid), x, y, z);
  172.     //  else GetPlayerPos(npcid, x, y, z);
  173.     SendClientMessage(npcid, -1, "RNPC:102");
  174.     //RNPC_SetInternalPos(x, y, z);
  175. }
  176.  
  177.  
  178.  
  179. // ************************************************************************************ //
  180. /**
  181.  * @By EnzoMetlc.
  182.  *
  183.  */
  184.  
  185. #if !defined GetPointZPos
  186. stock Float:GetPointZPos(const Float: fX, const Float: fY, &Float: fZ = 0.0)
  187. {
  188.     if(!((-3000.0 < fX < 3000.0) && (-3000.0 < fY < 3000.0)))
  189.     {
  190.         return 0.0;
  191.     }
  192.     static File: s_hMap;
  193.     if(!s_hMap)
  194.     {
  195.         s_hMap = fopen("SAfull.hmap", io_read);
  196.         if(!s_hMap)
  197.         {
  198.             return 0.0;
  199.         }
  200.     }
  201.     new afZ[1] ;
  202.     fseek(s_hMap, ((6000 * (-floatround(fY, floatround_tozero) + 3000) + (floatround(fX, floatround_tozero) + 3000)) << 1));
  203.     fblockread(s_hMap, afZ);
  204.     return (fZ = ((afZ[0] >>> 16) * 0.01));
  205. }
  206. #endif
  207.  
  208.  
  209. stock SetRNPCPosFindZ(npcid)
  210. {
  211.     if(IsPlayerNPC(npcid))
  212.     {
  213.         new Float:Pos[3];
  214.         GetRNPCPos(npcid, Pos[0], Pos[1], Pos[2]);
  215.         GetPointZPos(Pos[0], Pos[1], Pos[2]);
  216.         SetRNPCPos(npcid, Pos[0], Pos[1], Pos[2]+0.5);
  217.     }
  218. }
  219.  
  220. stock SetRNPCPosFindZEx(npcid, Float:PosX, Float:PosY)
  221. {
  222.     if(IsPlayerNPC(npcid))
  223.     {
  224.         SetRNPCPos(npcid, PosX, PosY, 3.0);
  225.         SetRNPCPosFindZ(npcid);
  226.     }
  227. }
  228.  
  229.  
  230. stock SetRNPCPos(npcid, Float:PosX, Float:PosY, Float:PosZ)
  231. {
  232.     if(IsPlayerNPC(npcid))
  233.     {
  234.         SetPlayerPos(npcid, PosX, PosY, PosZ);
  235.     }
  236. }
  237.  
  238.  
  239.  
  240. stock GetRNPCPos(npcid, &Float:PosX, &Float:PosY, &Float:PosZ)
  241. {
  242.     if(IsPlayerNPC(npcid))
  243.     {
  244.         GetPlayerPos(npcid, PosX, PosY, PosZ);
  245.     }
  246. }
  247.  
  248.  
  249.  
  250. stock SetRNPCHealth(npcid, Float:Health)
  251. {
  252.     if(IsPlayerNPC(npcid))
  253.     {
  254.         SetPlayerHealth(npcid, Health);
  255.     }
  256. }
  257.  
  258. stock Float:GetRNPCtHealth(npcid, &Float:Health)
  259. {
  260.     if(IsPlayerNPC(npcid))
  261.     {
  262.         GetPlayerHealth(npcid, Health);
  263.     }
  264.     return Float:0xFFFF;
  265. }
  266.  
  267.  
  268. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  269. {
  270.     if(hittype == 1 && IsPlayerNPC(hitid))
  271.     {
  272.         new Float:HealthRNPC = GetRNPCtHealth(hitid, HealthRNPC);
  273.         if(HealthRNPC >= 0.1)
  274.         {
  275.             switch(weaponid)
  276.             {
  277.                 case 22: SetRNPCHealth(hitid, HealthRNPC-8.25);
  278.                 case 23: SetRNPCHealth(hitid, HealthRNPC-13.2);
  279.                 case 24: SetRNPCHealth(hitid, HealthRNPC-46.2);
  280.                 case 25: SetRNPCHealth(hitid, HealthRNPC-49.5);
  281.                 case 26: SetRNPCHealth(hitid, HealthRNPC-49.5);
  282.                 case 27: SetRNPCHealth(hitid, HealthRNPC-39.6);
  283.                 case 28: SetRNPCHealth(hitid, HealthRNPC-6.6);
  284.                 case 29: SetRNPCHealth(hitid, HealthRNPC-8.25);
  285.                 case 30, 31: SetRNPCHealth(hitid, HealthRNPC-9.9);
  286.                 case 32: SetRNPCHealth(hitid, HealthRNPC-6.6);
  287.                 case 33: SetRNPCHealth(hitid, HealthRNPC-24.75);
  288.                 case 34: SetRNPCHealth(hitid, HealthRNPC-41.25);
  289.                 case 38: SetRNPCHealth(hitid, HealthRNPC-46.2);
  290.             }
  291.             /*
  292.             switch(random(2))
  293.             {
  294.                 case 0: ApplyNPCAnimation(hitid, "PED", "HIT_front", 4.1, 0, 1, 1, 0, 500);
  295.                 case 1: ApplyNPCAnimation(hitid, "PED", "IDLE_stance", 4.1, 0, 1, 1, 0, 500);
  296.             }
  297.             */
  298.             new Float:HealthRest = GetRNPCtHealth(hitid, HealthRest);
  299.             CallLocalFunction("OnPlayerDamgeToNPC", "ddif", playerid, hitid, weaponid, HealthRNPC-HealthRest);
  300.         }
  301.         else
  302.         {
  303.             CallLocalFunction("OnRNPCDeath", "ddi", hitid, playerid, weaponid);
  304.             SetTimerEx("OnNPCSpawn", 4000, false, "d", hitid);
  305.             ApplyAnimation(hitid, "SWEET", "LaFin_Sweet", 4.1, 1, 1, 1, 1, 0, 0);
  306.         }
  307.     }
  308.     return 1;
  309. }
  310. #if defined _ALS_OnPlayerWeaponShot
  311.     #undef OnPlayerWeaponShot
  312. #else
  313.     #define _ALS_OnPlayerWeaponShot
  314. #endif
  315. #define OnPlayerWeaponShot OnPlayerDamageToRNPC
  316.  
  317. forward OnPlayerDamageToRNPC(playerid, npcid, weaponid, Float:amount);
  318. forward OnRNPCDeath(npcid, killerid, weaponid);
  319.  
  320.  
  321.  
  322. /**
  323.  *  Serverside interface for RNPC communication
  324.  */
  325. public OnPlayerCommandText(playerid, cmdtext[])
  326. {
  327.     if (!IsPlayerNPC(playerid)) return CallLocalFunction("RNPC_OnPlayerCommandText", "is", playerid, cmdtext);
  328.  
  329.     #if defined RNPC_DEBUG
  330.         printf("RNPC %d: [CMD] %s", playerid, cmdtext);
  331.     #endif
  332.  
  333.     if (!strcmp("RNPC:002", cmdtext, true, 8))
  334.     {
  335.         CallLocalFunction("OnRNPCPlaybackFinished", "i", playerid);
  336.     }
  337.     else
  338.     {
  339.         return CallLocalFunction("RNPC_OnPlayerCommandText", "is", playerid, cmdtext);
  340.     }
  341.  
  342.     return true;
  343. }
  344. #if defined _ALS_OnPlayerCommandText
  345.     #undef OnPlayerCommandText
  346. #else
  347.     #define _ALS_OnPlayerCommandText
  348. #endif
  349. #define OnPlayerCommandText RNPC_OnPlayerCommandText
  350. forward RNPC_OnPlayerCommandText(playerid, cmdtext[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement