y_vehicledata - Versão de Impressão +- Portal SAMP (https://portalsamp.com) +-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5) +--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6) +--- Tópico: y_vehicledata (/showthread.php?tid=992) |
y_vehicledata - Flenex - 28/03/2021 recentemente vi essa include dentro do ysi. alguem sabe como usa-la? RE: y_vehicledata - Dayvison - 28/03/2021 Introduction I have time and again seen code defining properties of vehicles that uses loops or vast chunks of memory, when far far less is needed. Many of those times I've even explained HOW to do it smaller, but no-one has, so I did. Thus, I present y_vehicledata (formally YSI_Game\y_vehicledata, but not yet in any YSI repository). The include has three prefixes - that is, three groups of functions - "Vehicle_", "Model_", and "VIM_". All three groups have the same functions, but take different inputs.
These functions take a vehicleid, i.e. a value returned by CreateVehicle or GetPlayerSurfingVehicleID etc.
These functions take a modelid, i.e. an object as passed to AddStaticVehicle or returned by GetVehicleModel etc.
These functions take a special VIM variable, that is, one with a tag of VIM:. VIM stands for Vehicle Internal Model, and is specific to this include (but others are free to use it if they want). This is different to normal models in three ways: 1) They are always valid. 2) They can be used as indexes. 3) They have a strong tag to differentiate them. This second point is very important. Standard model IDs start at 400 and go up to 611, so if you want to use them to index an array you either need 400 empty slots in the array, or to subtract 400 from the model ID (which is exactly what VIMs are). Functions
Equivalents exist for Model_, taking a modelid instead of a vehicleid - replace the Vehicle_ prefix with Model_. VIM Conversion Equivalents to all the above functions also exist for VIM: tagged variables - replace the Vehicle_ prefix with VIM_. There are two ways to get a VIM: variable - from a vehicleid or from a modelid: Código PHP: new Note the difference in "Get" and "To" - this is by design, as models are closer to VIMs than vehicleids are. So why use these instead? They just save a level of conversion: Código PHP: #define Vehicle_IsPoliceCar(%0) (Vehicle_IsCar(%0) && Vehicle_IsPolice(%0)) That is all fine, but internally calls several functions twice (including GetVehicleModel). This is slightly better: [pawn]#define Model_IsPoliceCar(%0) (Model_IsCar(%0) && Model_IsPolice(%0))[/pawn] But that still has to do the "- 400" subtraction discussed earlier (and check that the result is valid). Using VIM functions you can do the conversion and bounds checks once, then use the result far more efficiently: Código PHP: RE: y_vehicledata - Flenex - 28/03/2021 funcionou, vlw |