SA-MP Forums Archive
GetVehicleModelInfo + OnPlayerWeaponShoot - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: GetVehicleModelInfo + OnPlayerWeaponShoot (/showthread.php?tid=488655)



GetVehicleModelInfo + OnPlayerWeaponShoot - Riddick94 - 18.01.2014

Simply, GetVehicleModelInfo is returning null values when player shoot a vehicle.

Code:
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    switch(hittype)
    {
        case BULLET_HIT_TYPE_VEHICLE:
        {
            new Float:Offset[9];
            GetVehicleModelInfo(hitid, VEHICLE_MODEL_INFO_WHEELSFRONT, Offset[0], Offset[1], Offset[2]);
            GetVehicleModelInfo(hitid, VEHICLE_MODEL_INFO_WHEELSREAR,  Offset[3], Offset[4], Offset[5]);
            GetVehicleModelInfo(hitid, VEHICLE_MODEL_INFO_PETROLCAP,   Offset[6], Offset[7], Offset[8]);

            printf("Front wheels: %f, %f, %f",  Offset[0], Offset[1], Offset[2]);
            printf("Read wheels: %f, %f, %f",  Offset[3], Offset[4], Offset[5]);
            printf("Petrol cap: %f, %f, %f",  Offset[6], Offset[7], Offset[8]);
        }
    }
    return 1;
}
Log:
Код:
[20:39:15] Front wheels: 0.000000, 0.000000, 0.000000
[20:39:15] Read wheels: 0.000000, 0.000000, 0.000000
[20:39:15] Petrol cap: 0.000000, 0.000000, 0.000000



Re: GetVehicleModelInfo + OnPlayerWeaponShoot - Reboma - 18.01.2014

You have to pass the model as first parameter, not the vehicle ID:

Parameters: (https://sampwiki.blast.hk/wiki/GetVehicleModelInfo)
pawn Код:
(vehiclemodel, infotype, Float:X, Float:Y, Float:Z)
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    switch(hittype)
    {
        case BULLET_HIT_TYPE_VEHICLE:
        {
            new Float:Offset[9], model = GetVehicleModel(hitid);
            GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_WHEELSFRONT, Offset[0], Offset[1], Offset[2]);
            GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_WHEELSREAR,  Offset[3], Offset[4], Offset[5]);
            GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_PETROLCAP,   Offset[6], Offset[7], Offset[8]);

            printf("Front wheels: %f, %f, %f",  Offset[0], Offset[1], Offset[2]);
            printf("Read wheels: %f, %f, %f",  Offset[3], Offset[4], Offset[5]);
            printf("Petrol cap: %f, %f, %f",  Offset[6], Offset[7], Offset[8]);
        }
    }
    return 1;
}



Re: GetVehicleModelInfo + OnPlayerWeaponShoot - Patrick - 18.01.2014

@Reboma - Yes, you need to create a new variable or just use GetVehicleModel(hitid), to make the code work.

@Riddick94 - GetVehicleModelInfo first parameter is vehiclemodel, sometimes you need to check the parameter of the function you are using if you're doing it right or wrong.

Quote:
Originally Posted by SA-MP Wiki
pawn Код:
GetVehicleModelInfo(vehiclemodel, infotype, Float:X, Float:Y, Float:Z)
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    switch(hittype)
    {
        case BULLET_HIT_TYPE_VEHICLE:
        {
            new
                Float:Offset[3][3];

            GetVehicleModelInfo(GetVehicleModel(hitid), VEHICLE_MODEL_INFO_WHEELSFRONT, Offset[0][0], Offset[0][1], Offset[0][2]);
            GetVehicleModelInfo(GetVehicleModel(hitid), VEHICLE_MODEL_INFO_WHEELSREAR,  Offset[1][0], Offset[1][1], Offset[1][2]);
            GetVehicleModelInfo(GetVehicleModel(hitid), VEHICLE_MODEL_INFO_PETROLCAP,   Offset[2][0], Offset[2][1], Offset[2][2]);

            printf("Front wheels: %.3f, %.3f, %.3f",  Offset[0][0], Offset[0][1], Offset[0][2]);
            printf("Read wheels: %.3f, %.3f, %.3f", Offset[1][0], Offset[1][1], Offset[1][2]);
            printf("Petrol cap: %.3f, %.3f, %.3f",  Offset[2][0], Offset[2][1], Offset[2][2]);
        }
    }
    return 1;
}
Result ( Vehicle ID:498 )
Код:
[20:51:40] Front wheels: 1.090, 2.410, -0.579
[20:51:40] Read wheels: 0.990, -1.740, -0.579
[20:51:40] Petrol cap: -1.299, -0.009, 0.090
[20:51:41] Front wheels: 1.090, 2.410, -0.579
[20:51:41] Read wheels: 0.990, -1.740, -0.579
[20:51:41] Petrol cap: -1.299, -0.009, 0.090
[20:51:47] Front wheels: 1.090, 2.410, -0.579
[20:51:47] Read wheels: 0.990, -1.740, -0.579
[20:51:47] Petrol cap: -1.299, -0.009, 0.090



Re: GetVehicleModelInfo + OnPlayerWeaponShoot - Riddick94 - 18.01.2014

Wut.. I was searching net, and someone had similar code to mine (checking ID) and it worked for him o.o Thanks guys.


Re: GetVehicleModelInfo + OnPlayerWeaponShoot - Reboma - 18.01.2014

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
@Reboma - Yes, you need to create a new variable or just use GetVehicleModel(hitid), to make the code work.
Using a variable faster than call a function multiple times for the same result