Vehicle isn't letting into interior
#1

So I have a vehicle interior system for tropics and journeys and the vehicle isn't allowing me to enter the interior, in game is says only got the car is enterable.

Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_CTRL_BACK)
	{
		if(PlayerInfo[playerid][pInVehicle] == -1) { //Enter vehicle.
			new car = PlayerToCar(playerid, 2, 5.0);
			new vInt = IsEnterableVehicle(car);
			if(vInt != -1) {
				if(!IsPlayerInAnyVehicle(playerid)) {
					new Float:x, Float:y, Float:z;
					SendClientMessage(0, COLOR_ORANGE, "Getting Vehicle Relative pos.");
					GetVehicleRelativePos(car, x, y, z, VehicleInteriorPos[vInt][vExitX], VehicleInteriorPos[vInt][vExitY], VehicleInteriorPos[vInt][vExitZ]);
					if(IsPlayerInRangeOfPoint(playerid, 2, x, y, z)) {
					    SendClientMessage(0, COLOR_ORANGE, "checking if car is locked.");
						if(VehicleInfo[car][vLocked] == 0) {
							GetPlayerPos(playerid, PlayerInfo[playerid][EnterVehPos][0], PlayerInfo[playerid][EnterVehPos][1], PlayerInfo[playerid][EnterVehPos][2]);
							SetPlayerPos(playerid, VehicleInteriorPos[vInt][vIntX], VehicleInteriorPos[vInt][vIntY], VehicleInteriorPos[vInt][vIntZ]);
							SetPlayerVirtualWorld(playerid, car);
							SetPlayerInterior(playerid, car);
							SendClientMessage(playerid, COLOR_WHITE, "Use '/exit' or click the door hotkey to leave this vehicle.");
							if(GetPVarInt(playerid, "DrugTime") == 0) { SetPlayerWeather(playerid, 11); }
							PlayerInfo[playerid][pInVehicle] = car;
							TempFreeze(playerid);
							return 1;
						}
						else SendClientMessage(playerid, COLOR_WHITE, "This vehicle is locked!");
					}
				}
			}
		}
	}
	return 1;
}

stock PlayerToCar(playerid,type,Float:distance) {
    new Float:x, Float:y, Float:z, Float:closedist, id = -1;
    foreach(new c : Vehicle) {
        if(IsVehicleStreamedIn(c, playerid)) {
			GetVehiclePos(c,x,y,z);
			new Float:dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
			if(!closedist) {
				closedist = dist;
				id = c;
			} else {
				if(dist < closedist) {
					closedist = dist;
					id = c;
				}
			}
		}
    }
	if(id != -1) {
		GetVehiclePos(id,x,y,z);
		SendClientMessage(0, COLOR_ORANGE, "Got the car id.");
		if(IsPlayerInRangeOfPoint(playerid,distance,x,y,z)) {
			switch(type) {
				case 1: return true;
				case 2: return id;
			}
		}
	}
	if(type == 1) return false;
    return INVALID_VEHICLE_ID;
}

stock IsEnterableVehicle(id) {
	new model = GetVehicleModel(id);
	SendClientMessage(0, COLOR_ORANGE, "Got if car is enterable.");
	if(model == 508) {
		return VEHICLE_INTERIOR_JOURNEY;
	} else if(model == 427) {
		return VEHICLE_INTERIOR_ENFORCER;
	} else if(model == 416) {
		return VEHICLE_INTERIOR_AMBULANCE;
	} else if(model == 577) {
		return VEHICLE_INTERIOR_AT400;
	} else if(model == 454) {
		return VEHICLE_INTERIOR_TROPIC;
	}
	return VEHICLE_INTERIOR_INVALID;
}

