NPC problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: NPC problem (
/showthread.php?tid=276394)
NPC problem -
Jack Shred - 13.08.2011
Hello there,
I'm trying to let an NPC response whenever a player near the NPC says anything in a sentence including 'door'.
I tried three ways, but none of 'em work.
I'd appreciate any help ;d
Код:
else if((strcmp("door", tmp, true, strlen(tmp)) == 0) && (strlen(tmp) == strlen("door")))
{
new NPCID = GetPlayerIDFromName("Cadet_Two");
new Float:x,Float:y,Float:z;
GetPlayerPos(NPCID,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,15,x,y,z)) //Checking if you're near the NPC
{
if(!IsACop(playerid) || !IsAnAgent(playerid))
{
SetPlayerChatBubble(NPCID, "I'm sorry sir, but you're not an officer", 0xFF0000FF, 100.0, 3000);
}
else if(SFPD_Door[Opened] == 0)
{
MoveObject(SFPD_Door[ObjectID3], 253.19029236, 106.5986328125, 1002.21875000, 1.50);
MoveObject(SFPD_Door[ObjectID4], 253.19029236, 111.578125, 1002.21875000, 1.50);
SFPD_Door[Opened] = 2; SFPD_Door[TimerID]= SetTimer("PDDoorCheck", 5000, 0);
MoveObject(SFPD_Door[ObjectID3], 253.19029236, 106.5986328125, 1002.21875000, 1.50);
MoveObject(SFPD_Door[ObjectID4], 253.19029236, 111.578125, 1002.21875000, 1.50);
SFPD_Door[Opened] = 2; SFPD_Door[TimerID]= SetTimer("PDDoorCheck", 5000, 0);
SetPlayerChatBubble(NPCID, "Certainly sir, the doors have been opened.", 0xFF0000FF, 100.0, 3000);
}
}
}
GetPlayerIDFromName:
Код:
stock GetPlayerIDFromName(const playername[], partofname=0)
{
new i;
new playername1[64];
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,playername1,sizeof(playername1));
if (strcmp(playername1,playername,true)==0)
{
return i;
}
}
}
new correctsigns_userid=-1;
new tmpuname[128];
new hasmultiple=-1;
if(partofname)
{
for (i=0;i<MAX_PLAYERS;i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i,tmpuname,sizeof(tmpuname));
if(!strfind(tmpuname,playername1[partofname],true, 0))
{
hasmultiple++;
correctsigns_userid=i;
}
if (hasmultiple>0)
{
return -2;
}
}
}
}
return correctsigns_userid;
}
Re: NPC problem -
Jack Shred - 13.08.2011
I'm willing to use another method aswell
Re: NPC problem -
Adil - 14.08.2011
pawn Код:
public OnPlayerText(playerid, text[])
{
if(strfind(text, "door", true) != -1)
{
new NPCID = GetPlayerIDFromName("Cadet_Two");
new Float:x,Float:y,Float:z;
GetPlayerPos(NPCID,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,15,x,y,z))
{
if(IsACop(playerid) || IsAnAgent(playerid))
{
if(SFPD_Door[Opened] == 0)
{
MoveObject(SFPD_Door[ObjectID3], 253.19029236, 106.5986328125, 1002.21875000, 1.50);
MoveObject(SFPD_Door[ObjectID4], 253.19029236, 111.578125, 1002.21875000, 1.50);
SFPD_Door[Opened] = 2; SFPD_Door[TimerID]= SetTimer("PDDoorCheck", 5000, 0);
MoveObject(SFPD_Door[ObjectID3], 253.19029236, 106.5986328125, 1002.21875000, 1.50);
MoveObject(SFPD_Door[ObjectID4], 253.19029236, 111.578125, 1002.21875000, 1.50);
SFPD_Door[Opened] = 2; SFPD_Door[TimerID]= SetTimer("PDDoorCheck", 5000, 0);
SetPlayerChatBubble(NPCID, "Certainly sir, the doors have been opened.", 0xFF0000FF, 100.0, 3000);
}
}
else
{
SetPlayerChatBubble(NPCID, "I'm sorry sir, but you're not an officer", 0xFF0000FF, 100.0, 3000);
}
}
}
return 1;
}