Vehicle isn't letting into interior
#3

Quote:
Originally Posted by codExpert
View Post
system doesn't need to consider vehicle relative positsion and other useless things, when system finds nearest vehicle then just put player into interior and everything is working like it needs to be.
PHP Code:
//vehicle ids start from 1
public OnPlayerKeyStateChange(playeridnewkeysoldkeys){
    if(
newkeys KEY_CTRL_BACK)    {
        if(
PlayerInfo[playerid][pInVehicle] != || !IsPlayerInAnyVehicle(playerid))return 1;
        
//finding nearest vehicle
        
new nearestVeh=getNearestVehicle(playerid,5.0),
        if(!
nearestVeh)return SendClientMessage(playeridCOLOR_ORANGE"you aren't near to any vehicle!");
        if(
VehicleInfo[nearestVeh][vLocked])return SendClientMessage(playeridCOLOR_ORANGE"vehicle is locked!");
        
//finding nearest vehicle model
        
new vehInt=getVehIntFromModel(GetVehicleModel(nearestVeh));
        if(
vehInt==VEHICLE_INTERIOR_INVALID)return SendClientMessage(playeridCOLOR_ORANGE"not enterable vehicle!");
        
//putting player into interior
        
GetPlayerPos(playeridPlayerInfo[playerid][EnterVehPos][0], PlayerInfo[playerid][EnterVehPos][1], PlayerInfo[playerid][EnterVehPos][2]);
        
SetPlayerPos(playeridVehicleInteriorPos[vehInt][vIntX], VehicleInteriorPos[vehInt][vIntY], VehicleInteriorPos[vehInt][vIntZ]);
        
SetPlayerVirtualWorld(playeridnearestVeh);
        
SetPlayerInterior(playeridnearestVeh);
        
PlayerInfo[playerid][pInVehicle] = nearestVeh;
        
SendClientMessage(playeridCOLOR_WHITE"Use '/exit' or click the door hotkey to leave this vehicle.");
        
TempFreeze(playerid);
    }
    return 
1;
}
//vehicle related functions
getNearestVehicle(playerid,Float:radius){
    new 
lastVeh=0,Float:xFloat:yFloat:z;
    
GetPlayerPos(playerid,x,y,z);
    foreach(new 
Vehicle){
        if( (
dis=GetVehicleDistanceFromPoint(playeridxyz)) <= radius ){
            
radius=dis;
            
lastVeh=i;
        }
    }
    return 
lastVeh;
}
getVehIntFromModel(model){
    if(
model == 508)return VEHICLE_INTERIOR_JOURNEY;
    if(
model == 427)return VEHICLE_INTERIOR_ENFORCER;
    if(
model == 416)return VEHICLE_INTERIOR_AMBULANCE;
    if(
model == 577)return VEHICLE_INTERIOR_AT400;
    if(
model == 454)return VEHICLE_INTERIOR_TROPIC;
    return 
VEHICLE_INTERIOR_INVALID;
}
exitFromVehInt(pid){
    if(!
PlayerInfo[pid][pInVehicle])return 1;
    
SetPlayerPos(pidPlayerInfo[pid][EnterVehPos][0], PlayerInfo[pid][EnterVehPos][1], PlayerInfo[pid][EnterVehPos][2]);
    
SetPlayerVirtualWorld(pid0);
    
SetPlayerInterior(pid0);
    
PlayerInfo[pid][pInVehicle]=0;
    return 
1;
}
//player related functions
tempFreeze(pid){
    
TogglePlayerControllable(playerid,false);
    return 
SetTimerEx("tempUnfreeze"1500false"i"playerid);
}
forward tempUnfreeze(playerid);
public 
tempUnfreeze(playerid){
    return 
TogglePlayerControllable(playerid,true);

undefined symbal dis
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: 1 Guest(s)