SA-MP Forums Archive
SetVehicleParamsEx problems - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetVehicleParamsEx problems (/showthread.php?tid=634491)



SetVehicleParamsEx problems - TheAngryBird - 20.05.2017

Код:
	if((newkeys & KEY_YES) && !(oldkeys & KEY_YES))
	{
		new NearestVehicleID = GetClosestVehicle(playerid);
		if(!PlayerToVehicle(playerid, NearestVehicleID, 3.0)) NearestVehicleID = 0;
		new Float:NearestVehiclePosX, Float:NearestVehiclePosY, Float:NearestVehiclePosZ;
		GetVehiclePos(NearestVehicleID, NearestVehiclePosX, NearestVehiclePosY, NearestVehiclePosZ);
		new playerName[MAX_PLAYER_NAME];
		GetPlayerName(playerid,playerName,sizeof playerName);
	    if(IsPlayerInAnyVehicle(playerid))
	    {
	        Dialog_Show(playerid, DIALOG_VEHICLEMENU, DIALOG_STYLE_LIST, "Vehicle", "Engine\nLight\nHood\nBoot\nDoors\nWindows\nPark", "Ok", "Cancel");
	    }
	    else
	    {
	        if(IsPlayerInRangeOfPoint(playerid, 3.0, NearestVehiclePosX, NearestVehiclePosY, NearestVehiclePosZ))
	        {
	    		if(IsVehiclePrivate(NearestVehicleID))
	    		{
	    		    if(!strcmp(playerName,PrivateVehicles[ConvertVID(NearestVehicleID)][_owner])) return 0;
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx(NearestVehicleID, engine, lights, alarm, doors, bonnet, boot, objective);
	    		    if(doors == VEHICLE_PARAMS_OFF)
	    		    {
	    		    	SetVehicleParamsEx(NearestVehicleID, engine, lights, alarm, VEHICLE_PARAMS_ON, bonnet, boot, objective);
	    		    	SendClientMessage(playerid, -1, "your vehicle is now locked");
	    		    }
	    		    if(doors == VEHICLE_PARAMS_ON)
	    		    {
	    		    	SetVehicleParamsEx(NearestVehicleID, engine, lights, alarm, VEHICLE_PARAMS_OFF, bonnet, boot, objective);
	    		    	SendClientMessage(playerid, -1, "your vehicle is now unlocked");
	    		    }
		        }
		        else
		        {
		        }
	        }
	    }
	}
when y press Y , i can start/stop engine from inside the car so it work fine.
but door wont lock/unlock ? ( from outside )
i know its just the door lock part that isnt working because if i add a message right before if(doors == VEHICLE_PARAMS_OFF) i reveive the message.
same if i do a command. im playing with this bug since 2 days and cant find anything.
tried different includes , different codes... no luck.
PS if i add a message that give the nearest vehicle id , then i get the right id. this is not the problem.


Re: SetVehicleParamsEx problems - DobbysGamertag - 20.05.2017

Are you setting the parameters beforehand?

