Server command not found [+REP].
#1

Ok, so in my server i've this function;

pawn Код:
if(!strcmp(option, "list", true))
    {
        if(PlayerInfo[playerid][pVehicles] == 0) return SCM(playerid, COLOR_LIGHTRED, "You do not own any vehicles.");
        SCMEx(playerid, COLOR_GREEN, "______________Your Vehicles(%d)______________", PlayerInfo[playerid][pVehicles]);
        for(new i = 1; i <= PlayerInfo[playerid][pVehicles]; i++)
        {
            if(VehicleStatus[playerid][i][carOn] == 1)
            {
                if(FindVehicleByPlate(VehicleStatus[playerid][i][carPlate]))
                {
                    SCMEx(playerid, COLOR_GREEN, "Vehicle %d: %s, Lock[%d], Alarm[%d], Immobiliser[%d], Insurances[%d], Times Destroyed[%d], Next Insurance Price[$%d]", i, VehicleNames[VehicleStatus[playerid][i][carModel]-400],VehicleStatus[playerid][i][carLock],VehicleStatus[playerid][i][carAlarm],VehicleStatus[playerid][i][carImmob],VehicleStatus[playerid][i][carInsurances],VehicleStatus[playerid][i][carDestroyed],GetInsurancePrice2(playerid, i));
                }
                else
                {
                    SCMEx(playerid, COLOR_WHITE, "Vehicle %d: %s, Lock[%d], Alarm[%d], Immobiliser[%d], Insurances[%d], Times Destroyed[%d], Next Insurance Price[$%d]", i, VehicleNames[VehicleStatus[playerid][i][carModel]-400],  VehicleStatus[playerid][i][carLock],VehicleStatus[playerid][i][carAlarm],VehicleStatus[playerid][i][carImmob],VehicleStatus[playerid][i][carInsurances],VehicleStatus[playerid][i][carDestroyed],GetInsurancePrice2(playerid, i));
                }
            }
        }
        return 1;
    }
To check how cars you have ofcourse, but if I purchase just 1 car, then it all works find, shows etc.

But if I buy 2 cars, then it shows the 1st car and says "Server command was not found" on the line that the next car should been?

Any ideas?
Reply
#2

What "VehicleStatus[playerid][i][carOn]" stands for ?
Reply
#3

It's caused run time error 4. Let's say you have 10 vehicles in VehicleStatus for each player. The valid indexes will be 0-9. Indexes always start from 0 so the loop would be:
pawn Код:
for(new i = 0; i < PlayerInfo[playerid][pVehicles]; i++)
and PlayerInfo[playerid][pVehicles] would be how many cars you have.

1 car? it loops with index 0.
2 cars? it loops with index 0 and 1
and so on..

that way, it won't go out of bounds.
Reply
#4

Can you please explain what I should write instead of 0 then Konstantinos? 3 or what?
Reply
#5

Quote:
Originally Posted by HK
Посмотреть сообщение
Can you please explain what I should write instead of 0 then Konstantinos? 3 or what?
I didn't say to replace 0 with something else. My point was that indexes in arrays start from 0 and not 1.
Reply
#6

I changed it from 1 till 0, but it stills makes it? I really don't know what's causing it.. I don't understand what you mean either.
Reply
#7

Okay, let me explain it better. I don't know your code so I'll give few examples instead.

Let's say you have:
pawn Код:
new VehicleStatus[MAX_PLAYERS][10][some_enum];
// 10 vehicles (valid indexes 0-9)
If you have 10 vehicles and PlayerInfo[playerid][pVehicles] is 10, by doing:
pawn Код:
for(new i = 1; i <= PlayerInfo[playerid][pVehicles]; i++)
it will loop from 1 to 10. As I said, the last (in this example) will be 9 and passing 10 is an invalid index and it causes run time error 4.
Reply
#8

This still doesn't explain why it says unknow error for the 2nd vehicle IG?
Reply
#9

Run time errors that are caused inside commands will display the unknown command message.

You probably increase PlayerInfo[playerid][pVehicles] and when "i" accesses the element at an invalid index in VehicleStatus array will cause the run time error 4.

Without the code and information of crashdetect, I can't really help you by just guessing.

Crashdetect plugin: https://sampforum.blast.hk/showthread.php?tid=262796
Debug info: https://github.com/Zeex/samp-plugin-...ith-debug-info
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)