Can't put NPC into vehicle
#1

Hey

I've making a mission and i want to put NPC into vehicle.
NPC connecting and spawning well, i set it to the correct position.
Then i'm creating a vehicle with CreateVehicle and put the NPC into...
The NPC just staying on the roof of the vehicle



PutPlayerInVehicle(missionNPC, missionVehicle, 0);

the value's of the variables are correct. MissionNPC = playerid 1, missionVehicle = 1050....


npctest....



public OnNPCConnect(myplayerid)
{
printf("npctest: OnNPCConnect(My playerid=%d)", myplayerid);
}

public OnNPCSpawn()
{
printf("npctest: OnNPCSpawn");
}

cant see any of theese prints in the server log...
Reply
#2

anyone?
Reply
#3

i think you have to create the vehicle with
PHP код:
AddStaticVehicle 
Reply
#4

i did... but nothing changed
Reply
#5

First of all: Put your code between [code] tags, even if they are printfs. I don't have to explain why.
Second: Post your code. Without your code we can't help you, we don't know what u have already.

In order to successfully put a NPC in a vehicle, make sure the following is done in your script:
I will call the bot Mike in ths example.

PHP код:
new botvehicle;

public 
OnGameModeInit()
{
    
ConnectNPC("Mike","mode"); // since your NPC is already connected and standing on top of the vehicle you probably will not need this
    
    
botvehicle AddStaticVehicle(420000,001);

}

