Riding along in NPC vehicles


#1

Earlier today I was attempting to create a script which allows you to hop into the back seats of NPC vehicles and ride along. Every time I would get into a vehicle, my character would eventually jump out after some time. I was wondering if there is a way to trick the player script into thinking the person driving is an actual player?


#2

Try this and get back to me
keep in mind have it set to this until they press F


local vehicle = (Use closest vehicle native or whichever entity it is) 
SetVehicleDoorsLocked(vehicle, 4)

4 will result in the vehicle being able to enter but not exit so they will be able to get in but not get out, so what you’ll need to do is when they press F to get out you’ll need to allow them to exit the vehicle at that time, its not a perfect method but it may work let me know keep me posted :slight_smile: Hopefully I helped
a bit.


#3

Nope, for some reason an inner function is overrides this when I get into a npc vehicle.
@KrizFrost


#4

This would be dirty and could cause lots of issues and is probably the dumbest possible idea ever however…

You could try to set the vehicle as a mission entity, then once you exit set it as no longer needed for instance, something like…

Checking to see if the driver seat is available, if it is not, set the vehicle the ped is in a mission entity. Once the player gets out, then you can set it as no longer needed…

Again, dirty and stupid way to try to work around it but.


#5

Glad you have assisted him he sat waiting for help for 4 hours and I finally just gave him something to work with, never said it was good, Never said it was clean, didn’t say it wouldn’t cause problems but I’m glad you’ve stepped in and provided some knowledge to assist him with it considering nobody else would or has.


#6

Hi Kriz,

I may have misunderstood your message but I hope you did not take my comment as a bash to your reply what so ever. In fact, I didn’t even review your post - I apologize, I was calling my own way a possibly dirty way! I hope I was able to assist him in some form.

I’m working with another community member in creating a NPC driven public transportation bus to be released eventually, hopefully that will shed some light on the use of AI. There may be a chance an element can shine some better light on the subject being that he’s trying to use AI to do this.

I will say there is a AI taxi resource already he may be able to take a peek at to get some information. What might help too is a bit more information as to what he’s already done and what he means by “hopping in”?


#7

This also does not work, the player still gets out of the vehicle after a few seconds or less.


#9

Posting a follow up here, because well - it’s da forums and it’s searchable so anyone who comes across this - the information may help them.

Consider setting a relationship group…

empty, driver_group = AddRelationshipGroup("bus_driver")
SetRelationshipBetweenGroups(0, driver_group, GetHashKey("PLAYER"))
SetRelationshipBetweenGroups(0, GetHashKey("PLAYER"), driver_group)


SetPedRelationshipGroupHash(ped, driver_group)```

 [8:01 PM] tomgie: Alright, that worked
 [8:02 PM] tomgie: Interesting
 [8:05 PM] haIIux: Setting the relationship group worked?
 [8:08 PM] tomgie: kind of

#10

Alright I finally figured it out, before setting the relationship, you must set the vehicle and the ped as a mission vehicle


#11

Does this propagate?
I mean, if player 18 sets a ped to be relationship status 0 to them, will it sync and become relationship status 0 to player 4 as well?
All players are in the PLAYER group by default, so it makes sense if it does.

Maybe create a relationship group called “bus_passenger” so it can be removed from the player when they leave the bus? Maybe it’s not a problem anyway?
I’m just trying to figure out this relationship group thing. Interesting stuff.