Command doesn't work for me
#1

Hi, now I need help with another command. So I edited the /engine command some days ago, it is working, but when I am in a job vehicle (trashmaster, forklift, etc) then it says unknown command. Seems like I'm the only one that it doesn't work for, it works for the other players as far as I know. It sometimes works and sometimes not.
Here's the code:

Код:
code removed, I don't want to release it :P
This is what crashdetect says:
Код:
[08:26:28] [debug] AMX backtrace:
[08:26:28] [debug] #0 001e7860 in public cmd_engine (playerid=0, params[]=@006ef004 "") at C:\Users\User\Documents\Desktop\Los Santos Life Roleplay\gamemodes\LSLRP.pwn:28644
[08:26:28] [debug] #1 native CallLocalFunction () from samp03svr
[08:26:28] [debug] #2 0001dfc0 in public OnPlayerCommandText (playerid=0, cmdtext[]=@006eefe4 "/engine") at C:\Users\User\Documents\Desktop\Los Santos Life Roleplay\pawno\include\zcmd.inc:102
What is wrong in the command?
Reply
#2

Which one is line:28644?
Reply
#3

Код:
CarData[id][carFaction]
"id" is the problem. Next time post the full logs crashdetect reports so it'll be easier for everyone.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Код:
CarData[id][carFaction]
"id" is the problem. Next time post the full logs crashdetect reports so it'll be easier for everyone.
Ah, the id... I used "id" instead of "carid" before I asked for help, so I just changed it to "carid" before asking for help. No, it's not the problem. :P It was acting the same way when it was "id". The problem is something else as I can't start the job vehicles.
Quote:
Originally Posted by Stinged
Посмотреть сообщение
Which one is line:28644?
It's in the code. :P
Reply
#5

"id" shouldn't be used anyway, you want the data of a specific vehicle (the one the player is in). Post the full logs please otherwise we don't know what we are looking for (the value passed and the last in-bound index ARE important - assuming it is a run time error 4).
Reply
#6

Код:
SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[09:00:28] filterscripts = ""  (string)
[09:00:28] 
[09:00:28] Server Plugins
[09:00:28] --------------
[09:00:28]  Loading plugin: crashdetect.so
[09:00:28]   CrashDetect v4.15.1 is OK.
[09:00:28]   Loaded.
[09:00:28]  Loading plugin: sscanf.so
[09:00:28] 

[09:00:28]  ===============================

[09:00:28]       sscanf plugin loaded.     

[09:00:28]          Version:  2.8.2        

[09:00:28]    © 2012 Alex "******" Cole  

[09:00:28]  ===============================

[09:00:28]   Loaded.
[09:00:28]  Loading plugin: streamer.so
[09:00:28] 

*** Streamer Plugin v2.8.1 by Incognito loaded ***

[09:00:28]   Loaded.
[09:00:28]  Loading plugin: Whirlpool.so
[09:00:28]  
[09:00:28]  ==================
[09:00:28]  
[09:00:28]   Whirlpool loaded
[09:00:28]  
[09:00:28]  ==================
[09:00:28]  
[09:00:28]   Loaded.
[09:00:28]  Loading plugin: mysql.so
[09:00:28]  >> plugin.mysql: R39-5 successfully loaded.
[09:00:28]   Loaded.
[09:00:28]  Loading plugin: nativechecker.so
[09:00:28]   Loaded.
[09:00:28]  Loaded 6 plugins.

[09:00:28] 
[09:00:28] Filterscripts
[09:00:28] ---------------
[09:00:28]   Loaded 0 filterscripts.

[09:00:28]  
[09:00:28]  
[09:00:28]  
[09:00:28]  ======================================= 
[09:00:28]  |                                     | 
[09:00:28]  |        YSI version 3.09.0684        | 
[09:00:28]  |        By Alex "******" Cole        | 
[09:00:28]  |                                     | 
[09:00:28]  ======================================= 
[09:00:28]  
[09:00:28] [SQL] Connection to "127.0.0.1" passed!
[09:00:28] Los Santos Life Roleplay
[09:00:28] Number of vehicle models: 4
[09:02:02] [debug] Run time error 4: "Array index out of bounds"
[09:02:02] [debug]  Accessing element at negative index -1
[09:02:02] [debug] AMX backtrace:
[09:02:02] [debug] #0 001e7860 in public cmd_engine (playerid=1, params[]=@006ef004 "") at C:\Users\User\Documents\Desktop\Los Santos Life Roleplay\gamemodes\LSLRP.pwn:28644
[09:02:02] [debug] #1 native CallLocalFunction () from samp03svr
[09:02:02] [debug] #2 0001dfc0 in public OnPlayerCommandText (playerid=1, cmdtext[]=@006eefe4 "/engine") at C:\Users\User\Documents\Desktop\Los Santos Life Roleplay\pawno\include\zcmd.inc:102
Reply
#7

