SA-MP Forums Archive
WHat is wrong in this code? - 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: WHat is wrong in this code? (/showthread.php?tid=196971)



WHat is wrong in this code? - Kyle_Olsen - 07.12.2010

Okey, this is my vehicle initation process...

Код:
stock InitVehicles()
{
print("Initiating vehicle initiation process");
	new Vehicle[16];
	for(new i = 0; i < 500; i++)
	{
	
	    format(Vehicle, sizeof(Vehicle), "V_%d", i);
	    if(djIsSet(VEHICLES_FILE, Vehicle) )
	    {
	    
	        format(Vehicle, sizeof(Vehicle), "V_%d/PosX", i);
	        Vehicles[i][CarPosX] = djFloat(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/PosY", i);
	        Vehicles[i][CarPosY] = djFloat(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/PosZ", i);
	        Vehicles[i][CarPosZ] = djFloat(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/ZAngle", i);
	        Vehicles[i][CarZAngle] = djFloat(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Model", i);
	        Vehicles[i][CarModel] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Owner", i);
	        Vehicles[i][Owner] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Plate", i);
	        Vehicles[i][Plate] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Col1", i);
	        Vehicles[i][CarColour1] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Col2", i);
	        Vehicles[i][CarColour2] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Group", i);
	        Vehicles[i][CarGroup] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Locked", i);
	        Vehicles[i][Locked] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        format(Vehicle, sizeof(Vehicle), "V_%d/Alarm", i);
	        Vehicles[i][Alarm] = djInt(VEHICLES_FILE, Vehicle, true);
	        
	        CarCount++;
	        
            if(Vehicles[i][CarModel] != 537 && Vehicles[i][CarModel] != 538 && Vehicles[i][CarModel] != 569 && 570 && Vehicles[i][CarModel] != 590 )
            {
            	Vehicles[i][GameID] = AddStaticVehicleEx(Vehicles[i][CarModel], Vehicles[i][CarPosX], Vehicles[i][CarPosY], Vehicles[i][CarPosZ], Vehicles[i][CarZAngle], Vehicles[i][CarColour1], Vehicles[i][CarColour2], 3600 );
            	SetVehicleNumberPlate(i, Vehicles[i][Plate]);
            	new engine,lights,alarm,doors,bonnet,boot,objective;
                GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamsEx(i,engine,lights,Vehicles[i][Alarm],Vehicles[i][Locked],bonnet,boot,objective);
            }
            
            printf( "[system] InitVehicles(): Vehicle %d has spawned (spawned from %s).", i, VEHICLES_FILE);
     }
 }
}
It doesn't give any errors or warnings, but it seems that if(djIsSet(VEHICLES_FILE, Vehicle) ) is blocking it... My problem is that the cars don't spawn. I've checked my file, and I'm sure they are all set. Here is something out of my file for you to see
Код:
"V_1":{"Col1":-1,"Col2":-1,"Group":1,"Model":596,"Plate":LSGV-DMV,"Locked":0,"Alarm":0,"Owner":0,"PosX":1545.589233,"PosY":-1680.213623,"PosZ":5.612060,"ZAngle":91.456855}
So what is wrong here? Is it a bug maybe?


Re: WHat is wrong in this code? - DVDK - 07.12.2010

Debug everything.


Re: WHat is wrong in this code? - Toreno - 07.12.2010

I guess everything, what's that supposed to do?


Re: WHat is wrong in this code? - Kyle_Olsen - 08.12.2010

It's supposed to load the vehicles from the Vehicles.json file and add them to the server.

It's 0.3c so it's supposed to fix doors and car alarm of the vehicle, and plates too.


Re: WHat is wrong in this code? - Kyle_Olsen - 09.12.2010

Sorry for double post, but I can't figure what's wrong here. I don't think the error is in this code, but yeah.


Re: WHat is wrong in this code? - 6d - 09.12.2010

Vehicles[i][CarPosX], show us those enum.
be sure that. fx:
pawn Код:
enum VehicleInfo
{
Float:CarPosX,
}
ALSO there is a edit button for something,
double post again and i WONT help you.
And "What is wrong with this title?",
please put a descriptive title next time.

Hope i helped.


Re: WHat is wrong in this code? - Hal - 09.12.2010

[QUOTE=Kyle_Olsen;946302]Okey, this is my vehicle initation process...

pawn Код:
stock InitVehicles()
{
print("Initiating vehicle initiation process");
    new Vehicle[16];
    for(new i = 0; i < 500; i++)
    {
   
        format(Vehicle, sizeof(Vehicle), "V_%d", i);
        if(djIsSet(VEHICLES_FILE, Vehicle) )
        {
       
            format(Vehicle, sizeof(Vehicle), "V_%d/PosX", i);
            Vehicles[i][CarPosX] = djFloat(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/PosY", i);
            Vehicles[i][CarPosY] = djFloat(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/PosZ", i);
            Vehicles[i][CarPosZ] = djFloat(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/ZAngle", i);
            Vehicles[i][CarZAngle] = djFloat(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Model", i);
            Vehicles[i][CarModel] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Owner", i);
            Vehicles[i][Owner] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Plate", i);
            Vehicles[i][Plate] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Col1", i);
            Vehicles[i][CarColour1] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Col2", i);
            Vehicles[i][CarColour2] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Group", i);
            Vehicles[i][CarGroup] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Locked", i);
            Vehicles[i][Locked] = djInt(VEHICLES_FILE, Vehicle, true);
           
            format(Vehicle, sizeof(Vehicle), "V_%d/Alarm", i);
            Vehicles[i][Alarm] = djInt(VEHICLES_FILE, Vehicle, true);
           
            CarCount++;
           
            if(Vehicles[i][CarModel] != 537 && Vehicles[i][CarModel] != 538 && Vehicles[i][CarModel] != 569 && 570 && Vehicles[i][CarModel] != 590 )
            {
                Vehicles[i][GameID] = AddStaticVehicleEx(Vehicles[i][CarModel], Vehicles[i][CarPosX], Vehicles[i][CarPosY], Vehicles[i][CarPosZ], Vehicles[i][CarZAngle], Vehicles[i][CarColour1], Vehicles[i][CarColour2], 3600 );
                SetVehicleNumberPlate(i, Vehicles[i][Plate]);
                new engine,lights,alarm,doors,bonnet,boot,objective;
                GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
                SetVehicleParamsEx(i,engine,lights,Vehicles[i][Alarm],Vehicles[i][Locked],bonnet,boot,objective);
            }
           
            printf( "[system] InitVehicles(): Vehicle %d has spawned (spawned from %s).", i, VEHICLES_FILE);
     }
     else
     {
          print("Cars Not Found!")
     }
 }
}
the indentation got messed up so tidy it up before you use it.


See what i added at the bottom of the script, if it prints that in the console, then you know its djIsSet

Why did you remove the MAX_VEHICLES define? just use it for simplicity.


PS: djInt is for integers. You should change that.