SA-MP Forums Archive
Subtraction not working.. help please - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Subtraction not working.. help please (/showthread.php?tid=244976)



Subtraction not working.. help please - Hornet600 - 29.03.2011

I made one vehicle system and now i added a new feature that is vehicle insurances, when a vehicle blows up the vehicle gets removed from the database and this works alright.

But now I'm trying to make a subtraction when a vehicle destroys example i got three insurances them the car blows up,
them the car goes to two insurances etc, but my code to do it got a bug and i need help to fix this out.

Here goes the code

pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{

    if(vehicleinfo[currentplayervehicle[killerid]][Insurances] == 0) //working
    {
        new query[256];
        new currentveh = GetPlayerVehicleID(killerid);
        DestroyVehicle(currentveh);
        format(query, sizeof(query),"DELETE FROM vehicles WHERE carid=%d",vehicleinfo[currentveh][id]);
        mysql_query(query);
        LoadPlayerKeys(vehicleinfo[currentveh][Owner]);
        SendClientMessage(vehicleinfo[currentveh][Owner],COLOR_RED, " Your vehicle as been destroyed\n (deleted)");
    }
    else // bug
    {   // the script of currentveh is working
        new currentveh = GetPlayerVehicleID(killerid);
        vehicleinfo[currentveh][Insurances]--; // this line is used to make one Subtraction of the insurances variable with "1"
        SaveVehicle(vehicleinfo[currentveh][id]); // saves the vehicle insurances
        DestroyVehicle(currentveh); // destroys the vehicle
        SendClientMessage(vehicleinfo[currentveh][Owner], COLOR_RED, " Your vehicle as destroyed \n one of the licenses is gone now"); //this is working how its supused :p
    }

    return 1;
}



AW: Subtraction not working.. help please - Nero_3D - 29.03.2011

try the long version there are sometimes problems with enums, like using arrays inside an enum

pawn Код:
vehicleinfo[currentveh][Insurances] = (vehicleinfo[currentveh][Insurances] - 1);



Re: Subtraction not working.. help please - Hornet600 - 29.03.2011

weird this is not subtracting the variable


Re: Subtraction not working.. help please - Donya - 29.03.2011

OnVehicleDeath(vehicleid, killerid) does not work properly


Re: Subtraction not working.. help please - Joe Staff - 29.03.2011

new currentveh = vehicleid

Also
currentvehicle[killerid] should be vehicleid


Re: Subtraction not working.. help please - Hornet600 - 29.03.2011

it is not.. my script is very complex and i got something wrong.. i printed the values and its its decreasing the values i left something in the midle and need figure it out lol, anyway ty nero it worked.


Re: Subtraction not working.. help please - Joe Staff - 29.03.2011

This means whoever killed the vehicle is losing insurances, not the vehicle itself


Re: Subtraction not working.. help please - Hornet600 - 29.03.2011

hm this is working now . when i print the values this match with vehicle system itself but i figured that my stock to save vehicles was buged so i created a new query update to insert the insurances when it destroys and now it works perfect