• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Library] Vehicle Components Library
#1
Vehicle Components Library



[Image: sampctl-samp--vehicle--components--libra...-the-badge]



This library add a new functions, which help find compatible upgrades.



Installation



Simply install to your project:



Code:
sampctl package install pawno-labs/samp-vehicle-components-library



Include in your code and begin using the library:



Code:
#include <components>



Usage



Code:
public OnVehicleMod(playerid, vehicleid, componentid)

{

? ? new modelid = GetVehicleModel(vehicleid);



? ? if (IsVehicleUpgradeCompatible(modelid, componentid))

? ? {

? ? ? ? new

? ? ? ? ? ? name[64],

? ? ? ? ? ? string[144];



? ? ? ? GetVehicleComponentName(componentid, name, sizeof(name));



? ? ? ? format(string, sizeof(string), "You have successfully installed \"%s\"", name);

? ? ? ? SendClientMessage(playerid, -1, string);

? ? }

? ? return 1;

}



Testing



To test, simply run the package:



Code:
sampctl package run
  Reply
#2
I like your code style, it looks clean and I see potential in this for being the go-to include for this purpose. However there are some issues I'd like to point out.




  • I'm not sure what you're trying to achieve with the asserts. Why even give users the possibility to define the constants themselves if they have to use the default value anyway?

  • You're mixing K&R and allman braces.

  • All of the data arrays are using different modifiers. The ultimate combination for all of them would be static stock const.

  • You should pack the component names.

  • If the compatible components array is based on the one by JernejL, there should be a post in that thread fixing the data for one model, allowing you to make the array significantly smaller.

  • You're not checking if the model IDs passed to the functions are valid.

  • IsVehicleHaveUpgrades is?not valid english, it should be DoesVehicleHaveUpgrades.

  • Y_Less suggested IsValidUpgrade as an alternative name for IsVehicleUpgradeCompatible, however I kind of like the current one more, you decide.

  • GetVehicleCompatibleUpgrades should either return the amount of compatible upgrades or reset the remaining slots to?INVALID_VEHICLE_COMPONENT_ID?so the user would have some sort of information about how many compatible components there are, preferrably go for the first option.

  • You could return 0 when?IsVehicleUpgradeCompatible?hits the first instance of?INVALID_VEHICLE_COMPONENT_ID.

  • This one's super nitpicky because the amount of data isn't that large, but it would make your library stand out from the competition. You could use binary search in IsVehicleUpgradeCompatible instead. To make it even more efficient, you could store the amount of compatible components for each vehicle in the first slot of their array (or create a completely new one, I'd go for the first option, but that's up to you).




Edit: I also sent the feedback to Ziggi, because a large part of the code is clearly copied from his library: https://github.com/Open-GTO/zvehcomp
  Reply
#3
Thanks for your feedback.



I updated the library code following your recommendations.
  Reply


Forum Jump: