"return 0" issue.
#1

Here I have some code for my command.

It doesn't seem to work? It just returns 0 all the time displaying \"Unknown Command.\".

pawn Код:
command(mycars, playerid, params[])
{
    new string[256], string1[256];
    print("new string[256], string1[256];");
    if(Player[playerid][CarKey1] != 0)format(string1, sizeof(string1), "Vehicle Slot 1: %s(ID %d) - Plate: %s.", GetVehicleName(OwnedCar(Player[playerid][CarKey1])), OwnedCar(Player[playerid][CarKey1]), Vehicles[OwnedCar(Player[playerid][CarKey1])][VehiclePlate]);
    print("if(Player[playerid][CarKey1] != 0)format(string1, sizeof(string1), \"Vehicle Slot 1: %s(ID %d) - Plate: %s.\", GetVehicleName(OwnedCar(Player[playerid][CarKey1])), OwnedCar(Player[playerid][CarKey1]), Vehicles[OwnedCar(Player[playerid][CarKey1])][VehiclePlate]);");
    if(Player[playerid][CarKey1] == 0)format(string1, sizeof(string1), "Vehicle Slot 1: Not used.");
    print("else if(Player[playerid][CarKey1] == 0)format(string1, sizeof(string1), \"Vehicle Slot 1: Not used.\");");
    format(string, sizeof(string), "%s\n", string1);
    print("format(string, sizeof(string), \"%s\n\", string1);");
    ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "Your Owned Vehicles", string, "OK", "");
    print("ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, \"Your Owned Vehicles\", string, OK,\"\");");
    return 1;
}
If somebody can help, that would be great!

The print("new string[256], string1[256]"); prints and that's the only thing that does print.

Crashdetect is:

Код:
[04:13:18] [debug] Run time error 4: "Array index out of bounds"
[04:13:18] [debug]   Accessing element at negative index -400
[04:13:18] [debug] AMX backtrace:
[04:13:18] [debug] #0  000cc5cc in ?? () from new.amx
[04:13:18] [debug] #1  00029ae0 in public cmd_mycars () from new.amx
[04:13:18] [debug] #2  native CallLocalFunction () [00472260] from samp-server.exe
[04:13:18] [debug] #3  000065e0 in public OnPlayerCommandText () from new.amx
Thanks!
Reply
#2

As your debugger tells you, you have an array index out of bounds runtime error, which means that you're probably pointing to an index in your array that doesn't exist (is out of bounds), most likely in this part of the code:

pawn Код:
GetVehicleName(OwnedCar(Player[playerid][CarKey1])), OwnedCar(Player[playerid][CarKey1]), Vehicles[OwnedCar(Player[playerid][CarKey1])][VehiclePlate]
You should show us these functions and additionally print out the values of the arguments being passed to them so we can see what's going wrong exactly.
Reply
#3

What parts is it you need to see? Because I don't know what one's that you wanna see.

Please tell me the one's and I will show them .
Reply
#4

Quote:
Originally Posted by iGetty
Посмотреть сообщение
What parts is it you need to see? Because I don't know what one's that you wanna see.

Please tell me the one's and I will show them .
The functions that I posted. They are not part of the default SA-MP API and I don't know what they do so you'll have to show them.
Reply
#5

pawn Код:
#define OwnedCar(%0)        ivCreated[%0]
new ivCreated[MAX_VEHICLES];
pawn Код:
new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
    "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};

stock GetVehicleName(vehicleid)
{
    new String[28];
    format(String,sizeof(String),"%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return String;
}
Them?
Reply
#6

Okay, so based on the debugger I can already tell what the issue is.

The "VehicleNames" array is 212 cells in size and in some cases when you're using GetVehicleName, the vehicleid argument that's being passed is invalid, which means the model being taken from that is going to turn up as 0, which means you are then pointing to VehicleNames[-400], which doesn't exist and results in a runtime error. This lines up with your debugging information: "Accessing element at negative index -400".

So you need to do some debugging, you need to print the value of Player[playerid][CarKey1] and the value that's returned by your macro "OwnedCar", as clearly it's not returning the correct value. Print those values at the start of your command and see the output, check if the return values are valid.
Reply
#7

It prints:

CarKey1 = 3

When the Vehicle ID is 2.

I've just made an edit on the SQL to see if it changes anything. One sec and I'll edit this to let you know.
Reply
#8

Ah, you got any other idea's of what is wrong with it, mate?
Reply
#9

Your problem is here: GetVehicleName(OwnedCar(Player[playerid][CarKey1]))

Your GetVehicleName function expects the vehicleid, but looks like you're feeding it some other id from an array (perhaps an "is vehicle created" array based on its name?) try using just GetVehicleName(Player[playerid][CarKey1])
Reply
#10

Instead of doing it that way, is there any way to do a loop through ALL owned vehicles, then match the name with the 3 cars that are owned by the player?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)