So -1 is passed in an array in the command (not some function is called in the command). Let's review the code:
pawn Код:
if (carid != -1 && Car_IsOwner(playerid, carid) || CoreVehicles[vehicleid][vehTemporary] || (PlayerData[playerid][pFaction] != -1 && CarData[carid][carFaction] == GetFactionType(playerid)) || IsAJobVehicle(vehicleid) || PlayerData[playerid][pCarKeys] == carid) // line 28644
Which are the arrays?

pawn Код:
CoreVehicles[vehicleid][vehTemporary]

PlayerData[playerid][pFaction]

CarData[carid][carFaction]

PlayerData[playerid][pCarKeys]
"playerid" cannot be an invalid so the two left are:
pawn Код:
CoreVehicles[vehicleid][vehTemporary]

CarData[carid][carFaction]
"vehicleid" will be either 0 or the vehicle ID so we exclude it as well and the one left is:
pawn Код:
CarData[carid][carFaction]
and we know that "carid" can be -1 in certain situations. Where it gets odd is that you check about the value being different than -1 so if it was an invalid, the rest shouldn't be checked at all. Can you add printf to debug it manually?
Reply
#8

try this:
PHP код:
CMD:engine(playeridparams[])
{
    new
        
vehicleid GetPlayerVehicleID(playerid),
        
carid,
         
vehiclemodel;
    if (!
IsPlayerInAnyVehicle(playerid))
        {
    
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.");
        }    
    
carid Car_GetID(vehicleid);
    
    if (
carid != -&& Car_IsOwner(playeridcarid) || CoreVehicles[vehicleid][vehTemporary] || (PlayerData[playerid][pFaction] != -&& CarData[carid][carFaction] == GetFactionType(playerid)) || IsAJobVehicle(vehicleid) || PlayerData[playerid][pCarKeys] == carid// line 28644
    
{
        
vehiclemodel GetVehicleModel(vehicleid);
        
        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(vehiclemodel));
            }
            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(vehiclemodel));
            }
        }
    }
    else 
SendErrorMessage(playerid"You don't have the keys to this vehicle.");
    return 
1;

Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
So -1 is passed in an array in the command (not some function is called in the command). Let's review the code:
pawn Код:
if (carid != -1 && Car_IsOwner(playerid, carid) || CoreVehicles[vehicleid][vehTemporary] || (PlayerData[playerid][pFaction] != -1 && CarData[carid][carFaction] == GetFactionType(playerid)) || IsAJobVehicle(vehicleid) || PlayerData[playerid][pCarKeys] == carid) // line 28644
Which are the arrays?

pawn Код:
CoreVehicles[vehicleid][vehTemporary]

PlayerData[playerid][pFaction]

CarData[carid][carFaction]

PlayerData[playerid][pCarKeys]
"playerid" cannot be an invalid so the two left are:
pawn Код:
CoreVehicles[vehicleid][vehTemporary]

CarData[carid][carFaction]
"vehicleid" will be either 0 or the vehicle ID so we exclude it as well and the one left is:
pawn Код:
CarData[carid][carFaction]
and we know that "carid" can be -1 in certain situations. Where it gets odd is that you check about the value being different than -1 so if it was an invalid, the rest shouldn't be checked at all. Can you add printf to debug it manually?
Uh, what do I need to printf? I'm confused. :P
Reply
#10

What I meant is before the reported line to use printf to print the value of "carid". But.. just for the sake of debugging, you might as well separate each condition and add print messages:
pawn Код:
if (carid != -1)
{
    print("carid != -1");
    if (Car_IsOwner(playerid, carid)) printf("Car_IsOwner(%i, %i)", playerid, carid);
    else if (CoreVehicles[vehicleid][vehTemporary]) printf("CoreVehicles[%i][vehTemporary]", vehicleid);
    ...
}
Continue with the rest.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)