NPC question
#1

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

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

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?
Reply
#4

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

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?
Reply
#6

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

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

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

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

Bump?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)