"If a parameter is unset (SetVehicleParamsEx not used beforehand) the value will be -1 ('unset')." - Try changing
pawn Код:
if(doors == VEHICLE_PARAMS_OFF
//to
if(doors != VEHICLE_PARAMS_ON)
Possibly adding:
pawn Код:
//Before the if(doors == VEHICLE_PARAMS_OFF)
if(doors == VEHICLE_PARAMS_UNSET)
{
    SendClientMessage(playerid, -1, "Vehicle params are unset");
}
As an extra debug step might help.


Re: SetVehicleParamsEx problems - StrikerZ - 20.05.2017

I had that issue too. I fixed it by using
PHP код:
if(engine == -1engine 0;
    if(
lights == -1lights 0;
    if(
alarm == -1alarm 0;
    if(
doors == -1doors 0;
    if(
boot == -1boot 0;
    if(
objective == -1objective 0



Re: SetVehicleParamsEx problems - TheAngryBird - 20.05.2017

thanks for the help. same thing.
but i noticed it doesnt return any vehicle ID now. it was doing yesterday and i changed nothing but add sendclientmessage since then.
ill re-write my code completly

EDIT : it give id 1999 ?? WTF

Код:
	if((newkeys & KEY_YES) && !(oldkeys & KEY_YES))
	{
		new NearestVehicleID = GetClosestVehicle(playerid, 3.0);
		new string[128];
		format(string, sizeof(string), "ID %i ", NearestVehicleID);
		SendClientMessage(playerid, -1, string);
Код:
stock GetClosestVehicle(playerid, Float:range)
{
    new     Float:p_X;
    new     Float:p_Y;
    new     Float:p_Z;

    new     Float:Distance;
    new     Float:PretendentDistance = range +1;
    new     Pretendent;

    GetPlayerPos(playerid, p_X, p_Y, p_Z);

    for(new vehicleid=1; vehicleid < MAX_VEHICLES; vehicleid++)
    {
        Distance = GetVehicleDistanceFromPoint(vehicleid, p_X, p_Y, p_Z);

        if(Distance <= range && Distance <= PretendentDistance)
        {
            Pretendent = vehicleid;
            PretendentDistance = Distance;
        }
    }

    return Pretendent;
}



Re: SetVehicleParamsEx problems - StrikerZ - 20.05.2017

Post your code, let me have a look.


Re: SetVehicleParamsEx problems - TheAngryBird - 20.05.2017

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
Post your code, let me have a look.
this is the old code
Код:
	if((newkeys & KEY_YES) && !(oldkeys & KEY_YES))
	{
		new NearestVehicleID = GetClosestVehicle(playerid, 3.0);
		//if(!PlayerToVehicle(playerid, NearestVehicleID, 3.0)) NearestVehicleID = 0;
		new Float:NearestVehiclePosX, Float:NearestVehiclePosY, Float:NearestVehiclePosZ;
		GetVehiclePos(NearestVehicleID, NearestVehiclePosX, NearestVehiclePosY, NearestVehiclePosZ);
		new playerName[MAX_PLAYER_NAME];
		GetPlayerName(playerid,playerName,sizeof playerName);
		new string[128];
		format(string, sizeof(string), "ID %i ", NearestVehicleID);
		SendClientMessage(playerid, -1, string);
		/*
	    if(IsPlayerInAnyVehicle(playerid))
	    {
	        Dialog_Show(playerid, DIALOG_VEHICLEMENU, DIALOG_STYLE_LIST, "Vehicle", "Engine\nLight\nHood\nBoot\nDoors\nWindows\nPark", "Ok", "Cancel");
	    }
	    else
	    {
	        if(IsPlayerInRangeOfPoint(playerid, 5.0, NearestVehiclePosX, NearestVehiclePosY, NearestVehiclePosZ))
	        {
	    		if(IsVehiclePrivate(NearestVehicleID))
	    		{
	    		    if(!strcmp(playerName,PrivateVehicles[ConvertVID(NearestVehicleID)][_owner])) return 0;
	    		    new string[128];
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx(NearestVehicleID, engine, lights, alarm, doors, bonnet, boot, objective);
					if(engine == -1) engine = 0;
				    if(lights == -1) lights = 0;
				    if(alarm == -1) alarm = 0;
				    if(doors == -1) doors = 0;
				    if(boot == -1) boot = 0;
				    if(objective == -1) objective = 0;
	    		    format(string, sizeof(string), "ID %i doors %i", NearestVehicleID, doors);
	    		    SendClientMessage(playerid, -1, string);
					if(doors == VEHICLE_PARAMS_UNSET)
					{
					    SendClientMessage(playerid, -1, "Vehicle params are unset");
					}
	    		    if(doors != VEHICLE_PARAMS_ON)
	    		    {
	    		    	SetVehicleParamsEx(NearestVehicleID, engine, lights, alarm, VEHICLE_PARAMS_ON, bonnet, boot, objective);
	    		    	SendClientMessage(playerid, -1, "your vehicle is now locked");
	    		    }
	    		    if(doors != VEHICLE_PARAMS_OFF)
	    		    {
	    		    	SetVehicleParamsEx(NearestVehicleID, engine, lights, alarm, VEHICLE_PARAMS_OFF, bonnet, boot, objective);
	    		    	SendClientMessage(playerid, -1, "your vehicle is now unlocked");
	    		    }
		        }
		        else
		        {
		        }
	        }
	    }
	    */
	}
but im re-writing it. i just did this to try before i go too far
Код:
	if((newkeys & KEY_YES) && !(oldkeys & KEY_YES))
	{
		new NearestVehicleID = GetClosestVehicle(playerid, 3.0);
		new string[128];
		format(string, sizeof(string), "ID %i ", NearestVehicleID);
		SendClientMessage(playerid, -1, string);
        }
and it give id 1999 while it should be 1 as its the only vehicle for now.


Re: SetVehicleParamsEx problems - StrikerZ - 20.05.2017

Try
PHP код:

stock GetClosestVehicle
(playeridFloat:range)
{
    new     
Float:p_X;
    new     
Float:p_Y;
    new     
Float:p_Z;
    new     
Float:Vpos[3];
    
    
GetPlayerPos(playeridp_Xp_Yp_Z);
    for(new 
vehicleid=1vehicleid MAX_VEHICLESvehicleid++)
    {
        
GetVehiclePos(vehicleid,Vpos[0],Vpos[1],Vpos[2]);
        if(
IsPlayerInRangeOfPoint(playerid,range,Vpos[0],Vpos[1],Vpos[2]))
        {
            return 
vehicleid;
        }
    }
    return 
0;




Re: SetVehicleParamsEx problems - TheAngryBird - 20.05.2017

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
Try
PHP код:

stock GetClosestVehicle
(playeridFloat:range)
{
    new     
Float:p_X;
    new     
Float:p_Y;
    new     
Float:p_Z;
    new     
Float:Vpos[3];
    
    
GetPlayerPos(playeridp_Xp_Yp_Z);
    for(new 
vehicleid=1vehicleid MAX_VEHICLESvehicleid++)
    {
        
GetVehiclePos(vehicleid,Vpos[0],Vpos[1],Vpos[2]);
        if(
IsPlayerInRangeOfPoint(playerid,range,Vpos[0],Vpos[1],Vpos[2]))
        {
            return 
vehicleid;
        }
    }
    return 
0;

your stock work. thank you. re-writing whole code with your stock


Re: SetVehicleParamsEx problems - StrikerZ - 20.05.2017

Quote:
Originally Posted by TheAngryBird
Посмотреть сообщение
your stock work. thank you. re-writing whole code with your stock
No problem bro.


Re: SetVehicleParamsEx problems - Vince - 20.05.2017

Quote:
Originally Posted by TheAngryBird
Посмотреть сообщение
your stock work. thank you. re-writing whole code with your stock
You mean function. It's also not exactly the same as it just finds the first vehicle that's in range regardless of the distance. For example if vehicles 5 and 20 are in range and you're closer to vehicle 20 then it will still return vehicle 5 because that's the first vehicle that's found to be in range. This may not matter for smaller distances but it gets worse with larger distance because more vehicles will get in range.