SA-MP Forums Archive
[Include] Vehicle Entering Fix - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Vehicle Entering Fix (/showthread.php?tid=574093)



Vehicle Entering Fix - ZiGGi - 13.05.2015

Fix for missing animation when enter locked vehicle as driver. About this bug you can read here: https://sampforum.blast.hk/showthread.php?tid=560019

Thanks to Emmet_ for idea.

Usage
Copy enterfix.inc into your include dir and add
PHP код:
#include "enterfix" 
after
PHP код:
#include <a_samp> 
Screenshot


Download


Re: Vehicle Entering Fix - Pottus - 13.05.2015

Код:
is_locked[vehicleid] = doors == VEHICLE_PARAMS_ON ? true : false;
LOL! That is just ridiculous.
Код:
is_locked[vehicleid] = bool:doors;
And again with the silly checks
Код:
doors = is_locked[vehicleid] ? VEHICLE_PARAMS_ON : VEHICLE_PARAMS_OFF;
Код:
doors = _:is_locked[vehicleid];



Re: Vehicle Entering Fix - ZiGGi - 13.05.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Код:
is_locked[vehicleid] = doors == VEHICLE_PARAMS_ON ? true : false;
LOL! That is just ridiculous.

Код:
is_locked[vehicleid] = bool:doors;
Nope, because value for VEHICLE_PARAMS_UNSET is non-obvious.


Quote:
Originally Posted by Pottus
Посмотреть сообщение
And again with the silly checks

Код:
doors = is_locked[vehicleid] ? VEHICLE_PARAMS_ON : VEHICLE_PARAMS_OFF;
Код:
doors = _:is_locked[vehicleid];
We need to use constants for keep compatibility.


Re: Vehicle Entering Fix - Pottus - 13.05.2015

Okay I understand why you did like that on the first part now but as for the second part there is no compatibility issues there is only one data type in pawn so you can directly assign an integer to an bool (with the exception of having more than two states).


Re: Vehicle Entering Fix - ZiGGi - 13.05.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Okay I understand why you did like that on the first part now but as for the second part there is no compatibility issues there is only one data type in pawn so you can directly assign an integer to an bool (with the exception of having more than two states).
For example: in sa-mp 0.4.2 Mr. Kalcor has changed the values for VEHICLE_PARAMS_ON to 2 and for VEHICLE_PARAMS_OFF to 1. After it, your code will break, my code will work perfect.


Re: Vehicle Entering Fix - Pottus - 13.05.2015

I really doubt that would happen in fact it would never happen anyways I was very curious to see what is the best way to do this and it seems the switch() is the best method interestingly.

Код:
#include <a_samp>


static bool:RetVals[3] = {
	false,
	false,
	true
};


public OnFilterScriptInit()
{
	new time = GetTickCount();
	new bool:locked;
	new doors = -1;

	for(new j = 0; j < 3; j++)
	{
		printf("\nResults When Doors = %i", doors);

		for(new i = 0; i < 1000000; i++)
		{
			locked = doors == VEHICLE_PARAMS_ON ? true : false;
		}
		printf("Time::Assignment/Ternary::%i", GetTickCount() - time);
		time = GetTickCount();

		for(new i = 0; i < 1000000; i++)
		{
			locked = RetVals[doors+1];
		}
		printf("Time::Array Referencing::%i", GetTickCount() - time);
		time = GetTickCount();

		for(new i = 0; i < 1000000; i++)
		{
			switch(doors)
			{
			    case VEHICLE_PARAMS_ON: locked = true;
			    default: locked = false;
			}
		}
		printf("Time::Switch::%i", GetTickCount() - time);


		for(new i = 0; i < 1000000; i++)
		{
			if(doors == 1) locked = true;
			else locked = false;
		}
		printf("Time::if/else::%i", GetTickCount() - time);
		time = GetTickCount();

		doors++;
	}
}
Results When Doors = -1
[12:49:27] Time::Assignment/Ternary::84
[12:49:27] Time::Array Referencing::78
[12:49:27] Time::Switch::71
[12:49:27] Time::if/else::146

Results When Doors = 0
[12:49:27] Time::Assignment/Ternary::85
[12:49:27] Time::Array Referencing::77
[12:49:27] Time::Switch::69
[12:49:27] Time::if/else::140

Results When Doors = 1
[12:49:27] Time::Assignment/Ternary::72
[12:49:28] Time::Array Referencing::75
[12:49:28] Time::Switch::78
[12:49:28] Time::if/else::173


Re: Vehicle Entering Fix - ZiGGi - 13.05.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
anyways I was very curious to see what is the best way to do this and it seems the switch() is the best method interestingly.
More speed != best. For me: compatibility > readability > speed


Re: Vehicle Entering Fix - Pottus - 13.05.2015

Quote:
Originally Posted by ZiGGi
Посмотреть сообщение
More speed != best. For me: compatibility > readability > speed
I never said more speed was the best did I? I more interested in seeing what would out perform what. As for compatibility again that is a complete non-issue those constants will never change

Obviously the switch() would be the best choice given the criteria you listed.


Re: Vehicle Entering Fix - Konstantinos - 13.05.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Obviously the switch() would be the best choice given the criteria you listed.
Both switch and ternary operator would be.

Also ternary operator seems to be faster when doors is 0 and 1 than switch (you forgot to assign to "time" after the loop) - but the speed is not even noticeable.

@ZiGGi: I don't think this would be ever fixed by samp team (there are more important bugs to be fixed) so good job on fixing it with your include.


Re: Vehicle Entering Fix - Kar - 14.05.2015

Quote:
Originally Posted by ZiGGi
Посмотреть сообщение
For example: in sa-mp 0.4.2 Mr. Kalcor has changed the values for VEHICLE_PARAMS_ON to 2 and for VEHICLE_PARAMS_OFF to 1. After it, your code will break, my code will work perfect.
-------