Vehicle doesn't spawn
#1

Hello, I have been trying to make a copy of my /veh command but then with the mselection this is the /veh cmd:


PHP код:
CMD:veh(playeridparams[]) {
    if(
PlayerInfo[playerid][pAdmin] >= 4) {
        new
            
iVehicle,
            
iColors[2];
        if(
sscanf(params"iii"iVehicleiColors[0], iColors[1])) {
            
SendClientMessageEx(playeridCOLOR_GREY"USAGE: /veh [model ID] [color 1] [color 2]");
        }
        else if(!(
400 <= iVehicle <= 611)) {
            
SendClientMessageEx(playeridCOLOR_GRAD2"Invalid model specified (model IDs start at 400, and end at 611).");
        }
        else if(
IsATrain(iVehicle)) {
            
SendClientMessageEx(playeridCOLOR_GREY"Trains cannot be spawned during runtime.");
        }
        else if(!(
<= iColors[0] <= 255 && <= iColors[1] <= 255)) {
            
SendClientMessageEx(playeridCOLOR_GRAD2"Invalid color specified (IDs start at 0, and end at 255).");
        }
        else for(new 
iIteratoriIterator sizeof(CreatedCars); iIterator++) if(iIterator >= 49) {
            return 
SendClientMessageEx(playeridCOLOR_GRAD1"The maximum limit of 50 spawned vehicles has been reached.");
        }
        else if(
CreatedCars[iIterator] == INVALID_VEHICLE_ID) {
            new
                
FloatfVehPos[4];
            new 
fVW GetPlayerVirtualWorld(playerid);
            
GetPlayerPos(playeridfVehPos[0], fVehPos[1], fVehPos[2]);
            
GetPlayerFacingAngle(playeridfVehPos[3]);
            
CreatedCars[iIterator] = CreateVehicle(iVehiclefVehPos[0], fVehPos[1], fVehPos[2], fVehPos[3], iColors[0], iColors[1], -1);
            
VehicleFuel[CreatedCars[iIterator]] = 100.0;
            
Vehicle_ResetData(CreatedCars[iIterator]);
            
LinkVehicleToInterior(CreatedCars[iIterator], GetPlayerInterior(playerid));
            
SetVehicleVirtualWorld(CreatedCars[iIterator], fVW);
            return 
SendClientMessageEx(playeridCOLOR_GREY"Vehicle spawned!");
        }
    }
    else 
SendClientMessageEx(playeridCOLOR_GRAD1"You are not authorized to use that command.");
    return 
1;
}] 
This is the list to spawn it with the MSelection as you can see I masked things with numbers to see how far it comes in the console, it doesn't go further then number 2


PHP код:
if(listid == AdminCarList)
    {
        new
            
iVehicle,
            
iColors[2];
        if(
IsATrain(iVehicle)) {
            
SendClientMessageEx(playeridCOLOR_GREY"Trains cannot be spawned during runtime.");
        }
        else for(new 
iIteratoriIterator sizeof(CreatedCars); iIterator++) if(iIterator >= 49) {
            return 
SendClientMessageEx(playeridCOLOR_GRAD1"The maximum limit of 50 spawned vehicles has been reached.");
        }
        else if(
CreatedCars[iIterator] == INVALID_VEHICLE_ID) {
            new
                
FloatfVehPos[4];
            
//new iVehicle[MAX_PLAYERS];
            
print("1");
            new 
fVW GetPlayerVirtualWorld(playerid);
            
GetPlayerPos(playeridfVehPos[0], fVehPos[1], fVehPos[2]);
            
GetPlayerFacingAngle(playeridfVehPos[3]);
            
CreatedCars[iIterator] = CreateVehicle(iVehiclefVehPos[0], fVehPos[1], fVehPos[2], fVehPos[3], iColors[0], iColors[1], -1);
            print(
"2");
            
VehicleFuel[CreatedCars[iIterator]] = 100.0;
            
Vehicle_ResetData(CreatedCars[iIterator]);
            print(
"3");
            
LinkVehicleToInterior(CreatedCars[iIterator], GetPlayerInterior(playerid));
            print(
"4");
            
SetVehicleVirtualWorld(CreatedCars[iIterator], fVW);
            return 
SendClientMessage(playerid0xFF0000FF"Admin vehicle spawned");
        }
        else 
SendClientMessage(playerid0xFF0000FF"Canceled Admin vehicle selection");
        return 
1;
    } 
Reply
#2

