(Script) NPCAnswer - stock
#1

#define MAX_NPCS (number, the npc that what you have.)
(example)
i have 3 npcs.
#define MAX_NPCS 3


stock NPCAnswer(playerid, ask[], ans[], text[]) // Base Made by [Star]Panic.
{ // Source Made by [Pro]Master, Zenis Transco (Korean)


new string[256];
if(strcmp(ask, text, true) == 0)
{
for(new npc=0; npc<MAX_NPCS; npc++)
{
new NPCName[MAX_PLAYER_NAME];
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerName(npc,NPCName,sizeof(NPCName));
if(IsPlayerNPC(npc))
{
if(IsPlayerInRangeOfPoint(npc, 10.0, X,Y,Z))
{
if(GetClosestNPC(playerid))
{
format(string, sizeof(string), "%s: %s.", NPCName, ans);
SendClientMessageToAll(0xFFFFFFFA, string);
TurnPlayerFaceToPlayer(npc,playerid);
return 1;
}
}
}
}
}
return 1;
}
stock NPCAnswer2(playerid, ask[], ans1[], ans2[], text[]) // Base Made by [Star]Panic.
{ // Source Made by [Pro]Master, Zenis Transco.
new string[256];
if(strcmp(ask, text, true) == 0)
{
for(new npc=0; npc<MAX_NPCS; npc++)
{
new NPCName[MAX_PLAYER_NAME];
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerName(npc,NPCName,sizeof(NPCName));
if(IsPlayerNPC(npc))
{
if(IsPlayerInRangeOfPoint(npc, 10.0, X,Y,Z))
{
if(GetClosestNPC(playerid))
{
new Say = random(2);
if(Say == 0){format(string, sizeof(string), "%s: %s.", NPCName, ans1);}
if(Say == 1){format(string, sizeof(string), "%s: %s.", NPCName, ans2);}
SendClientMessageToAll(0xFFFFFFFA, string);
TurnPlayerFaceToPlayer(npc,playerid);
return 1;
}
}
}
}
}
return 1;
}


stock NPCAnswer3(playerid, ask[], ans1[], ans2[], ans3[], text[]) // Base Made by [Star]Panic.
{ // Source Made by [Pro]Master, Zenis Transco.
new string[256];
if(strcmp(ask, text, true) == 0)
{
for(new npc=0; npc<MAX_NPCS; npc++)
{
new NPCName[MAX_PLAYER_NAME];
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerName(npc,NPCName,sizeof(NPCName));
if(IsPlayerNPC(npc))
{
if(IsPlayerInRangeOfPoint(npc, 10.0, X,Y,Z))
{
if(GetClosestNPC(playerid))
{
new Say = random(3);
if(Say == 0){format(string, sizeof(string), "%s: %s.", NPCName, ans1);}
if(Say == 1){format(string, sizeof(string), "%s: %s.", NPCName, ans2);}
if(Say == 2){format(string, sizeof(string), "%s: %s.", NPCName, ans3);}
SendClientMessageToAll(0xFFFFFFFA, string);
TurnPlayerFaceToPlayer(npc,playerid);
return 1;
}
}
}
}
}
return 1;
}


stock TurnPlayerFaceToPlayer(playerid, facingtoid)
{
new Float:angle;
new Float:misc = 5.0;
new Float, Float:y, Float:z;
new Float:ix, Float:iy, Float:iz;
GetPlayerPos(facingtoid, x, y, z);
GetPlayerPos(playerid, ix, iy, iz);
angle = 180.0-atan2(ix-x,iy-y);
angle += misc;
misc *= -1;
SetPlayerFacingAngle(playerid, angle+misc);
}

HOW TO USE IT ?
(Example)

public OnPlayerText(playerid, text[])
{
NPCAnswer(playerid,"Hey","What...",text);
NPCAnswer2(playerid,"Hmm","Hmmmm..","Have you any ploblem sir?",text);
NPCAnswer3(playerid,"Fuck","Don't say like that.","Sorry?","Pardon?",text);
return 1;
}

Good working now.

Sorry to my bad english .


If you want to see the server,
Message to me plz.
Reply
#2

You said that it's working now, but there is still a theoretical problem within your code. When you call random(), you need to know that it starts returning values from and including 0, like this:
Код:
random(1) -> 0
random(2) -> 0, 1
random(3) -> 0, 1, 2
random(4) -> 0, 1, 2, 3
...
From this, you should be able to see your problem. You set the value to 'Say', and then exclude 0 from it's returned values. Do this instead:
pawn Код:
if(Say == 0) ...
else if(Say == 1) ... // This is for NPCAnswer2().
else if(Say == 2) ... // This is for NPCAnswer3().
Check out the wiki and pawn-lang.pdf for information on random().

~Cueball~
Reply
#3

Quote:
Originally Posted by Cuecumber
You said that it's working now, but there is still a theoretical problem within your code. When you call random(), you need to know that it starts returning values from and including 0, like this:
Код:
random(1) -> 0
random(2) -> 0, 1
random(3) -> 0, 1, 2
random(4) -> 0, 1, 2, 3
...
From this, you should be able to see your problem. You set the value to 'Say', and then exclude 0 from it's returned values. Do this instead:
pawn Код:
if(Say == 0) ...
else if(Say == 1) ... // This is for NPCAnswer2().
else if(Say == 2) ... // This is for NPCAnswer3().
Check out the wiki and pawn-lang.pdf for information on random().

~Cueball~
thank you,
Reply
#4

please use [pawn] tags
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)