[Include] AFNPC - Control System for NPC.
#1

Код:
  • Changelog:
    • 23/01/2014 - 4:30 - Include published.
Hi guys.

Today I present this one include that I did to be able to control the NPC's using only the native functions that SA-MP offers. First that nothing, they will have to have the file 'SAfull.hmap' and unload these files and include them in the specified folder: http://www.mediafire.com/download/ow...9jg9/AFNPC.zip


Functions:

pawn Код:
// Done by RyDeR:
native Float:GetPointZPos(const Float: fX, const Float: fY, &Float: fZ = 0.0);


// Done by me:
native CreateNPC(npcid, name[]); // Create a NPC in the Server.
native DestroyNPC(npcid); // It destroys a NPC in the Server.

native SpawnNPC(npcid);
native SetNPCPos(npcid, Float:PosX, Float:PosY, Float:PosZ);
native SetNPCPosFindZ(npcid); // It establishes the NPC in the position Z adapted in his position.
native SetNPCPosFindZEx(npcid, Float:PosX, Float:PosY); // It establishes the NPC in the position Z adapted in the declared positions.
native SetNPCFacingAngle(npcid, Float:Angle);
native RotateNPCToPos(npcid, const Float:PosX, const Float:PosY); // It does that the angle of the NPC is fixed in the positions 'X' and 'Y'
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 CountAllNPC(); // He returns NPC's quantity connected in the Server.
native KickAllNPC();
native ForeachNPC(iterate); // It crosses a loop for all the connected NPC's.


// Forward's:

forward OnNPCCreated(npcid); // Called when a NPC connects to the Server.
forward OnNPCSpawn(npcid); // Called when a NPC spawns in the Server.
forward OnPlayerDamgeToNPC(npcid, playerid, weaponid, Float:amount); // Called when one Player damages a NPC with firearms.
forward OnNPCDeath(npcid, killerid, weaponid); // Called when a NPC dies for a player.
forward OnNPCDisconnect(npcid); // Called when a NPC is disconnected.

Note: When a Player damages a NPC, the quantity of life that reduces him to the NPC is the same that when a Player damages another Player.
Note2: The animation of dies (OnNPCDeath) is established when a NPC dies for 2° time in forward.



Bugs:

Without counting previously saying, none.


Downloads:

Pastebin: [Include] AFNPC - Control System for NCP.
MediaFire: [Include] AFNPC - Control System for NCP.



Credits:

Me - Idea and Script.
Edugta. - Thanks to him I could solve a mistake where 'OnNPCSpawn' was never called.
RyDeR` - For an idea of how to do a 'RotateNPCToPos' and for 'SAfull.hmap' (https://sampforum.blast.hk/showthread.php?tid=266806).
pds2k12 - An improvement of 'ForeachNPC' -(Example use: http://pastebin.com/6SHkSj1f)-

Regards.
Reply
#2

Well done, but i will test that later.
And btw, you've to mention that you need 0.3z.
Reply
#3

Hmmm... I came here because I've seen a similar title name... I took a look into the code and it is not much different than the others, I mean, it mostly looks like you got few codes from few NPC includes and edited them, even you say you didn't, I don't think ALL the functions are perfectly working. We're friends, and I don't want to claim the name is stolen or something, but if I were in you I would modify a bit the include structure.
Reply
#4

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Hmmm... I came here because I've seen a similar title name... I took a look into the code and it is not much different than the others, I mean, it mostly looks like you got few codes from few NPC includes and edited them, even you say you didn't, I don't think ALL the functions are perfectly working. We're friends, and I don't want to claim the name is stolen or something, but if I were in you I would modify a bit the include structure.
I am not in the habit of passing so much for these sections, and simply it do not belong if there are other script's with the same title or anything. I only made him like that and also to the functions since other names did not happen to me.
In addition the system me was not so complex of creating, so it me has not passed for the mind to look for other script's to see how they were working.


EDIT: Now that recollection, 'RotateNPCToAngle' I saw of RyDeR's comment ', I forgot to mention it.



[D]ry[D]esert: Thank you, just now I add it.


Regards.
Reply
#5

People should make stuff for improving, not for the same usage.
Reply
#6

Would you be able to provide an actual download link for the .inc file, of anyone can then I'd be appreciative.
Reply
#7

Quote:
Originally Posted by Blunt
Посмотреть сообщение
Would you be able to provide an actual download link for the .inc file, of anyone can then I'd be appreciative.
Yes, it can unload it from the following link: https://www.mediafire.com/?rx34gt2jvb8m91g.

PS: Very soon they will have updates on the include, also I will try to see if I can add 'MoveNPC'.

Regards .
Reply
#8

I don't know if it's relevant, but you might also call an rcon command to increase maxnpc value (by default its in server.cfg file). Anyway it looks good, I always get confused about the NPCs functions, but not anymore, it's way simpler for me now. Don't forget to change OnPlayerWeaponShoot to OnPlayerGiveDamage now, because that callback supports damage for NPCs since 0.3z R4 version.

Good include.
Reply
#9

Does the NPC's go through San Andreas objects? That was a big problem for me when I used NPC's for a while.
Reply
#10

Alright, so I was creating a filterscript for my server testing out this include and I came across an issue with spawning the NPC, and setting the NPC's position, world and interior ids. I might be right and I might be wrong but by using this code I assume I'm correct with my code.

When /spawnnpc is executed with an available NPCID, the NPC thats supposed to have been spawned, and set at the command executor's position doesn't appear and cannot be seen anywhere.

Ignore any loose indentations, merely due to the forum mode.

Код:
COMMAND:createnpc(playerid, params[])
{
	new npcid,npcname[20], string[50];
	if(sscanf(params, "is[20]", npcid,npcname)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /createnpc [npc_id] [npc_name]");
	else
	{
	    CreateNPC(npcid, npcname);
	    npc_id++;
	    format(string,sizeof(string),"SERVER: NPC ID: %d has been created.",npc_id);
	    SendClientMessage(playerid,COLOR_WHITE,string);
	    print(string);
	}
	return 1;
}

COMMAND:deletenpc(playerid, params[])
{
    new npcid, string[50];
    if(sscanf(params, "i", npcid)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /destroynpc [npc_id]");
    else
    {
          DestroyNPC(npcid);
	  npc_id--;
	  format(string,sizeof(string),"SERVER: NPC ID: %d has been deleted.",npc_id);
	  SendClientMessage(playerid,COLOR_WHITE,string);
	  print(string);
     }
     return 1;
}

COMMAND:spawnnpc(playerid, params[])
{
        new npcid, string[50],Float:x,Float:y,Float:z,Float:angle, interior, world;
	if(sscanf(params, "i", npcid)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /spawnnpc [npc_id]");
	else
	{
	   if(IsNPCSpawned[npcid] == true) return SendClientMessage(playerid,COLOR_GREY,"SERVER: NPC ID already has been spawned.");
	   GetPlayerPos(playerid, x, y, z);
	   GetPlayerFacingAngle(playerid,angle);
	   GetPlayerVirtualWorld(playerid,world);
	   GetPlayerInterior(playerid,interior);
	   SpawnNPC(npcid);
	   SetNPCPos(npcid, x, y, z+1);
	   SetNPCFacingAngle(npcid, angle);
	   SetNPC
	   format(string,sizeof(string),"SERVER: NPC ID: %d has been spawned.",npc_id);
	   SendClientMessage(playerid,COLOR_WHITE,string);
	   print(string);
	}
        return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)