Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_hooks>
- /* // Native functions:
- // Done by RyDeR:
- native Float:GetPointZPos(const Float: fX, const Float: fY, &Float: fZ = 0.0);
- native RotateNPCToPos(npcid, const Float:PosX, const Float:PosY);
- // Done by me:
- native CreateNPC(npcid, name[]);
- native DestroyNPC(npcid);
- native SpawnNPC(npcid);
- native SetNPCPos(npcid, Float:PosX, Float:PosY, Float:PosZ);
- native SetNPCPosFindZ(npcid);
- native SetNPCPosFindZEx(npcid, Float:PosX, Float:PosY);
- native SetNPCFacingAngle(npcid, Float:Angle);
- native SetNPCHealth(npcid, Float:Health);
- native SetNPCArmour(npcid, Float:Armour);
- native ApplyNPCAnimation(npcid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync = 0);
- native GetNPCPos(npcid, &Float:PosX, &Float:PosY, &Float:PosZ);
- native GetNPCFacingAngle(npcid, &Float:Angle);
- native Float:GetNPCHealth(npcid);
- native Float:GetNPCArmour(npcid);
- native ForeachNPC(iterate); // Thank you pds2k12 for a better code. :)
- native CountAllNPC();
- native KickAllNPC();
- // Forward's:
- forward OnNPCCreated(npcid);
- forward OnNPCSpawn(npcid);
- forward OnPlayerDamgeToNPC(npcid, playerid, weaponid, Float:amount);
- forward OnNPCDeath(npcid, killerid, weaponid);
- forward OnNPCDisconnect(npcid);
- */
- #define MAX_NPC 5
- /
- #define ForeachNPC(%0,%1) \
- new %0; while(++%0 < %1) if(IsPlayerNPC(%0)) return true; else return false;
- new ToAddUpNPCCreated;
- enum DataNPC
- {
- Float:HealthNPC,
- Float:ArmourNPC,
- bool:IsCreated,
- bool:IsSpawned,
- };
- new InfoNPC[MAX_NPC][DataNPC];
- 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));
- }
- stock CreateNPC(npcid, name[])
- {
- if(InfoNPC[npcid][IsCreated] == false)
- {
- if(strlen(name) > 2)
- {
- ToAddUpNPCCreated ++;
- new string[15];
- format(string, sizeof(string), "E_NPC[%i]", ToAddUpNPCCreated);
- npcid = ConnectNPC(name, string);
- InfoNPC[npcid][IsSpawned] = false;
- InfoNPC[npcid][IsCreated] = true;
- ApplyNPCAnimation(npcid, "SWEET", "LaFin_Sweet", 4.1, 1, 1, 1, 1, 0, 0);
- }
- else
- {
- print(" ");
- print("***********************************************************************");
- print("* *");
- print("* *");
- print("* [Warning-AFNPC] The Nick of the NPC must have 3 characters or more. *");
- print("* *");
- print("* *");
- print("***********************************************************************");
- print(" ");
- }
- }
- }
- stock GetNPCFacingAngle(npcid, &Float:Angle)
- {
- if(IsPlayerNPC(npcid)) return GetPlayerFacingAngle(npcid, Angle);
- return 1;
- }
- stock Float:GetNPCHealth(npcid)
- {
- if(IsPlayerNPC(npcid)) return (InfoNPC[npcid][HealthNPC]);
- return 1.0;
- }
- stock Float:GetNPCArmour(npcid)
- {
- if(IsPlayerNPC(npcid)) return (InfoNPC[npcid][ArmourNPC]);
- }
- stock DestroyNPC(npcid)
- {
- if(IsPlayerNPC(npcid))
- {
- ToAddUpNPCCreated --;
- Kick(npcid);
- }
- }
- stock SpawnNPC(npcid)
- {
- if(IsPlayerNPC(npcid))
- {
- SpawnPlayer(npcid);
- InfoNPC[npcid][IsSpawned] = true;
- }
- }
- stock SetNPCPos(npcid, Float:PosX, Float:PosY, Float:PosZ)
- {
- if(IsPlayerNPC(npcid))
- {
- SetPlayerPos(npcid, PosX, PosY, PosZ);
- }
- }
- stock SetNPCPosFindZ(npcid)
- {
- if(IsPlayerNPC(npcid))
- {
- new Float:Pos[3];
- GetNPCPos(npcid, Pos[0], Pos[1], Pos[2]);
- GetPointZPos(Pos[0], Pos[1], Pos[2]);
- SetNPCPos(npcid, Pos[0], Pos[1], Pos[2]);
- }
- }
- stock SetNPCPosFindZEx(npcid, Float:PosX, Float:PosY)
- {
- if(IsPlayerNPC(npcid))
- {
- SetNPCPos(npcid, PosX, PosY, 0.0);
- SetNPCPosFindZ(npcid);
- }
- }
- /*
- // This script serves, but it does not work correctly (it is not possible to do that the NPC runs softly like it should)
- stock MoveNPC(npcid, Float:PosX, Float:PosY, Float:PosZ, Float:speed)
- {
- if(IsPlayerNPC(npcid))
- {
- new Float:Pos[3];
- new Float:AngleNPC;
- GetPlayerPos(npcid, Pos[0], Pos[1], Pos[2]);
- GetNPCFacingAngle(npcid, AngleNPC);
- RotateNPCToPos(npcid, PosX, PosY);
- DestroyObject(InfoNPC[npcid][ObjectMoveNPC]);
- InfoNPC[npcid][ObjectMoveNPC] = CreateObject(19300, Pos[0], Pos[1], Pos[2], 0.0, 0.0, AngleNPC);
- MoveObject(InfoNPC[npcid][ObjectMoveNPC], PosX, PosY, PosZ, speed, 0.0, 0.0, 0.0);
- ApplyNPCAnimation(npcid, "PED", "RUN_civi", 4.1, 0, 1, 1, 0, -1);
- InfoNPC[npcid][TimerMoveNPC] = SetTimerEx("MoveNPC_Callback", 75, true, "d", npcid);
- InfoNPC[npcid][IsMoving] = true;
- }
- }
- forward MoveNPC_Callback(npcid);
- public MoveNPC_Callback(npcid)
- {
- new Float:Pos[3];
- //ApplyNPCAnimation(npcid, "PED", "RUN_civi", 4.1, 0, 1, 1, 0, -1);
- GetObjectPos(InfoNPC[npcid][ObjectMoveNPC], Pos[0], Pos[1], Pos[2]);
- GetPointZPos(Pos[0], Pos[1], Pos[2]);
- SetNPCPos(npcid, Pos[0], Pos[1], Pos[2]+0.5);
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- new i;
- ForeachNPC(i)
- {
- if(InfoNPC[i][IsFollowing] == true)
- {
- StopObject(InfoNPC[i][ObjectMoveNPC]);
- KillTimer(InfoNPC[i][TimerMoveNPC]);
- }
- }
- return 1;
- }
- */
- stock SetNPCFacingAngle(npcid, Float:Angle)
- {
- if(IsPlayerNPC(npcid))
- {
- SetPlayerFacingAngle(npcid, Angle);
- }
- }
- stock RotateNPCToPos(npcid, const Float:PosX, const Float:PosY)
- {
- if(IsPlayerNPC(npcid))
- {
- new Float:Pos[2];
- new Float:AngleNPC;
- if(GetPlayerPos(npcid, Pos[0], Pos[1], AngleNPC))
- {
- AngleNPC = atan2((PosY-Pos[1]), (PosX-Pos[0])) + 270.0;
- SetNPCFacingAngle(npcid, (AngleNPC));
- }
- }
- }
- stock SetNPCSkin(npcid, skinid)
- {
- if(IsPlayerNPC(npcid))
- {
- SetPlayerSkin(npcid, skinid);
- }
- }
- stock GetNPCPos(npcid, &Float:PosX, Float:PosY, Float:PosZ)
- {
- if(IsPlayerNPC(npcid)) return GetPlayerPos(npcid, PosX, PosY, PosZ);
- return 1;
- }
- stock SetNPCHealth(npcid, Float:Health)
- {
- if(IsPlayerNPC(npcid))
- {
- InfoNPC[npcid][HealthNPC] = Health;
- }
- }
- stock SetNPCArmour(npcid, Float:Armour)
- {
- if(IsPlayerNPC(npcid))
- {
- InfoNPC[npcid][ArmourNPC] = Armour;
- }
- }
- stock ApplyNPCAnimation(npcid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync = 0)
- {
- if(IsPlayerNPC(npcid))
- {
- ClearAnimations(npcid);
- ApplyAnimation(npcid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
- }
- }
- stock CountAllNPC() return ToAddUpNPCCreated;
- stock KickToAllNpc()
- {
- ToAddUpNPCCreated = -1;
- new i;
- ForeachNPC(i)
- {
- Kick(i);
- }
- }
- // Hoocked functions:
- hook: public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
- {
- if(hittype == 1 && IsPlayerNPC(hitid))
- {
- if(InfoNPC[hitid][IsSpawned] == true)
- {
- new Float:Health = GetNPCHealth(hitid);
- if(GetNPCHealth(hitid) >= 0.001)
- {
- switch(weaponid)
- {
- case 22: SetNPCHealth(hitid, Health-8.25);
- case 23: SetNPCHealth(hitid, Health-13.2);
- case 24: SetNPCHealth(hitid, Health-46.2);
- case 25: SetNPCHealth(hitid, Health-49.5);
- case 26: SetNPCHealth(hitid, Health-49.5);
- case 27: SetNPCHealth(hitid, Health-39.6);
- case 28: SetNPCHealth(hitid, Health-6.6);
- case 29: SetNPCHealth(hitid, Health-8.25);
- case 30, 31: SetNPCHealth(hitid, Health-9.9);
- case 32: SetNPCHealth(hitid, Health-6.6);
- case 33: SetNPCHealth(hitid, Health-24.75);
- case 34: SetNPCHealth(hitid, Health-41.25);
- case 38: SetNPCHealth(hitid, Health-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 = GetNPCHealth(hitid);
- CallLocalFunction("OnPlayerDamgeToNPC", "ddif", hitid, playerid, weaponid, Health-HealthRest);
- }
- else
- {
- CallLocalFunction("OnNPCDeath", "ddi", hitid, playerid, weaponid);
- SetTimerEx("OnNPCSpawn", 4000, false, "d", hitid);
- ApplyNPCAnimation(hitid, "SWEET", "LaFin_Sweet", 4.1, 1, 1, 1, 1, 0, 0);
- }
- }
- }
- return 1;
- }
- hook: public OnFilterScriptInit()
- {
- ToAddUpNPCCreated = -1;
- return 1;
- }
- hook: public OnPlayerConnect(playerid)
- {
- if(IsPlayerNPC(playerid))
- {
- CallLocalFunction("OnNPCCreated", "d", playerid);
- }
- return 1;
- }
- hook: public OnPlayerDisconnect(playerid, reason)
- {
- if(IsPlayerNPC(playerid))
- {
- CallLocalFunction("OnNPCDisconnect", "di", playerid, reason);
- }
- return 1;
- }
- hook: public OnPlayerSpawn(playerid)
- {
- if(IsPlayerNPC(playerid))
- {
- SetTimerEx("OnNPCSpawn", 500, false, "d", playerid); // Fixed.
- }
- return 1;
- }
- hook: public OnNPCDeath(npcid, playerid, weaponid)
- {
- InfoNPC[npcid][IsSpawned] = false;
- return 1;
- }
- //*********
- forward OnNPCCreated(npcid);
- forward OnNPCSpawn(npcid);
- forward OnPlayerDamgeToNPC(npcid, playerid, weaponid, Float:amount);
- forward OnNPCDeath(npcid, killerid, weaponid);
- forward OnNPCDisconnect(npcid);
- // End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement