OnVehicleSpawn - Crashdetect and code
#1

hej there
im getting some errors from OnVehicleSpawn i dont really understand this crashdetection codes so i need some help from you here is the errors by the way it starts at (255) + till a number idk which one cuz never checkd it out and doesnt start from 1 anyway here is the codes


Crashdetect codes
Код:
[00:19:53] Teleports loaded successfully.
[00:20:01] [debug] Run time error 4: "Array index out of bounds"
[00:20:01] [debug]  Accessing element at index 255 past array upper bound 254
[00:20:01] [debug] AMX backtrace:
[00:20:01] [debug] #0 000744c0 in public OnVehicleSpawn (255) from RP.amx
[00:20:01] [debug] #1 native SetVehicleToRespawn () from samp-server.exe
[00:20:01] [debug] #2 00189e7c in ?? (255) from RP.amx
[00:20:01] [debug] #3 0018859c in ?? () from RP.amx
[00:20:01] [debug] #4 0014fd90 in public zcmd_OnGameModeInit () from RP.amx
[00:20:01] [debug] #5 native CallLocalFunction () from samp-server.exe
[00:20:01] [debug] #6 0000cf64 in public IRC_OnGameModeInit () from RP.amx
[00:20:01] [debug] #7 native CallLocalFunction () from samp-server.exe
[00:20:01] [debug] #8 0000cb54 in public OnGameModeInit () from RP.amx

OnVeh Spawn
Код:
public OnVehicleSpawn(vehicleid)
{
dini_IntSet(CarFile(vehicleid), "carmaterials", 0);
SetVehicleEngineOff(vehicleid);
    AddVehicleComponent(vehicleid, 1010);
	AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa0]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa1]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa2]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa3]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa4]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa5]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa6]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa7]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa8]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa9]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa10]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa11]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa12]);
    AddVehicleComponent(vehicleid, Vehicles[vehicleid][compa13]);

    if(vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid);
    vTrailer[vehicleid] = 0;
    CarBombActive[vehicleid] = 0;
    vehicleGuns[vehicleid] = 0;
    vehicleBullets[vehicleid] = 0;
    new vid = GetPlayerVehicleID(vehicleid);
    /*if(Vehicles[vehicleid][nitro] > 0)
    {
        AddVehicleComponent(vid, 1010); // Nitro
    }*/
    if(Vehicles[vehicleid][hydros] > 0)
    {
        AddVehicleComponent(vid, 1087); // Hydros
    }
    for(new i=0;i<13;i++)
	{
		VehicleWeapon[vehicleid][i] 	= 0;
		VehicleAmmo[vehicleid][i]     = 0;
	}
	HasGunCrates[vehicleid] = 0;
    HasBulletCrates[vehicleid] = 0;
    HasCGuns[vehicleid] = 0;
	comps[vehicleid][guns] = 0;
	comps[vehicleid][oil] = 0;
	comps[vehicleid][alchool] = 0;
	comps[vehicleid][money] = 0;
	comps[vehicleid][drugs] = 0;
	comps[vehicleid][stuffs] = 0;
	compscar[vehicleid] = 0;
	SetVehicleVirtualWorld(vehicleid,0);
	SetTimerEx("SetVehicleWorld", 500, false,"dd", vehicleid, Vehicles[vehicleid][vw]);
	if(vehicleid<sizeof(Vehicles)) LinkVehicleToInterior(vehicleid, 0);
	if(Gas[vehicleid]<20) Gas[vehicleid]+=20;
	UnlockVehicle(vehicleid);
	if(!strcmp(Vehicles[vehicleid][carowner], "NoBodY", false) || Vehicles[vehicleid][carprice] > 0) UnlockVehicle(vehicleid);
	else LockVehicle(-1, vehicleid);
	SetTimerEx("ModCar", 1000, 0, "d", vehicleid);
	ChangeVehiclePaintjob(vehicleid, Vehicles[vehicleid][paintjob]);
			            if(Vehicles[vehicleid][carmodel] == 448 || Vehicles[vehicleid][carmodel] == 461 || Vehicles[vehicleid][carmodel] == 462 || Vehicles[vehicleid][carmodel] == 463 || Vehicles[vehicleid][carmodel] == 468 || Vehicles[vehicleid][carmodel] == 471 || Vehicles[vehicleid][carmodel] == 481 ||
            Vehicles[vehicleid][carmodel] == 509 || Vehicles[vehicleid][carmodel] == 510 || Vehicles[vehicleid][carmodel] == 521 || Vehicles[vehicleid][carmodel] == 522 || Vehicles[vehicleid][carmodel] == 523 || Vehicles[vehicleid][carmodel] == 581 || Vehicles[vehicleid][carmodel] == 586)
            {
            UnlockVehicle(vehicleid);
            }
	if(Vehicles[vehicleid][carmodel] == 470)
 SetVehicleHealth(vehicleid, 2500);
 else
 SetVehicleHealth(vehicleid, 1000);


	return 1;
}
Reply
#2

This line makes no sense, remove it
PHP код:
if(vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid); 
Reply
#3

done
still gettin same error
start from 255 to 607 cars
Reply
#4

Show how you are declaring vehicle variables
Vehicle, VehicleWeapon, VehicleAmmo, comps..ect

EDIT: you can make another easy solution tho
PHP код:
public OnVehicleSpawn(vehicleid)
{
if(
vehicleid 254) return 0;
dini_IntSet(CarFile(vehicleid), "carmaterials"0);
SetVehicleEngineOff(vehicleid);
    
AddVehicleComponent(vehicleid1010);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa0]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa1]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa2]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa3]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa4]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa5]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa6]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa7]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa8]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa9]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa10]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa11]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa12]);
    
AddVehicleComponent(vehicleidVehicles[vehicleid][compa13]);
    if(
vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid);
    
vTrailer[vehicleid] = 0;
    
CarBombActive[vehicleid] = 0;
    
vehicleGuns[vehicleid] = 0;
    
vehicleBullets[vehicleid] = 0;
    new 
vid GetPlayerVehicleID(vehicleid);
    
/*if(Vehicles[vehicleid][nitro] > 0)
    {
        AddVehicleComponent(vid, 1010); // Nitro
    }*/
    
if(Vehicles[vehicleid][hydros] > 0)
    {
        
AddVehicleComponent(vid1087); // Hydros
    
}
    for(new 
i=0;i<13;i++)
    {
        
VehicleWeapon[vehicleid][i]     = 0;
        
VehicleAmmo[vehicleid][i]     = 0;
    }
    
HasGunCrates[vehicleid] = 0;
    
HasBulletCrates[vehicleid] = 0;
    
HasCGuns[vehicleid] = 0;
    
comps[vehicleid][guns] = 0;
    
comps[vehicleid][oil] = 0;
    
comps[vehicleid][alchool] = 0;
    
comps[vehicleid][money] = 0;
    
comps[vehicleid][drugs] = 0;
    
comps[vehicleid][stuffs] = 0;
    
compscar[vehicleid] = 0;
    
SetVehicleVirtualWorld(vehicleid,0);
    
