Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Releases Libraries [Library] Vehicle Components Library

 
  • 0 Vote(s) - 0 Average
Library Vehicle Components Library
pawnoholic
Offline

Burgershot Member
Posts: 2
Threads: 1
Joined: Apr 2019
Reputation: 1
#1
2019-04-15, 06:47 PM (This post was last modified: 2019-04-17, 09:31 AM by pawnoholic.)
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
kristo
Offline

Burgershot Member
Posts: 47
Threads: 10
Joined: Feb 2019
Reputation: 7
Location: Estonia
#2
2019-04-17, 12:52 AM (This post was last modified: 2019-04-17, 01:27 AM by kristo.)
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 [font=Courier New]INVALID_VEHICLE_COMPONENT_ID[/font].
  • 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
pawnoholic
Offline

Burgershot Member
Posts: 2
Threads: 1
Joined: Apr 2019
Reputation: 1
#3
2019-04-17, 04:04 AM
Thanks for your feedback.

I updated the library code following your recommendations.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode