[Include] GetRepairPrice - Vehicle include
#1

Well, this is a REALLY simple include that consists of a local function.

Well, what this does is just collects the vehicles damage status on each vehicle component, shall we say? (includes: front bumper, rear bumper, doors, tires, wind-shield..ect) then it stores the result inside a variable then compares it with other components to get a complete price for fix.

Really not much to explain..

Code:
pawn Код:
/*
    2014, 18th of June.
   
    Credits:
        GiGi / d3ll / Brandon_More - Coder (Edited)
        Kalcor - a_samp.inc (functions)
        Mmartin - Original coder.
*/

#include <a_samp>
stock GetRepairPrice(vehicleid, &price)
{
    new panels,
        doors,
        lights,
        tires;
       
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
// Vehicle perhiferals
    new front_left_panel    =   0xf & panels;
    new front_right_panel   =   ( ( 0xf << 4 ) & panels ) >> 4;
    new rear_left_panel     =   ( ( 0xf << 8 ) & panels ) >> 8;
    new rear_right_panel    =   ( ( 0xf << 12 ) & panels ) >> 12;
   
    new wind_shield         =   ( ( 0xf << 16 ) & panels ) >> 16;
   
    new front_bumper        =   ( ( 0xf << 20 ) & panels ) >> 20;
    new rear_bumper         =   ( ( 0xf << 24 ) & panels ) >> 24;
    new hood                =   0xf & doors;   
    new trunk               =   ( ( 0xf << 8 ) & doors ) >> 8;
// Vehicle seats
    new front_left_seat     =   ( ( 0xf << 16 ) & doors ) >> 16;
    new front_right_seat    =   ( ( 0xf << 24 ) & doors ) >> 24;
    new rear_left_seat      =   ( ( 0xf << 32 ) & doors ) >> 32;
    new rear_right_seat     =   ( ( 0xf << 40 ) & doors ) >> 40;
// Tires
    new tire_front_left = 1 & tires;
    new tire_front_right = ( ( 1 << 1 ) & tires ) >> 1;
    new tire_rear_left = ( ( 1 << 2 ) & tires ) >> 2;
    new tire_rear_right = ( ( 1 << 3 ) & tires ) >> 3;
// Comparing the information together
    new panel_add = floatround( (   front_left_panel +
                                    front_right_panel +
                                    rear_left_panel +
                                    rear_right_panel +
                                    wind_shield +
                                    front_bumper +
                                    rear_bumper ) / 0.21 );
                       
    new door_add = floatround( (    hood +
                                    trunk +
                                    front_left_seat +
                                    front_right_seat +
                                    rear_left_seat +
                                    rear_right_seat ) / 0.24 );
   
    new tire_add = floatround( (    tire_front_left +
                                    tire_front_right +
                                    tire_rear_left +
                                    tire_rear_right ) / 0.04 );
   
    new pprice = 1 * panel_add;
    new dprice = 1 * door_add;
    new tprice = 2 * tire_add;
    new Float:iHealth;
    GetVehicleHealth(vehicleid, iHealth);
    new engineprice = floatround( ( floatround ( iHealth - 1000 ) * ( -1 ) ) * 0.75 );
    price = engineprice + tprice + dprice + pprice;
}
Adding to script:
pawn Код:
#include <GetRepairPrice> // Or whatever you saved the file as.
Functions:
Код:
GetRepairPrice(vehicleid, price);
Example:

pawn Код:
COMMAND:fixcar(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid) == 1)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new iPrice;
        GetRepairPrice(vehicleid, iPrice);
        if(GetPlayerMoney(playerid) >= iPrice)
        {
            return RepairVehicle(vehicleid);
        }
        else return SendClientMessage(playerid, -1, "You do not have enough money to repair this vehicle.");
    }
    else return SendClientMessage(playerid, -1, "You are not inside any vehicle.");
}

Reply


Messages In This Thread
GetRepairPrice - Vehicle include - by d3ll - 18.06.2014, 16:37
Re: GetRepairPrice - Vehicle include - by Abagail - 18.06.2014, 18:34
Re: GetRepairPrice - Vehicle include - by DexterC - 18.06.2014, 18:43
Re: GetRepairPrice - Vehicle include - by kristo - 18.06.2014, 19:16
Re: GetRepairPrice - Vehicle include - by d3ll - 18.06.2014, 19:21
Re: GetRepairPrice - Vehicle include - by cnoopers - 02.07.2014, 15:09

Forum Jump:


Users browsing this thread: 3 Guest(s)