SetTimerEx("SetVehicleWorld"500false,"dd"vehicleidVehicles[vehicleid][vw]);
    if(
vehicleid<sizeof(Vehicles)) LinkVehicleToInterior(vehicleid0);
    if(
Gas[vehicleid]<20Gas[vehicleid]+=20;
    
UnlockVehicle(vehicleid);
    if(!
strcmp(Vehicles[vehicleid][carowner], "NoBodY"false) || Vehicles[vehicleid][carprice] > 0UnlockVehicle(vehicleid);
    else 
LockVehicle(-1vehicleid);
    
SetTimerEx("ModCar"10000"d"vehicleid);
    
ChangeVehiclePaintjob(vehicleidVehicles[vehicleid][paintjob]);
                        if(
Vehicles[vehicleid][carmodel] == 448 || Vehicles[vehicleid][carmodel] == 461 || Vehicles[vehicleid][carmodel] == 462 || Vehicles[vehicleid][carmodel] == 463 || Vehicles[vehicleid][carmodel] == 468 || Vehicles[vehicleid][carmodel] == 471 || Vehicles[vehicleid][carmodel] == 481 ||
            
Vehicles[vehicleid][carmodel] == 509 || Vehicles[vehicleid][carmodel] == 510 || Vehicles[vehicleid][carmodel] == 521 || Vehicles[vehicleid][carmodel] == 522 || Vehicles[vehicleid][carmodel] == 523 || Vehicles[vehicleid][carmodel] == 581 || Vehicles[vehicleid][carmodel] == 586)
            {
            
UnlockVehicle(vehicleid);
            }
    if(
Vehicles[vehicleid][carmodel] == 470)
 
SetVehicleHealth(vehicleid2500);
 else
 
SetVehicleHealth(vehicleid1000);
    return 
1;

Reply
#5

Your MAX_VEHICLE or whatever your Vehicles's size is is defined to 255 for some reason, that means every vehicle you make more than that will crash at this function.

PHP код:
    if(vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid); 
move this to the start of your OnVehicleSpawn or increase the limit to like 500.

and @Shinja things that doesn't make sense to you aren't necessarily wrong, it means you don't have enough knowledge, stop giving bs to random people, vehicleid>254 is exactly equal to vehicle>sizeof(Vehicles), but WAY WAY wrong, since he would need to change this whenever he increases the limit.

EDIT: solution got bolded^^
Reply
#6

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
that means every vehicle you make more than that will crash at this function.

PHP код:
    if(vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid); 
You just agreed with me by yourself thought, vehicleid > sizeof(Vehicles) will make runtime "Array out of bounds".

YOUR EDIT: return 0; will just cancel next steps for this vehicleid so he won't get runtimes, and yeah he need to change it whenever he increase the limit but it's still a solution
Reply
#7

It doesn't, using vehicleid as Vehicles index (Vehicles[vehicleid]) does.
Learn these errors, stop assuming random things just because they did happen once.

Quote:
Originally Posted by Shinja
Посмотреть сообщение
YOUR EDIT: Yes it's same but return 0; is not to Destroy it, destroying it which will make the runtime because the id is out of bounds, but return 0; will just cancel next steps for this vehicleid so he won't get runtimes, and yeah he need to change it whenever he increase the limit but it's still a solution
You have not idea what out of bounds means ! it means you are using an invalid index in an array, The vehicle is valid, there is no slot for it in the array.
It's a bad solution, it's a bad coding habit you are promoting, you are giving him more problems in his later codes.
Reply
#8

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
It doesn't, using vehicleid as Vehicles index (Vehicles[vehicleid]) does.
Ok let's say i'm wrong in this part, but the solution i gave him is still correct, same as your, only thing is sizeof(Vehicles) is dynamic
Note: Last reply with you
Reply
#9

actually im not using MAX VEHICLES define so i could load more and i dont really get how many vehicles i have loaded here as Pro Gamer said that might be the problem
anyway here is the enum of Vehicles and idk how to increase it to max vehicles im using for example 500
Код:
enum fcar
{
	materialtype,
	carmaterials,
	carmodel,
	Float:fx,
	Float:fy,
	Float:fz,
	Float:fa,
	color1,
	color2,
	respawn,
	carteam,
	cartype, // 0 = driveable by all // 1 family restricted // 2 job restricted // 3 rentable
	modeltype, //0 car // 1 heli // 2 plane // 3 boat
	jobname[20],
	biznumber,
	plate[10],
	tmplocked,
	tmplockedby,
	carowner[MAX_STRING],
	carprice,
	reset,
	Components[CAR_COMPONENTS],
	dupekey[MAX_STRING],
	vw,
	paintjob,
	nitro,
	hydros,
	carspawneed,
	bool:vActive, // if the vehicle is active.
	bool:vSpawned,
	vRID,
veehid,
 compa0,
 compa1,
 compa2,
 compa3,
 compa4,
 compa5,
 compa6,
 compa7,
 compa8,
 compa9,
 compa10,
 compa11,
 compa12,
 compa13
}

new Vehicles[][fcar]
Reply
#10

[]<< That is empty? Just like that? LOL, then there's probably a loads of data after it, if you are using static data like that whats the purpose of your save system?

Btw if you are using it like that then you can't use vehicleid as index directly just like that, since you can't add vehicles from IG.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)