Set NPc pos.
#1

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;
}
Reply
#2

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
Reply
#3

Quote:
Originally Posted by mastermax7777
View Post
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.
Reply
#4

Quote:
Originally Posted by [D]ry[D]esert
View Post
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.
Reply
#5

SetPlayerPos(npcid, x,y,z);
Reply
#6

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.
Reply
#7

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)