[Include] Vehicle Entering Fix
#1

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
Reply
#2

Код:
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];
Reply
#3

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.
Reply
#4

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).
Reply
#5

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.
Reply
#6

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
Reply
#7

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
Reply
#8

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.
Reply
#9

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.
Reply
#10

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.
-------
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)