Can't put NPC into vehicle -
m4karow - 04.03.2018
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...
Re: Can't put NPC into vehicle -
m4karow - 04.03.2018
anyone?
Re: Can't put NPC into vehicle -
PepsiCola23 - 04.03.2018
i think you have to create the vehicle with
PHP код:
AddStaticVehicle
Re: Can't put NPC into vehicle -
m4karow - 05.03.2018
i did... but nothing changed
Re: Can't put NPC into vehicle -
jasperschellekens - 05.03.2018
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(420, 0, 0, 0,0, 0, 1);
}
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(playerid, botvehicle, 0);
}
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.
Re: Can't put NPC into vehicle -
NaS - 05.03.2018
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.
Re: Can't put NPC into vehicle -
m4karow - 05.03.2018
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.
Re: Can't put NPC into vehicle -
NaS - 05.03.2018
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?
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
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
Re: Can't put NPC into vehicle -
NaS - 06.03.2018
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.
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
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.)
Re: Can't put NPC into vehicle -
NaS - 06.03.2018
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).
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
ok i'll try it. does it effect is i do theese things in a filterscript? if i'm right it shouldn't.
Re: Can't put NPC into vehicle -
NaS - 06.03.2018
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).
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
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;
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
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?
Re: Can't put NPC into vehicle -
NaS - 06.03.2018
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.
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
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
Re: Can't put NPC into vehicle -
NaS - 06.03.2018
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.
Re: Can't put NPC into vehicle -
m4karow - 06.03.2018
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