Unknown command
#1

Hi, I've added rental vehicles to my server today, added a check to /engine if player has keys to the rental vehicle, and now I'm getting unknown command when I try to /engine a vehicle that I don't rent, it works when I /engine a vehicle that I rent. Everything works except that when I /engine an unrented vehicle.
Here's the code:
Код:
CMD:engine(playerid, params[])
{
	new
		vehicleid,
		carid,
 		model;

	if (IsPlayerInAnyVehicle(playerid)) {
		vehicleid = GetPlayerVehicleID(playerid);
		model = GetVehicleModel(vehicleid);
		carid = Car_GetID(vehicleid);
	}
	else return SendErrorMessage(playerid, "You are not in any vehicle.");
		
	if (!IsEngineVehicle(vehicleid))
	    return SendErrorMessage(playerid, "This vehicle doesn't have an engine.");
		
	if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
	    return SendErrorMessage(playerid, "You can't do this as you're not the driver.");
		
	if (PlayerData[playerid][pInjured])
 		return SendErrorMessage(playerid, "You can't do this while being injured or dead.");

	if (ReturnVehicleHealth(vehicleid) <= 300)
		return SendErrorMessage(playerid, "This vehicle is totalled and can't be started.");
		
	if (CoreVehicles[vehicleid][vehFuel] < 1)
		return SendErrorMessage(playerid, "The fuel tank is empty.");
	
	if (carid != -1 && Car_IsOwner(playerid, carid) || CoreVehicles[vehicleid][vehTemporary] || CoreVehicles[vehicleid][vehRental]  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] || (PlayerData[playerid][pFaction] != -1 && CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid)
	{
		switch (GetEngineStatus(vehicleid))
		{
			case false:
			{
				SetEngineStatus(vehicleid, true);
				ShowPlayerFooter(playerid, "You have ~g~started~w~ the engine!");
				SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "** %s inserts the key into the ignition and starts the engine of the %s.", ReturnName(playerid, 0), ReturnVehicleModelName(model));
			}
			case true:
			{
				SetEngineStatus(vehicleid, false);
				ShowPlayerFooter(playerid, "You have ~r~stopped~w~ the engine!");
				SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "** %s inserts the key into the ignition and stops the engine of the %s.", ReturnName(playerid, 0), ReturnVehicleModelName(model));
			}
		}
	}
	else SendErrorMessage(playerid, "You don't have the keys to this vehicle.");
	return 1;
}
Crashdetect outputs this:
Код:
[14:21:12] [debug] Run time error 4: "Array index out of bounds"
[14:21:12] [debug]  Accessing element at negative index -1
[14:21:12] [debug] AMX backtrace:
[14:21:12] [debug] #0 0018a534 in public cmd_engine (4, 7397284) from LSLRP.amx
[14:21:12] [debug] #1 native CallLocalFunction () from samp03svr
[14:21:12] [debug] #2 00017ca8 in public OnPlayerCommandText (4, 7397252) from LSLRP.amx
I already had this problem, but I could fix it somehow, now it happens again. Does anyone know how to fix it?
Reply
#2

What do you have at OnPlayerCommandText?
Reply
#3

