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

Nice! Useful for heavy RP servers where as in real life you actually pay according to what has been damaged, and how badly. Keep up the good work.
Reply
#3

Nice release, was about to start looking for something like this to implement on my server.
Reply
#4

http://forum.ls-rp.com/viewtopic.php?f=592&t=242039
I'm quite sure most of it is copied from this thread. If you don't have an account: http://pastebin.com/65ysmcLB
Reply
#5

Quote:
Originally Posted by kvann
Посмотреть сообщение
http://forum.ls-rp.com/viewtopic.php?f=592&t=242039
I'm quite sure most of it is copied from this thread. If you don't have an account: http://pastebin.com/65ysmcLB
I added, it was edited. I just neatened it up alittle - I was actually looking for this post to credit him, as it's been on my computer for a while and I couldn't remember where I got it. Anyway, he has been added to the credits.
Reply
#6

Its always give me $1 price, i aint changed anything in that.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)