1. use fVehPosX fVehPosY etc. it is faster than multi dimensional.
2. Can you post the code of Vehicle_ResetData or have you checked the logs with the crashdetect plugin?
Reply
#3

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
1. use fVehPosX fVehPosY etc. it is faster than multi dimensional.
2. Can you post the code of Vehicle_ResetData or have you checked the logs with the crashdetect plugin?
This is the Vehicle_ResetData and about the FVehpos I just keep it like this for now just need this to work so vehicles spawn
PHP код:
Vehicle_ResetData(iVehicleID) {
    if(
GetVehicleModel(iVehicleID)) {
        for(new 
cv 0cv 6cv++)
        {
            
CrateVehicleLoad[iVehicleID][vCrateID][cv] = -1;
        }
        
Vehicle_Armor(iVehicleID);
        
LockStatus{iVehicleID} = 0;
        
VehicleStatus{iVehicleID} = 0;
        
arr_Engine{iVehicleID} = 0;
        
stationidv[iVehicleID][0] = 0;
        
TruckContents{iVehicleID} = 0;
        
TruckDeliveringTo[iVehicleID] = INVALID_BUSINESS_ID;
        
VehicleFuel[iVehicleID] = 100.0;
        if(
LockStatus{iVehicleID}) {
            foreach(new 
iPlayer)
            {
                if(
PlayerInfo[i][pLockCar] == iVehicleID) {
                    
PlayerInfo[i][pLockCar] = INVALID_VEHICLE_ID;
                }
            }
        }
        if(
VehicleBomb{iVehicleID} == 1) {
            foreach(new 
iPlayer)
            {
                if(
PlacedVehicleBomb[i] == iVehicleID) {
                    
VehicleBomb{iVehicleID} = 0;
                    
PlacedVehicleBomb[i] = INVALID_VEHICLE_ID;
                    
PickUpC4(i);
                    
PlayerInfo[i][pC4Used] = 0;
                    
PlayerInfo[i][pC4Get] = 1;
                }
            }
        }
    }

Reply
#4

Anyone ?
Reply
#5

Код:
        else if(CreatedCars[iIterator] == INVALID_VEHICLE_ID) { 

            new 
                Float: fVehPos[4]; 
            //new iVehicle[MAX_PLAYERS]; 
            print("1"); 
            new fVW = GetPlayerVirtualWorld(playerid); 
            GetPlayerPos(playerid, fVehPos[0], fVehPos[1], fVehPos[2]); 
            GetPlayerFacingAngle(playerid, fVehPos[3]); 
            CreatedCars[iIterator] = CreateVehicle(iVehicle, fVehPos[0], fVehPos[1], fVehPos[2], fVehPos[3], iColors[0], iColors[1], -1); 
            print("2"); 
            VehicleFuel[CreatedCars[iIterator]] = 100.0; 
            Vehicle_ResetData(CreatedCars[iIterator]); 
            print("3"); 
            LinkVehicleToInterior(CreatedCars[iIterator], GetPlayerInterior(playerid)); 
            print("4"); 
            SetVehicleVirtualWorld(CreatedCars[iIterator], fVW); 
            return SendClientMessage(playerid, 0xFF0000FF, "Admin vehicle spawned");  //Here
        }
may i ask you why you are using return ?
Reply
#6

From my silly experince.
Don't return break all incoming values and cancel all perivous action? unless you didn't control it with conditional (if)
may i ask you to try it without if it works ?
Reply
#7

Quote:
Originally Posted by AstroPoid
Посмотреть сообщение
From my silly experince.
Don't return break all incoming values and cancel all perivous action? unless you didn't control it with conditional (if)
may i ask you to try it without if it works ?
The return does not make any difference here. It's at the very end of the block and the other block cannot be executed even if it continues to run (the else cannot execute, since the if did execute).

Furthermore, a return does stop the current function from executing but it does NOT cancel any previous actions. That's impossible.

Also, OP said it didn't run further than print("2"), then how would the return play a role?

If code does not continue to run without the use of return, break or continue (which were not used anywhere near the print "2") there are most likely only 2 causes:

- An error that stops the execution for good reasons (most likely Array index out of bounds)
- An Infinite Loop

Since there is no loop, you must look for an error.
If you have crashdetect, see crashs.log. If you don't, install it and you will see where and what error occured.
Reply
#8

are u using SA:MP 0.3.DL or 0.3.8?
try to debug this vehicle's ID, Coordinates and Virtual World when the code ends.
Reply
#9

Im not using 0.3.8 and as for the crash log there is nothing in there
Reply
#10

Thing is I just want this to work because otherwise i'm unable to /destroycars and some functions are coming out of /veh and made a new command so admins see the MSelection menu to spawn cars insteat of /veh [VEHID] [Col1][Col2]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)