PHP код:
CMD:engine(playeridparams[])
{
    new
        
vehicleid,
        
carid,
         
model;

    if (
IsPlayerInAnyVehicle(playerid)) {
        
vehicleid GetPlayerVehicleID(playerid);
        
model GetVehicleModel(vehicleid);
        
carid Car_GetID(vehicleid);
    }
    else
    {
        
SendErrorMessage(playerid"You are not in any vehicle.");
    }
    if (!
IsEngineVehicle(vehicleid))
    {
         
SendErrorMessage(playerid"This vehicle doesn't have an engine.");
     }

    if (
GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
    {
         
SendErrorMessage(playerid"You can't do this as you're not the driver.");
    }
    if (
PlayerData[playerid][pInjured])
     {
          
SendErrorMessage(playerid"You can't do this while being injured or dead.");
    }
    if (
ReturnVehicleHealth(vehicleid) <= 300)
    {
        
SendErrorMessage(playerid"This vehicle is totalled and can't be started.");
    }
    if (
CoreVehicles[vehicleid][vehFuel] < 1)
    {
         
SendErrorMessage(playerid"The fuel tank is empty.");
    }
    if (
carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] || CoreVehicles[vehicleid][vehRental]  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid)
    {
        switch (
GetEngineStatus(vehicleid))
        {
            case 
false:
            {
                
SetEngineStatus(vehicleidtrue);
                
ShowPlayerFooter(playerid"You have ~g~started~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and starts the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
            case 
true:
            {
                
SetEngineStatus(vehicleidfalse);
                
ShowPlayerFooter(playerid"You have ~r~stopped~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and stops the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
        }
    }
    else 
SendErrorMessage(playerid"You don't have the keys to this vehicle.");
    return 
1;

Reply
#4

Quote:
Originally Posted by Meller
Посмотреть сообщение
What do you have at OnPlayerCommandText?
It's zmd.
Quote:
Originally Posted by FuNkYTheGreat
Посмотреть сообщение
PHP код:
CMD:engine(playeridparams[])
{
    new
        
vehicleid,
        
carid,
         
model;
    if (
IsPlayerInAnyVehicle(playerid)) {
        
vehicleid GetPlayerVehicleID(playerid);
        
model GetVehicleModel(vehicleid);
        
carid Car_GetID(vehicleid);
    }
    else
    {
        
SendErrorMessage(playerid"You are not in any vehicle.");
    }
    if (!
IsEngineVehicle(vehicleid))
    {
         
SendErrorMessage(playerid"This vehicle doesn't have an engine.");
     }
    if (
GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
    {
         
SendErrorMessage(playerid"You can't do this as you're not the driver.");
    }
    if (
PlayerData[playerid][pInjured])
     {
          
SendErrorMessage(playerid"You can't do this while being injured or dead.");
    }
    if (
ReturnVehicleHealth(vehicleid) <= 300)
    {
        
SendErrorMessage(playerid"This vehicle is totalled and can't be started.");
    }
    if (
CoreVehicles[vehicleid][vehFuel] < 1)
    {
         
SendErrorMessage(playerid"The fuel tank is empty.");
    }
    if (
carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] || CoreVehicles[vehicleid][vehRental]  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid)
    {
        switch (
GetEngineStatus(vehicleid))
        {
            case 
false:
            {
                
SetEngineStatus(vehicleidtrue);
                
ShowPlayerFooter(playerid"You have ~g~started~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and starts the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
            case 
true:
            {
                
SetEngineStatus(vehicleidfalse);
                
ShowPlayerFooter(playerid"You have ~r~stopped~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and stops the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
        }
    }
    else 
SendErrorMessage(playerid"You don't have the keys to this vehicle.");
    return 
1;

It's the same code, also you removed the returns which will totally mess the code up.
Reply
#5

PHP код:
CMD:engine(playeridparams[])
{
    new 
vehicleidcaridmodel;
    if(!
IsPlayerInAnyVehicle(playerid)) return SendErrorMessage(playerid"You are not in any vehicle.");
    if(!
IsEngineVehicle(vehicleid)) return SendErrorMessage(playerid"This vehicle doesn't have an engine.");
    if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendErrorMessage(playerid"You can't do this as you're not the driver.");
    if(
PlayerData[playerid][pInjured]) return SendErrorMessage(playerid"You can't do this while being injured or dead.");
    if(
ReturnVehicleHealth(vehicleid) <= 300) return SendErrorMessage(playerid"This vehicle is totalled and can't be started.");
    if(
CoreVehicles[vehicleid][vehFuel] < 1) return SendErrorMessage(playerid"The fuel tank is empty.");
    if(
carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] || CoreVehicles[vehicleid][vehRental]  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid)
    {
        switch (
GetEngineStatus(vehicleid))
        {
            case 
false:
            {
                
SetEngineStatus(vehicleidtrue);
                
ShowPlayerFooter(playerid"You have ~g~started~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and starts the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
            case 
true:
            {
                
SetEngineStatus(vehicleidfalse);
                
ShowPlayerFooter(playerid"You have ~r~stopped~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and stops the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
        }
    }
    
SendErrorMessage(playerid"You don't have the keys to this vehicle.");
    return 
1;

Show us the used stocks like IsVehicleEngine...ect
Are you putting the code inside OnPlayerCommandText brackets? if you have some lines there show us
Reply
#6

PHP код:
CMD:engine(playeridparams[])
{
    new 
vehicleidcaridmodel;
    if(
IsPlayerInAnyVehicle(playerid)) vehicleid GetPlayerVehicleID(playerid), model GetVehicleModel(vehicleid), carid Car_GetID(vehicleid);
    else return 
SendErrorMessage(playerid"You are not in any vehicle.");
    if(!
IsEngineVehicle(vehicleid)) return SendErrorMessage(playerid"This vehicle doesn't have an engine.");
    if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendErrorMessage(playerid"You can't do this as you're not the driver.");
    if(
PlayerData[playerid][pInjured]) return SendErrorMessage(playerid"You can't do this while being injured or dead.");
    if(
ReturnVehicleHealth(vehicleid) <= 300) return SendErrorMessage(playerid"This vehicle is totalled and can't be started.");
    if(
CoreVehicles[vehicleid][vehFuel] < 1) return SendErrorMessage(playerid"The fuel tank is empty.");
    if(
carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] || CoreVehicles[vehicleid][vehRental]  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid)
    {
        switch(
GetEngineStatus(vehicleid))
        {
            case 
false:
            {
                
SetEngineStatus(vehicleidtrue);
                
ShowPlayerFooter(playerid"You have ~g~started~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and starts the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
            case 
true:
            {
                
SetEngineStatus(vehicleidfalse);
                
ShowPlayerFooter(playerid"You have ~r~stopped~w~ the engine!");
                
SendNearbyMessage(playerid30.0COLOR_PURPLE"** %s inserts the key into the ignition and stops the engine of the %s."ReturnName(playerid0), ReturnVehicleModelName(model));
            }
        }
        return 
1;
    }
    
SendErrorMessage(playerid"You don't have the keys to this vehicle.");
    return 
1;

Reply
#7

Guys, you don't have to just edit the code a little and post it. Every single code here is the same as mine. Also there's nothing to do with OnPlayerCommandText, because I use zcmd, and zcmd is done with that.
The problem started happening after I added
Код:
CoreVehicles[vehicleid][vehRental]  && PlayerData[playerid][pRentedVehicle] == vehicleid
into the check. That's the problem. Everything else works, I told you. Only thing that doesn't work is /engine on a rental vehicle that's not being rented.
Reply
#8

What's the size of CoreVehicles?
And can you post the code for Car_IsOwner?
Reply
#9

You should assign values for your variables in if statement sentence.

For Example:
PHP код:
if(CoreVehicles[vehicleid][vehRental] == 1
So the whole if statement sentence should be like this:
PHP код:
if(carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] == || CoreVehicles[vehicleid][vehRental] == 1  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] == || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid
Reply
#10

Quote:
Originally Posted by Stinged
Посмотреть сообщение
What's the size of CoreVehicles?
And can you post the code for Car_IsOwner?
Size is MAX_VEHICLES, and Car_IsOwner has nothing to do with it I guess.
But here it is:
Код:
Car_IsOwner(playerid, carid)
{
	if (!PlayerData[playerid][pLogged] || PlayerData[playerid][pID] == -1)
	    return 0;

    if ((CarData[carid][carExists] && CarData[carid][carOwner] != 0) && CarData[carid][carOwner] == PlayerData[playerid][pID])
		return 1;

	return 0;
}
Quote:
Originally Posted by Juvanii
Посмотреть сообщение
You should assign values for your variables in if statement sentence.

For Example:
PHP код:
if(CoreVehicles[vehicleid][vehRental] == 1
So the whole if statement sentence should be like this:
PHP код:
if(carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] == || CoreVehicles[vehicleid][vehRental] == 1  && PlayerData[playerid][pRentedVehicle] == vehicleid || CoreVehicles[vehicleid][vehJob] == || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || PlayerData[playerid][pCarKeys] == carid
Not really,
Код:
CoreVehicles[vehicleid][vehRental] == 1
is same as
Код:
CoreVehicles[vehicleid][vehRental]
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)