SA-MP Forums Archive
I guess that's ZCMD bug or something - 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: I guess that's ZCMD bug or something (/showthread.php?tid=524782)



I guess that's ZCMD bug or something - kamiliuxliuxliux - 08.07.2014

Hey. I have one problem with ZCMD and vehicles. First, code:
pawn Код:
CMD:manomasinos(playerid)
{
    UpdatePlayerVehiclesInfo(playerid);
    new skaic[3][] =
    {
        "Pirma", // eng. "First"
        "Antra", // eng. "Second"
        "Trecia" // eng. "Third"
    };
    new s[300], sfin[900]; // two new vars
    for(new i = 0; i < 3; i++) // looping through player's private vehicles
    {
        if(anInfo[playerid][i][ID] != -1) // if player has a certain vehicle
        {
            new Float:kaina = anInfo[playerid][i][pard_kaina] / 2; // calculatings....
            if(anInfo[playerid][i][destroyed] == 1) {format(s, 300, "{FFFFFF}%s transp. priemone: {AB6CC6}%s{FFFFFF}. HP: {55B1C6}%.1f{FFFFFF}. Kaina parduodant serveriui: {785B25}%i{FFFFFF} Lt. Numeriai: {BBD623}%s {CE0000}( SUNAIKINTA! )\n", skaic[i], VehNames[GetVehicleModel(anInfo[playerid][i][real_vehid])-400], anInfo[playerid][i][health], floatround(kaina, floatround_round), anInfo[playerid][i][veh_numplate]);} // if player's vehicle is destroyed, we format string 's' in one way.
            else {format(s, 300, "{FFFFFF}%s transp. priemone: {AB6CC6}%s{FFFFFF}. HP: {55B1C6}%.1f{FFFFFF}. Kaina parduodant serveriui: {785B25}%i{FFFFFF} Lt. Numeriai: {BBD623}%s\n", skaic[i], VehNames[GetVehicleModel(anInfo[playerid][i][real_vehid])-400], anInfo[playerid][i][health], floatround(kaina, floatround_round), anInfo[playerid][i][veh_numplate]);} // else if it's not, we format string 's' in another way.
            strcat(sfin, s); // then we merge 's' into 'sfin'
        }
    }
    if(isnull(sfin)) {SPMB(playerid, "Tu neturi transp. priemoniu!");} // if player has no vehicles (var 'sfin' is empty), he will recieve a message.
    else SPD(playerid, DIALOG_SHOW_VEHS, DIALOG_STYLE_MSGBOX, "Nuosavos transp. priemones", sfin, "Gerai",""); // else we send player a dialog with full player vehicles info.
    return 1;
}
Now sometimes if vehicle is DESTROYED (anInfo[playerid][destroyed] == 1) this command gets bugged and it recieves me a message SERVER: Unknown command. But now why am I sayin' that's something with vehicles? Because other commands which do something with DESTROYED vehicles gets bugged also (e.g. I want to sell destroyed vehicle). I just posted a code above exactly with the command I faced first. Any help?



Re: I guess that's ZCMD bug or something - kamiliuxliuxliux - 08.07.2014

Anyone?


Re: I guess that's ZCMD bug or something - Konstantinos - 08.07.2014

Load crashdetect plugin and compile the scripts with debug info, run the server and execute the command. If it displays the unknown command message, then post your server log.


Re: I guess that's ZCMD bug or something - kamiliuxliuxliux - 08.07.2014

And there you go:
Код:
[2014.07.08 <> 22:10:57] [debug] Run time error 4: "Array index out of bounds"
[2014.07.08 <> 22:10:57] [debug]  Accessing element at negative index -400
[2014.07.08 <> 22:10:57] [debug] AMX backtrace:
[2014.07.08 <> 22:10:57] [debug] #0 00054a64 in public cmd_manomasinos (0x00000000, 0x00070d4c) from LVG.amx
[2014.07.08 <> 22:10:57] [debug] #1 native CallLocalFunction () [00472ad0] from samp-server.exe
[2014.07.08 <> 22:10:57] [debug] #2 000060e8 in public OnPlayerCommandText (0x00000000, 0x00070d18) from LVG.amx



Re: I guess that's ZCMD bug or something - Konstantinos - 08.07.2014

You have:
pawn Код:
VehNames[GetVehicleModel(anInfo[playerid][i][real_vehid])-400]
The value of anInfo[playerid][i][real_vehid] is not a valid vehicle as GetVehicleModel function returns 0 and subtracting 400 from it, the result will be -400 which is an invalid index.

In order to prevent it, you'll have to check if the modelid is not 0.
pawn Код:
new modelid = GetVehicleModel(anInfo[playerid][i][real_vehid]);
if (modelid) // if not 0
{
    // code..
    // you can use "VehNames[modelid-400]" as argument here..
}



Re: I guess that's ZCMD bug or something - kamiliuxliuxliux - 08.07.2014

OMG Thank you!