check player name is vehicle owner name (help!)
#1

Ok so I just want it so this command checks if the PLAYER_NAME trying to use the command is = to the VEHICLEID's OWNER_NAME

The vehicles are stored in scriptfiles in avs in cars

They get saved as 1, 2, 3, 4, etc (each vehicles ID)

In the file is a line that sais..

Owner=Tyrone_Badman (just an example)

Here is the code...

Код:
CMD:vlock(playerid, params[])
{
	new vehicleid;
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		vehicleid = GetPlayerVehicleID(playerid);
	}
	else
	{
		vehicleid = GetClosestVehicle(playerid);
		if(!PlayerToVehicle(playerid, vehicleid, 5.0)) vehicleid = 0;
	}
	if(!vehicleid) return SendClientMessage(playerid, COLOR_RED, "You are not close to a vehicle!");
	new id = GetVehicleID(vehicleid);
	if(!IsValidVehicle(id)) return SendClientMessage(playerid, COLOR_RED, "You don't have the keys for this vehicle!");
	if(strcmp(PlayerName(playerid)) ==  VehicleOwner[vehicleid])
		return SendClientMessage(playerid, COLOR_RED, "You don't have the keys for this vehicle!");
	new engine, lights, alarm, doors, bonnet, boot, objective;
	GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	if(doors == 1)
	{
		doors = 0;
		VehicleLock[id] = 0;
		GameTextForPlayer(playerid, "~g~doors unlocked", 3000, 6);
	}
	else
	{
		doors = 1;
		VehicleLock[id] = 1;
		GameTextForPlayer(playerid, "~r~doors locked", 3000, 6);
	}
	SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	SaveVehicle(id);
	return 1;
}
This is the line I put into the code trying to get it to work but failed.. Not sure how to write it!

Код:
	if(strcmp(PlayerName(playerid)) ==  VehicleOwner[vehicleid])
Any help on this would be muchly appreciated! I haven't been coding long so sometimes I'm not too sure how to write something that I think of!

EDIT: EDIT: EDIT: EDIT: EDIT:

This is the original code but was not working.. We didn't notice as first but I came in day today and was unable to use my vehicle with /vlock it said I did not have the keys

Код:
CMD:vlock(playerid, params[])
{
	new vehicleid;
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		vehicleid = GetPlayerVehicleID(playerid);
	}
	else
	{
		vehicleid = GetClosestVehicle(playerid);
		if(!PlayerToVehicle(playerid, vehicleid, 5.0)) vehicleid = 0;
	}
	if(!vehicleid) return SendClientMessage(playerid, COLOR_RED, "You are not close to a vehicle!");
	new id = GetVehicleID(vehicleid);
	if(!IsValidVehicle(id)) return SendClientMessage(playerid, COLOR_RED, "You don't have the keys for this vehicle!");
	if(GetPlayerVehicleAccess(playerid, id) < 2)
		return SendClientMessage(playerid, COLOR_RED, "You don't have the keys for this vehicle!");
	new engine, lights, alarm, doors, bonnet, boot, objective;
	GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	if(doors == 1)
	{
		doors = 0;
		VehicleLock[id] = 0;
		GameTextForPlayer(playerid, "~g~doors unlocked", 3000, 6);
	}
	else
	{
		doors = 1;
		VehicleLock[id] = 1;
		GameTextForPlayer(playerid, "~r~doors locked", 3000, 6);
	}
	SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	SaveVehicle(id);
	return 1;
}
EDIT EDIT EDIT 2

Here is the GetPlayerVehicleAccess (might be something wrong here instead)

Код:
GetPlayerVehicleAccess(playerid, vehicleid)
{
	if(IsValidVehicle(vehicleid))
	{
		if(VehicleCreated[vehicleid] == VEHICLE_DEALERSHIP)
		{
			if(IsAdmin(playerid, 1))
			{
				return 1;
			}
		}
		else if(VehicleCreated[vehicleid] == VEHICLE_PLAYER)
		{
			if(strcmp(VehicleOwner[vehicleid], PlayerName(playerid)) == 0)
			{
				return 2;
			}
			else if(GetPVarInt(playerid, "CarKeys") == vehicleid)
			{
				return 1;
			}
		}
	}
	else
	{
		return 1;
	}
	return 0;
}
Reply
#2

Ignore all this.. I was stoned and made a stupid mistake..

When I had the cars made my name was Tyrone_Badman and when I logged in today I put Tyrone_BadMan

The vehicle system is case sensitive..... I found this out after hours or brain dead lol...

EPIC FAIL! LOL!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)