//============================================//
stock IsValidCar(vehicleid) {
	if(vehicleid == -1) { return false; }
	foreach(new car : Vehicle) {
		if(car == vehicleid) {
			return true;
		}
	}
	return false;
}
//============================================//
stock ExitVehicleInterior(playerid) {
	new car = PlayerInfo[playerid][pInVehicle];
	new vwCar = GetVehicleVirtualWorld(car), intCar = VehicleInfo[car][vInterior];
	if(vwCar != 0 || intCar != 0) { TempFreeze(playerid); }
	if(IsValidCar(car)) { //Exit by car.
		new Float:x, Float:y, Float:z, intID = IsEnterableVehicle(car);
		GetVehicleRelativePos(car, x, y, z, VehicleInteriorPos[intID][vExitX], VehicleInteriorPos[intID][vExitY], VehicleInteriorPos[intID][vExitZ]);
		Streamer_UpdateEx(playerid, x, y, z, vwCar, intCar);
		SetPlayerPos(playerid, x, y, z);
		new Float:velX, Float:velY, Float:velZ;
		GetVehicleVelocity(car, velX, velY, velZ);
		if(intID == VEHICLE_INTERIOR_TROPIC) {
			if(velX > 0.5 || velY > 0.5 || velZ > 0.5) {
				SetPlayerVelocity(playerid, velX, velY, velZ+0.25);
			} else TempFreeze(playerid);
		} else if(velX < 0.5 || velY < 0.5 || velZ < 0.5) {
			TempFreeze(playerid);
		}
	} else { //Exit where you entered.
		Streamer_UpdateEx(playerid, PlayerInfo[playerid][EnterVehPos][0], PlayerInfo[playerid][EnterVehPos][1], PlayerInfo[playerid][EnterVehPos][2], vwCar, intCar);
		SetPlayerPos(playerid, PlayerInfo[playerid][EnterVehPos][0], PlayerInfo[playerid][EnterVehPos][1], PlayerInfo[playerid][EnterVehPos][2]);
	}
	SetPlayerVirtualWorld(playerid, vwCar);
	SetPlayerInterior(playerid, intCar);
	//if(GetPVarInt(playerid, "DrugTime") == 0) { SetPlayerWeather(playerid, GMWeather); }
	PlayerInfo[playerid][pInVehicle] = -1;
	return 1;
}
//============================================//
stock GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff=0.0, Float:yoff=0.0, Float:zoff=0.0)
{
    new Float:rot;
    GetVehicleZAngle(vehicleid, rot);
    rot = 360 - rot;
    GetVehiclePos(vehicleid, x, y, z);
    x = floatsin(rot,degrees) * yoff + floatcos(rot,degrees) * xoff + x;
    y = floatcos(rot,degrees) * yoff - floatsin(rot,degrees) * xoff + y;
    z = zoff + z;
}
//============================================//
stock GetOffsetFromVehicle(Float:posXx, Float:posYy, Float:posZz, vehicleid, &Float:X, &Float:Y, &Float:Z) {
	new Float:pos[3];
	GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
	new Float:rotZ;
	GetVehicleZAngle(vehicleid, rotZ);
	new Float:off[2];
	off[0] = posX - pos[0];
	off[1] = posY - pos[1];
	X = off[0]*floatcos(rotZ, degrees)+off[1]*floatsin(rotZ, degrees);
	Y = -off[0]*floatsin(rotZ, degrees)+off[1]*floatcos(rotZ, degrees);
	Z = posZ - pos[2];
	return 1;
}

stock TempFreeze(playerid)
{
	TogglePlayerControllable(playerid,false);
    SetTimerEx("TempUnfreeze", 1500, false, "i", playerid);
	return 1;
}
//============================================//
forward TempUnfreeze(playerid);
public TempUnfreeze(playerid)
{
	TogglePlayerControllable(playerid,true);
	return 1;
}
Reply


Messages In This Thread
Vehicle isn't letting into interior - by TheLeech - 23.01.2019, 13:32
Re: Vehicle isn't letting into interior - by codExpert - 23.01.2019, 14:26
Re: Vehicle isn't letting into interior - by TheLeech - 23.01.2019, 14:48

Forum Jump:


Users browsing this thread: 2 Guest(s)