Problem With OnPlayerEnterVehicle
#1

Hello,

I was very confused why i compiled it and it gave me no errors. Then, i tried in game to enter the vehicle and nothing happened. I wonder why. Please, give the correct code to me to fix this thing. Thanks!

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
//------------------------------------------------------------------------------
	passenger[playerid] = ispassenger;
	if (GetPlayerSurfingVehicleID(playerid) == vehicleid)
	{
		ClearAnimations(playerid);
	}
	if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 592 && ispassenger == 1)
	{
		SetPlayerInterior(playerid,9);
		SetPlayerFacingAngle(playerid,0.0);
		SetPlayerPos(playerid, 315.856170,1024.496459,1949.797363);
		SetCameraBehindPlayer(playerid);
		InAndrom[playerid]=vehicleid;
	}
	if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 519 && ispassenger)
	{
		if (!ShamalExists(vehicleid))
		{
			CreateShamalInt(vehicleid, float(randomEx(3000)), float(randomEx(3000)), float(random(100)+800));
		}
		SetPlayerPosInShamal(playerid, vehicleid);
		InShamal[playerid] = vehicleid;
	}
	#if defined ENABLE_SPEC
	for(new xp=0; xp<MAX_PLAYERS; xp++) {
	    if(GetPlayerState(xp) == PLAYER_STATE_SPECTATING && PlayerInfo[xp][SpecID] == playerid) {
	        TogglePlayerSpectating(xp, 1);
	        PlayerSpectateVehicle(xp, vehicleid);
	        PlayerInfo[xp][SpecType] = ADMIN_SPEC_TYPE_VEHICLE;
		}
	}
	#endif
	if(onsys[vehicleid] == 1) {
		if(passenger[playerid] == 0) {
			if(PlayerInfo[playerid][LoggedIn] == 1) {
				if (strcmp(VehicleInfo[vehicleid][owner],PlayerInfo[playerid][name],false) == 0) {
					new string[128];
					format(string, sizeof(string), "~n~~n~~n~~g~Welcome to your %s %s, please drive carefully!", VehicleInfo[vehicleid][name], PlayerInfo[playerid][name]);
					GameTextForPlayer(playerid, string, 3000, 4);
				//	SendClientMessage(playerid, COLOR_GREEN, string);
					return 1;
				}
				if (strcmp(VehicleInfo[vehicleid][owner],DEFAULT_OWNER,false) == 0) {
					if(VehicleInfo[vehicleid][buybar] == 1) {
						new string[128];
						format(string,sizeof(string),"~n~~n~~n~~r~This %s has been set as non-buyable by server administration!", VehicleInfo[vehicleid][name]);
						GameTextForPlayer(playerid, string, 3000, 4);
					//	SendClientMessage(playerid, COLOR_BRIGHTRED, string);
						return 1;
					}
					new string[128];
					format(string, sizeof(string), "~n~~n~~n~~y~This %s is for sale and costs $%d, type /vmenu to see vehicle options.",VehicleInfo[vehicleid][name], VehicleInfo[vehicleid][vehiclecost]);
					GameTextForPlayer(playerid, string, 3000, 4);
				//	SendClientMessage(playerid, COLOR_YELLOW, string);
					return 1;
				}
				else {
					new string[128];
					format(string, sizeof(string), "~n~~n~~n~~r~This %s belongs to %s, and cannot be purchased.", VehicleInfo[vehicleid][name], VehicleInfo[vehicleid][owner]);
					GameTextForPlayer(playerid, string, 3000, 4);
				//	SendClientMessage(playerid, COLOR_BRIGHTRED, string);
					return 1;
				}
			}
			else {
			    new playername[128];
			    GetPlayerName(playerid,playername,sizeof(playername));
			    if (strcmp(VehicleInfo[vehicleid][owner],playername,false) == 0) {
					new string[128];
					format(string, sizeof(string), "~n~~n~~n~~g~Welcome to your %s %s, please drive carefully! ~n~Remember, you must be logged in to acces vehicle controls.", VehicleInfo[vehicleid][name], playername);
					return GameTextForPlayer(playerid, string, 3000, 4);
				}
		       	if (strcmp(VehicleInfo[vehicleid][owner],DEFAULT_OWNER,false) == 0) {
					if(VehicleInfo[vehicleid][buybar] == 1) {
		           		new string[128];
			        	format(string,sizeof(string),"~n~~n~~n~~r~This %s has been set as non-buyable by server administration!", VehicleInfo[vehicleid][name]);
			        	return GameTextForPlayer(playerid, string, 3000, 4);
				   	}
				   	new string[128];
		   	       	format(string, sizeof(string), "~n~~n~~n~~y~This %s is for sale and costs $%d, ~n~You must be logged in to purchase a vehicle.",VehicleInfo[vehicleid][name], VehicleInfo[vehicleid][vehiclecost]);
		   	       	return GameTextForPlayer(playerid, string, 3000, 4);
				}
				else {
		        	new string[128];
		          	format(string, sizeof(string), "~n~~n~~n~~r~This %s belongs to %s, and cannot be purchased.", VehicleInfo[vehicleid][name], VehicleInfo[vehicleid][owner]);
		          	return GameTextForPlayer(playerid, string, 3000, 4);
				}
			}
		}
	}
	return 1;
}
Some pictures...



Try to see it again...



And for the last time.... It didn't show me anything like messages and GameTexts...



Thanks!
Reply
#2

There's already a "vehicleid" parameter so don't use GetPlayerVehicleID. Besides that, this callback is called when the player starts to enter the vehicle, i.e. when they press F or Enter. This action can still be aborted. Better to use OnPlayerStateChange if you want the action to happen when the player is actually in the vehicle.
Reply
#3

Okay, Can you give me the correct code for it ? Or fixing it.
Reply
#4

Please, Give the right code to me, Thanks.
Reply
#5

You are not a passanger this code just a passanger on u car or u nrg
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)