SA-MP Forums Archive
NPC question - 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: NPC question (/showthread.php?tid=351965)



NPC question - TheArcher - 17.06.2012

Is possibile to put a NPC in a vehicle while he's on foot?


Re: NPC question - Calgon - 17.06.2012

You should be able to apply normal player functions to NPCs from your gamemode, so I don't think it should be a problem.

Also, judging by this, it should be fine.


Re: NPC question - TheArcher - 17.06.2012

Quote:
Originally Posted by Calgon
Посмотреть сообщение
You should be able to apply normal player functions to NPCs from your gamemode, so I don't think it should be a problem.

Also, judging by this, it should be fine.
That looks like a after a NPC is created it automaticaly gets in a car. My question was if i can put a NPC in a car after its spawned and everything.

E.g NPC named Dexter already spawned and its idle, i want to put him in a car by doing a command, is it possibile?


Re: NPC question - Calgon - 17.06.2012

That shouldn't make a significant difference at all... The code uses the OnPlayerSpawn callback, the only difference is you'll have to perform a loop to find Dexter's ID for the command.


Re: NPC question - TheArcher - 17.06.2012

Quote:
Originally Posted by Calgon
Посмотреть сообщение
That shouldn't make a significant difference at all... The code uses the OnPlayerSpawn callback, the only difference is you'll have to perform a loop to find Dexter's ID for the command.
I still dont get it, could you make an example?


Re: NPC question - Calgon - 17.06.2012

pawn Код:
CMD:getonmyhorse(playerid, params[]) {
    new
        iVehicle = 6,
        iSeat = 0,
        szPlayerName[MAX_PLAYER_NAME];
       
    foreach(Bot, i) {
        GetPlayerName(i, szPlayerName, MAX_PLAYER_NAME);
           
        if(!strcmp(szPlayerName, "Dexter", false)) {
            PutPlayerInVehicle(i, iVehicle, iSeat);
        }
    }
    return 1;
}
Something like this? This code will put Dexter in vehicle ID 6 as the driver.


Re: NPC question - TheArcher - 17.06.2012

I tried to do it following your example without any result, here's my test code (used in a FS)
pawn Код:
public OnFilterScriptInit()
{
    ConnectNPC("Dexter", "mynpc");
    return 1;
}
pawn Код:
CMD:npcinvehicle(playerid, params[])
{
    new target;
    if(sscanf(params, "d", target)) return SendClientMessage(playerid, -1 , " syntax: /npcinvehicle [npcid] ");
    if(IsPlayerNPC(target))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new vehicle = GetPlayerVehicleID(playerid);
            new szPlayerName[MAX_PLAYER_NAME];

            foreach(Bot, i)
            {
                GetPlayerName(i, szPlayerName, MAX_PLAYER_NAME);

                if(!strcmp(szPlayerName, "Dexter", false)) {
                    PutPlayerInVehicle(i, vehicle, 1);
                }
            }
        }
    }
    return 1;
}



Re: NPC question - Calgon - 18.06.2012

Your code is just confusing now. The loop was to find the name of Dexter, but you're using 'npcid' so you already know the ID. You can just use PutPlayerInVehicle... The code is self-explanatory.


Re: NPC question - TheArcher - 18.06.2012

I tried with this now:

pawn Код:
CMD:npcinvehicle(playerid, params[])
{
    new target;
    if(sscanf(params, "d", target)) return SendClientMessage(playerid, -1 , " syntax: /npcinvehicle [npcid] ");
    if(IsPlayerNPC(target))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new vehicle = GetPlayerVehicleID(playerid);
            new szPlayerName[MAX_PLAYER_NAME];

            GetPlayerName(target, szPlayerName, MAX_PLAYER_NAME);

            if(!strcmp(szPlayerName, "Dexter", false)) {
                PutPlayerInVehicle(target, vehicle, 1);
            }
        }
    }
    return 1;
}
Still no results.

Edit: I did a debug and it goes through all phases the problem is why the NPC doesn't enter the vehicle, the code seems correct.


Re: NPC question - TheArcher - 18.06.2012

Bump?