Anti pveh jacking
#1

Hey guys,

Im currencly making a PVeh FS, but i want anti-pveh-jacking. So if its not your pveh, you cant enter it.
Im using the variable vVehicle[]; for creating the vehicle, and im kinda stuck at the OnPlayerEnterVehicle.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    new Float:Pos[3];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( vVehicle[i] != playerid )
        {
            GetPlayerPos(i, Pos[0], Pos[1], Pos[2]);
            SetPlayerPos(i, Pos[0], Pos[1], Pos[2]);
            SendClientMessage(playerid, COLOR_RED, " ** This vehicle is not yours! ");
            RemovePlayerFromVehicle( i );
            break;
        }
    }
    return 1;
}
Atm i got this. Its working, but whenever i try to enter the vehicle, it just shows me the message 'This vehicle is not yours'.
Can someone give me a push in the right direction, so i can continue?

~Wesley
Reply
#2

Use OnPlayerStateChange. OnPlayerEnterVehicle is called when you're near a vehicle and you press ENTER.
Reply
#3

Yes i know that.
But when i do /createveh (the command to create the pveh) it creates my personal pveh. Then when i try to enter it (with the ENTER/F button) it says that the vehicle is not mines.
Reply
#4

or you can try to SetVehicleParamsEx lock the doors for everyone and SetVehicleParamsForPlayer for that player
Reply
#5

...
It does work, but not on the right way. When i enter MY PVeh, it shouldnt give me the message 'This vehicle is not yours' but just should let me enter.
I dont really know how i should check if it is my vehicle, so thats why im asking it.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    new Float:Pos[3];
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        if( vVehicle[i] != playerid )
        {
            GetPlayerPos(i, Pos[0], Pos[1], Pos[2]);
            SetPlayerPos(i, Pos[0], Pos[1], Pos[2]);
            SendClientMessage(playerid, COLOR_RED, " ** This vehicle is not yours! ");
            RemovePlayerFromVehicle( i );
            break;
        }
    }
    return 1;
}
Thats what i got atm
Reply
#6

the loop with MAX_PLAYERS is not needed - you know the playerid, and the vehicleid, thats all you need:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
	new Float:Pos[3];
	if( vVehicle[vehicleid] != playerid )
	{
		GetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
		SetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
		SendClientMessage(playerid, COLOR_RED, " ** This vehicle is not yours! ");
		RemovePlayerFromVehicle( playerid );//also remove this? the player is not yet in the car...
	}
	return 1;
}
Reply
#7

Quote:
Originally Posted by Babul
Посмотреть сообщение
the loop with MAX_PLAYERS is not needed - you know the playerid, and the vehicleid, thats all you need:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
	new Float:Pos[3];
	if( vVehicle[vehicleid] != playerid )
	{
		GetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
		SetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
		SendClientMessage(playerid, COLOR_RED, " ** This vehicle is not yours! ");
		RemovePlayerFromVehicle( playerid );//also remove this? the player is not yet in the car...
	}
	return 1;
}
This isnt working
When i enter my vehicle, i can just enter. When someone else want to enter it, he cant.
But when he creates his own vehicle, he cant enter his vehicle; but i can.
Reply
#8

i guess youre playerid 0. is there something like
Код:
vVehicle[vehicleid]=playerid;
in your /car command?
if not, all vehicle owners are playerid 0, so no wonder that all vehicles are your property (playerid 0)

edit: its a good idea to print the vehicle id, and its owner:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
	new string[128];
	format(string,sizeof(string),"vehicleid:%d vVehicle[vehicleid]:%d",vehicleid,vVehicle[vehicleid]);
	SendClientMessage(playerid,0xffffffff,string);
	new Float:Pos[3];
	if( vVehicle[vehicleid] != playerid )
	{
		GetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
		SetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
		SendClientMessage(playerid, COLOR_RED, " ** This vehicle is not yours! ");
		RemovePlayerFromVehicle( playerid );//also remove this? the player is not yet in the car...
	}
	return 1;
}
Reply
#9

I dont have vVehicle[vehicleid]=playerid; or anything familair to that.

This is what it prints
Код:
vehicleid:1 vVehicle[vehicleid]:0
Reply
#10

ok. its obvious that each vehicle got player id 0 as owner. by adding a new variable like
Код:
VehicleGotOwner[vehicleid]=0; //after createvehicle (set it to no owner)

//vVehicle[vehicleid]=playerid; //only checked if VehicleGotOwner[vehicleid]==1 will do the trick
and then checking IF a vehicle got an owner, then comparing the vVehicle[vehicleid] being playerid (owner), will solve it.

Код:
...
	if(VehicleGotOwner[vehicleid]==1)
	{
		if(vVehicle[vehicleid] != playerid )
		{
			GetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
			SetPlayerPos(playerid , Pos[0], Pos[1], Pos[2]);
			SendClientMessage(playerid, COLOR_RED, " ** This vehicle is not yours! ");
			RemovePlayerFromVehicle( playerid );//also remove this? the player is not yet in the car...
		}
	}
	else
	{
		VehicleGotOwner[vehicleid]=1;
		vVehicle[vehicleid]=playerid;
		SendClientMessage(playerid, COLOR_RED, "you stole a car");
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)