Set NPc pos. - 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)
+--- Thread: Set NPc pos. (
/showthread.php?tid=423611)
Set NPc pos. -
[D]ry[D]esert - 18.03.2013
Hello everyone.
I was wondering how to set NPC pos.
Actually i got npc without record(Free NPC), and i would like to give him weapon, teleport him, applying whatever i want to do on this NPC.
Can someone give me an example for this please ?
This what i've done.
pawn Code:
ConnectNPC("zombie"," "); // ongamemodeinit
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/bring", cmdtext, true, 10) == 0)
{
SetPlayerPos(What shall i put here ?, x,y,z);
return 1;
}
return 0;
}
Re: Set NPc pos. -
mastermax7777 - 18.03.2013
pawn Code:
ONplayerSpawn(playerid){
if(IsPlayerNPC(playerid)){
//do stuff here SetPlayerPos
//npcid = playerid
}
}
in ur example u should put the npc's ID. u can get it with what i showed u above
Re: Set NPc pos. -
[D]ry[D]esert - 18.03.2013
Quote:
Originally Posted by mastermax7777
pawn Code:
ONplayerSpawn(playerid){ if(IsPlayerNPC(playerid)){ //do stuff here SetPlayerPos //npcid = playerid } }
in ur example u should put the npc's ID. u can get it with what i showed u above
|
No clear yet ?
I know this way, but i need to get NPC's id, i want to get him using command.
Re: Set NPc pos. -
[D]ry[D]esert - 18.03.2013
Quote:
Originally Posted by [D]ry[D]esert
Not clear yet ?
I know this way, but i need to get NPC's id, i want to get him using command.
|
Just give me how to make it with command, and i will understand the rest.
Re: Set NPc pos. -
mastermax7777 - 18.03.2013
SetPlayerPos(npcid, x,y,z);
Re: Set NPc pos. -
Jstylezzz - 18.03.2013
This is just a guess, but maybe it works when you use a stock function, I've made this real quickly.
pawn Code:
stock GetNPCID(name[])
{
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerNPC(i))
{
new npcname[MAX_PLAYER_NAME];
GetPlayerName(i,npcname,MAX_PLAYER_NAME);
if(strcmp(name,npcname,true) == 0)
{
return i;
}
}
}
}
Send the NPC's name to this function, and you'll get the id (not tested).
It would be like
pawn Code:
new npcid = GetNPCID("Zombie");
SetPlayerPos(npcid,x,y,z);
It should work.
Re: Set NPc pos. -
Misiur - 18.03.2013
Assuming you have 1 npc on whole server:
pawn Code:
new ServantNPC;
//(...)
public OnPlayerConnect(playerid) {
if(IsPlayerNPC(playerid)) ServantNPC = playerid;
return 1;
}
//(...)
public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp("/bring", cmdtext, true, 6)) {
SetPlayerPos(ServantNPC, x,y,z);
return 1;
}
return 0;
}