public 
OnPlayerSpawn(playerid)
{
    if(!
IsPlayerNPC(playerid)) return 0;

    new 
playername[64];
    
GetPlayerName(playerid,playername,64); // Getting the name of the bot

     
if(!strcmp(playername,"Mike",true)) {
           
PutPlayerInVehicle(playeridbotvehicle0);
    }
    return 
1;

If the code above does not work. Your problem is related to elsewhere in your script. Something is preventing the NPC from entering the vehicle.
Reply
#6

If you want to make an Idle NPC in a vehicle you need to make a recording for that.

NPCs won't enter the vehicle unless they are playing back a Vehicle NPC Recording.
Reply
#7

I started playing a record file, but the npc still stay's on the roof. Should I have to use addstaticvehicle for NPC vehicles? I have read the wiki but i didn't noticed theese vehicles (except trains, trams) have to be crated as addstaticvehicle.
Reply
#8

Quote:
Originally Posted by m4karow
Посмотреть сообщение
I started playing a record file, but the npc still stay's on the roof. Should I have to use addstaticvehicle for NPC vehicles? I have read the wiki but i didn't noticed theese vehicles (except trains, trams) have to be crated as addstaticvehicle.
Both work, CreateVehicle and AddStaticVehicle.

Did you start the recording properly after the NPC was put in the vehicle?
Reply
#9

of course no, becouse the npc does not react for putplayerinvehicle. i've loaded the default SA-MP 'npctest' npc file, and all of the callbacks wont called i does not know, why. i've put the code into the default bare gamemode too and the npc was playing back the recording well but with addstatisvehicle, (i did not tried createvehicle) so the problem is in my mode. but what could cause this? it can't be removed by a timer becouse the removing was soooo fast. maybe a callback can cause this? i've deactivated all of the anticheat and nothing changed... i'm so puzzled... this is my first npc that driving a vehicle and i'm just suffer with
Reply
#10

Quote:
Originally Posted by m4karow
Посмотреть сообщение
of course no, becouse the npc does not react for putplayerinvehicle. i've loaded the default SA-MP 'npctest' npc file, and all of the callbacks wont called i does not know, why. i've put the code into the default bare gamemode too and the npc was playing back the recording well but with addstatisvehicle, (i did not tried createvehicle) so the problem is in my mode. but what could cause this? it can't be removed by a timer becouse the removing was soooo fast. maybe a callback can cause this? i've deactivated all of the anticheat and nothing changed... i'm so puzzled... this is my first npc that driving a vehicle and i'm just suffer with
PutPlayerInVehicle must be used to put the NPC in a vehicle. This NPC will be in the vehicle then, but since NPCs don't sync any data except when playing back a recording, it looks like it isn't in.

When putting an NPC into a Vehicle, it will then call the callback OnNPCEnterVehicle() in the NPC Mode. Here you have to start the recording (it must be a vehicle recording).

Код:
public OnNPCEnterVehicle()
{
StartRecordingPlayback(PLAYER_RECORDING_TYPE_DRIVER, "myrecording");
}
If this does not work make sure callbacks like OnPlayerStateChange do not react for NPCs (it could potentially be removed from the vehicle again).
You can test this by adding

Код:
if(IsPlayerNPC(playerid)) return 1;
to the beginning of the callback.
Reply
#11

yeah i know theese parts and i want to put it to a vehicle but as i written it's stays of the roof. i've made a command that put the vehicle into the vehicle that i give and i started flooding the command (lol) but the npc just stands on the roof but he got teleported to the vehicle (and the putplayervehicle function returning with 1.)
Reply
#12

Quote:
Originally Posted by m4karow
Посмотреть сообщение
yeah i know theese parts and i want to put it to a vehicle but as i written it's stays of the roof. i've made a command that put the vehicle into the vehicle that i give and i started flooding the command (lol) but the npc just stands on the roof...
Without starting a recording this will always happen.

But first see if any callback of your mode reacts for NPCs and removes them again (I edited my post above).
Reply
#13

ok i'll try it. does it effect is i do theese things in a filterscript? if i'm right it shouldn't.
Reply
#14

Quote:
Originally Posted by m4karow
Посмотреть сообщение
ok i'll try it. does it effect is i do theese things in a filterscript? if i'm right it shouldn't.
Should work in a Filterscript but you must make sure that your gamemode does not interfere with the NPCs (like removing them from vehicles, or not letting them spawn).
Reply
#15

I have theese
Код:
public OnNPCSpawn()
{
	printf("npctest: OnNPCConnect");
  	return 1;
}
Код:
public OnNPCConnect(myplayerid)
{
	printf("npctest: OnNPCConnect(My playerid=%d)", myplayerid);
	return 1;
}
And nothing printed. Just the simply [npc:join] text that you can see in the server log, but the NPC exist. You can see the picture...


statechange is builded well, always returning with 1 and NPC-s just exceptions
Код:
if(!IsPlayerNPC(playerid))
{
....
}
return 1;
Reply
#16

I've made this now. This is how things look like now And i'm used one putplayerinvehicle...
https://ezgif.com/video-to-gif/ezgif-1-72dac90dc0.mov
or this is becouse the npc is bugged into vehicle?
Reply
#17

Quote:
Originally Posted by m4karow
Посмотреть сообщение
I have theese
Код:
public OnNPCSpawn()
{
	printf("npctest: OnNPCConnect");
  	return 1;
}
Код:
public OnNPCConnect(myplayerid)
{
	printf("npctest: OnNPCConnect(My playerid=%d)", myplayerid);
	return 1;
}
And nothing printed. Just the simply [npc:join] text that you can see in the server log, but the NPC exist. You can see the picture...


statechange is builded well, always returning with 1 and NPC-s just exceptions
Код:
if(!IsPlayerNPC(playerid))
{
....
}
return 1;
Can you show the full code related to the NPC? Most importantly the NPC Mode and the code for putting the NPC into the vehicle?

Are you sure the recording you use is correct?

The reason you don't see the print messages is because they aren't logged to the server console. NPCs are seperate processes but they don't have a console window where you'd see the messages.
Reply
#18

Quote:
Originally Posted by NaS
Посмотреть сообщение
Can you show the full code related to the NPC? Most importantly the NPC Mode and the code for putting the NPC into the vehicle?
no, it's totally unnecessary. if i could make the NPC replay the recording in a default gamemode, i think i can in my main mode the mistake is different. i think one of the callbacks returning with 0 for npc-s but i dont know which becouse i have a modular gamemode.

but this is my code in short
Код:
onplayerconnect(...)
{
 if(ismynpc)
{
 putplayerinvehicle(mynpc, createvehicle(...), 0);
}
Quote:
Originally Posted by NaS
Посмотреть сообщение
Are you sure the recording you use is correct?
yes becouse i played the same record file on the bare gamemode and it's worked fine

Quote:
Originally Posted by NaS
Посмотреть сообщение
The reason you don't see the print messages is because they aren't logged to the server console. NPCs are seperate processes but they don't have a console window where you'd see the messages.
i didn't know this, thanks
Reply
#19

Quote:
Originally Posted by m4karow
Посмотреть сообщение
no, it's totally unnecessary. if i could make the NPC replay the recording in a default gamemode, i think i can in my main mode the mistake is different. i think one of the callbacks returning with 0 for npc-s but i dont know which becouse i have a modular gamemode.

but this is my code in short
Код:
onplayerconnect(...)
{
 if(ismynpc)
{
 putplayerinvehicle(mynpc, createvehicle(...), 0);
}
yes becouse i played the same record file on the bare gamemode and it's worked fine


i didn't know this, thanks
You should put PutPlayerInVehicle into OnPlayerSpawn (after that NPC spawns), but this may not be the cause here.

Check your gamemode for other callbacks that could probably handle NPCs or remove them from vehicles, etc. otherwise I don't know what else to say. If it works on bare, it's most likely your gamemode.
Reply
#20

Quote:
Originally Posted by NaS
Посмотреть сообщение
You should put PutPlayerInVehicle into OnPlayerSpawn (after that NPC spawns), but this may not be the cause here.

Check your gamemode for other callbacks that could probably handle NPCs or remove them from vehicles, etc. otherwise I don't know what else to say. If it works on bare, it's most likely your gamemode.
yes i know
i will check all of the hooks tomorrow
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)