Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * RNPC - Recordfile NPCs
- * Version 0.3
- * made by Mauzen, parts based on Joe Staffs code
- */
- #include <a_samp>
- #define PLAYER_RECORDING_TYPE_NONE 0
- #define PLAYER_RECORDING_TYPE_DRIVER 1
- #define PLAYER_RECORDING_TYPE_ONFOOT 2
- #define RNPC_SPEED_SPRINT (0.0095)
- #define RNPC_SPEED_RUN (0.0057)
- #define RNPC_SPEED_WALK (0.0015)
- #define RNPC_SPEED_FASTWALK (0.0040)
- #define MAP_ANDREAS_MODE_NONE 0
- #define MAP_ANDREAS_MODE_MINIMAL 1
- #define MAP_ANDREAS_MODE_MEDIUM 2 // currently unused
- #define MAP_ANDREAS_MODE_FULL 3
- #define MAP_ANDREAS_MODE_NOBUFFER 4
- // @since 0.3.2 - by Pamdex
- native RNPC_PathFinderMovement(Float:start_x, Float:start_y, Float:start_z, nodes_array[], nodes_array_size, Float:speed=RNPC_SPEED_RUN);
- // @since 0.2
- native RNPC_CreateBuild(npcid, type, slot=0);
- native RNPC_FinishBuild(clear=1);
- native RNPC_AddMovement(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN);
- native RNPC_AddAutoMovement(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN, maxsteps=1000);
- native RNPC_ConcatMovement(Float:x, Float:y, Float:z, Float:speed=RNPC_SPEED_RUN);
- native RNPC_AddPause(time);
- native RNPC_SetUpdateRate(rate);
- native RNPC_SetLRKeys(lr);
- native RNPC_SetUDKeys(ud);
- native RNPC_SetKeys(keys);
- native RNPC_SetQuat1(Float:w);
- native RNPC_SetQuat2(Float:x);
- native RNPC_SetQuat3(Float:y);
- native RNPC_SetQuat4(Float:z);
- native RNPC_SetArmour(arm);
- native RNPC_SetSpecialAction(sp);
- native RNPC_SetWeaponID(weaponid);
- native RNPC_SetAnimID(anim);
- native RNPC_SetAnimParams(params);
- native RNPC_SetAngleQuats(Float:a, Float:h, Float:b);
- native MapAndreas_Init(mode);
- native MapAndreas_FindZ_For2DCoord(Float:X, Float:Y, &Float:Z);
- native MapAndreas_FindAverageZ(Float:X, Float:Y, &Float:Z);
- native MapAndreas_Unload();
- // @since 0.2.1
- native RNPC_GetBuildLength();
- // @since 0.3
- native RNPC_SetSirenState(siren);
- native RNPC_SetDriverHealth(health);
- native RNPC_SetInternalPos(Float:x, Float:y, Float:z);
- native RNPC_SetAcceleration(Float:acc);
- native RNPC_SetDeceleration(Float:dec); // Unused yet
- native RNPC_AddMovementAlt(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:speed=RNPC_SPEED_RUN, bool:lock=true);
- // Fake communication functions
- #define RNPC_SetAutorepeat(%1,%2) new rtxt[10]; format(rtxt, 10, "RNPC:%d", 110 + %2); SendClientMessage(%1, -1, rtxt)
- forward OnRNPCPlaybackFinished(npcid);
- /**
- * Connects a new RNPC, returning his ID.
- * @since V0.1
- */
- stock ConnectRNPC(name[])
- {
- new slot = -1;
- for (new i = 0; i < GetMaxPlayers(); i++)
- {
- if(!IsPlayerConnected(i))
- {
- slot = i;
- break;
- }
- }
- ConnectNPC(name, "RNPC");
- return slot;
- }
- /**
- * Moves a RNPC to the given position.
- * @since V0.1
- */
- stock MoveRNPC(npcid, Float:x, Float:y, Float:z, Float:speed)
- {
- if (!IsPlayerNPC(npcid)) return false;
- new Float:nx, Float:ny, Float:nz;
- if(IsPlayerInAnyVehicle(npcid))
- {
- GetVehiclePos(GetPlayerVehicleID(npcid), nx, ny, nz);
- RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_DRIVER);
- RNPC_AddMovement(nx, ny, nz, x, y, z, speed);
- RNPC_FinishBuild();
- }
- else
- {
- GetPlayerPos(npcid, nx, ny, nz);
- RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
- RNPC_AddMovement(nx, ny, nz, x, y, z, speed);
- RNPC_FinishBuild();
- }
- RNPC_StartBuildPlayback(npcid);
- SendClientMessage(npcid, -1, "RNPC:101:0");
- return true;
- }
- /**
- *
- * @since V0.1.1
- */
- stock RNPC_StartPlayback(npcid, rec[])
- {
- if (!IsPlayerNPC(npcid)) return false;
- new form[40];
- format(form, 40, "RNPC:109:%s", rec);
- SendClientMessage(npcid, -1, form);
- return true;
- }
- /**
- *
- * @since V0.2
- */
- stock RNPC_StartBuildPlayback(npcid, slot=0, vehicleid=0)
- {
- if(vehicleid)
- {
- PutPlayerInVehicle(npcid, vehicleid, 0);
- SetTimerEx("DelayStart", 100, 0, "iii", npcid, vehicleid, slot);
- }
- new cmd[16];
- format(cmd, 16, "RNPC:101:%d", slot);
- SendClientMessage(npcid, -1, cmd);
- }
- /**
- * Delayed second start to fix vehicle playback problems
- * @since V0.3
- */
- forward DelayStart(npcid, vehicleid, slot);
- public DelayStart(npcid, vehicleid, slot)
- {
- PutPlayerInVehicle(npcid, vehicleid, 0);
- new cmd[16];
- format(cmd, 16, "RNPC:101:%d", slot);
- SendClientMessage(npcid, -1, cmd);
- }
- /**
- *
- * @since V0.3
- */
- stock RNPC_StopPlayback(npcid)
- {
- //new Float:x, Float:y, Float:z;
- //if (IsPlayerInAnyVehicle(npcid)) GetVehiclePos(GetPlayerVehicleID(npcid), x, y, z);
- // else GetPlayerPos(npcid, x, y, z);
- SendClientMessage(npcid, -1, "RNPC:102");
- //RNPC_SetInternalPos(x, y, z);
- }
- // ************************************************************************************ //
- /**
- * @By EnzoMetlc.
- *
- */
- #if !defined GetPointZPos
- stock Float:GetPointZPos(const Float: fX, const Float: fY, &Float: fZ = 0.0)
- {
- if(!((-3000.0 < fX < 3000.0) && (-3000.0 < fY < 3000.0)))
- {
- return 0.0;
- }
- static File: s_hMap;
- if(!s_hMap)
- {
- s_hMap = fopen("SAfull.hmap", io_read);
- if(!s_hMap)
- {
- return 0.0;
- }
- }
- new afZ[1] ;
- fseek(s_hMap, ((6000 * (-floatround(fY, floatround_tozero) + 3000) + (floatround(fX, floatround_tozero) + 3000)) << 1));
- fblockread(s_hMap, afZ);
- return (fZ = ((afZ[0] >>> 16) * 0.01));
- }
- #endif
- stock SetRNPCPosFindZ(npcid)
- {
- if(IsPlayerNPC(npcid))
- {
- new Float:Pos[3];
- GetRNPCPos(npcid, Pos[0], Pos[1], Pos[2]);
- GetPointZPos(Pos[0], Pos[1], Pos[2]);
- SetRNPCPos(npcid, Pos[0], Pos[1], Pos[2]+0.5);
- }
- }
- stock SetRNPCPosFindZEx(npcid, Float:PosX, Float:PosY)
- {
- if(IsPlayerNPC(npcid))
- {
- SetRNPCPos(npcid, PosX, PosY, 3.0);
- SetRNPCPosFindZ(npcid);
- }
- }
- stock SetRNPCPos(npcid, Float:PosX, Float:PosY, Float:PosZ)
- {
- if(IsPlayerNPC(npcid))
- {
- SetPlayerPos(npcid, PosX, PosY, PosZ);
- }
- }
- stock GetRNPCPos(npcid, &Float:PosX, &Float:PosY, &Float:PosZ)
- {
- if(IsPlayerNPC(npcid))
- {
- GetPlayerPos(npcid, PosX, PosY, PosZ);
- }
- }
- stock SetRNPCHealth(npcid, Float:Health)
- {
- if(IsPlayerNPC(npcid))
- {
- SetPlayerHealth(npcid, Health);
- }
- }
- stock Float:GetRNPCtHealth(npcid, &Float:Health)
- {
- if(IsPlayerNPC(npcid))
- {
- GetPlayerHealth(npcid, Health);
- }
- return Float:0xFFFF;
- }
- public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
- {
- if(hittype == 1 && IsPlayerNPC(hitid))
- {
- new Float:HealthRNPC = GetRNPCtHealth(hitid, HealthRNPC);
- if(HealthRNPC >= 0.1)
- {
- switch(weaponid)
- {
- case 22: SetRNPCHealth(hitid, HealthRNPC-8.25);
- case 23: SetRNPCHealth(hitid, HealthRNPC-13.2);
- case 24: SetRNPCHealth(hitid, HealthRNPC-46.2);
- case 25: SetRNPCHealth(hitid, HealthRNPC-49.5);
- case 26: SetRNPCHealth(hitid, HealthRNPC-49.5);
- case 27: SetRNPCHealth(hitid, HealthRNPC-39.6);
- case 28: SetRNPCHealth(hitid, HealthRNPC-6.6);
- case 29: SetRNPCHealth(hitid, HealthRNPC-8.25);
- case 30, 31: SetRNPCHealth(hitid, HealthRNPC-9.9);
- case 32: SetRNPCHealth(hitid, HealthRNPC-6.6);
- case 33: SetRNPCHealth(hitid, HealthRNPC-24.75);
- case 34: SetRNPCHealth(hitid, HealthRNPC-41.25);
- case 38: SetRNPCHealth(hitid, HealthRNPC-46.2);
- }
- /*
- switch(random(2))
- {
- case 0: ApplyNPCAnimation(hitid, "PED", "HIT_front", 4.1, 0, 1, 1, 0, 500);
- case 1: ApplyNPCAnimation(hitid, "PED", "IDLE_stance", 4.1, 0, 1, 1, 0, 500);
- }
- */
- new Float:HealthRest = GetRNPCtHealth(hitid, HealthRest);
- CallLocalFunction("OnPlayerDamgeToNPC", "ddif", playerid, hitid, weaponid, HealthRNPC-HealthRest);
- }
- else
- {
- CallLocalFunction("OnRNPCDeath", "ddi", hitid, playerid, weaponid);
- SetTimerEx("OnNPCSpawn", 4000, false, "d", hitid);
- ApplyAnimation(hitid, "SWEET", "LaFin_Sweet", 4.1, 1, 1, 1, 1, 0, 0);
- }
- }
- return 1;
- }
- #if defined _ALS_OnPlayerWeaponShot
- #undef OnPlayerWeaponShot
- #else
- #define _ALS_OnPlayerWeaponShot
- #endif
- #define OnPlayerWeaponShot OnPlayerDamageToRNPC
- forward OnPlayerDamageToRNPC(playerid, npcid, weaponid, Float:amount);
- forward OnRNPCDeath(npcid, killerid, weaponid);
- /**
- * Serverside interface for RNPC communication
- */
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (!IsPlayerNPC(playerid)) return CallLocalFunction("RNPC_OnPlayerCommandText", "is", playerid, cmdtext);
- #if defined RNPC_DEBUG
- printf("RNPC %d: [CMD] %s", playerid, cmdtext);
- #endif
- if (!strcmp("RNPC:002", cmdtext, true, 8))
- {
- CallLocalFunction("OnRNPCPlaybackFinished", "i", playerid);
- }
- else
- {
- return CallLocalFunction("RNPC_OnPlayerCommandText", "is", playerid, cmdtext);
- }
- return true;
- }
- #if defined _ALS_OnPlayerCommandText
- #undef OnPlayerCommandText
- #else
- #define _ALS_OnPlayerCommandText
- #endif
- #define OnPlayerCommandText RNPC_OnPlayerCommandText
- forward RNPC_OnPlayerCommandText(playerid, cmdtext[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement