Server says command doesn't exist, but it still executes
#1

I have a /veh command that when performed, it works, but the server says that the command doesn't exist.

pawn Код:
//The Command itself

CMD:veh(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    if(Player[playerid][AdminLevel] >= 4)
    {
        new string[128], vehid, color1, color2;
        if(sscanf(params, "iii", vehid, color1, color2)) return SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
        {
            if(vehid >= 400 || vehid <= 611)
            {
                new Float:pX, Float:pY, Float:pZ, Float:pA;
                GetPlayerPos(playerid, pX, pY, pZ);
                GetPlayerFacingAngle(playerid, pA);
                CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
                format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
                SendClientMessage(playerid, COLOR_WHITE, string);
            }
        }
    }
    else return SendClientMessage(playerid, -1, ADMIN);
    return 1;
}
pawn Код:
//What the server does when a command actually doesn't exist

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(!success)
    {
        new string[128];
        format(string, sizeof(string), "{C0C0C0}The command {FF0000}%s {C0C0C0}does not exist, please use /help.", cmdtext);
        SendClientMessage(playerid, -1, string);
    }
    return 1;
}
Reply
#2

debug it. For example:
pawn Код:
CMD:debug(playerid, params[])
{
    if(something)
    {
        printf("debug 1");
        something = 1;
        printf("debug 2");
        something2 = 0
        printf("debug 3");
    }
    else return SendClientMessage(playerid, -1, "blahblah");
    printf("debug 4");
    return true;
}
Reply
#3

Quote:
Originally Posted by Don_Cage
Посмотреть сообщение
debug it. For example:
pawn Код:
CMD:debug(playerid, params[])
{
    if(something)
    {
        printf("debug 1");
        something = 1;
        printf("debug 2");
        something2 = 0
        printf("debug 3");
    }
    else return SendClientMessage(playerid, -1, "blahblah");
    printf("debug 4");
    return true;
}
Could you explain it a little more? I don't understand from this example.
Reply
#4

Код:
CMD:veh(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    if(Player[playerid][AdminLevel] >= 4)
    {
        new string[128], vehid, color1, color2;
        if(sscanf(params, "iii", vehid, color1, color2)) return SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
        {
            if(vehid >= 400 || vehid <= 611)
            {
                new Float:pX, Float:pY, Float:pZ, Float:pA;
                GetPlayerPos(playerid, pX, pY, pZ);
                GetPlayerFacingAngle(playerid, pA);
                CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
                format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
                SendClientMessage(playerid, COLOR_WHITE, string);
            }
        }
    }
    else 
    {
        SendClientMessage(playerid, -1, ADMIN);
    }
    return 1;
}
Try that
Reply
#5

I think it's because you're returning a SendClientMessage and a 1, try to remove that return and keep the 1; only. As Blademaster^^ said above.
Reply
#6

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
I think it's because you're returning a SendClientMessage and a 1, try to remove that return and keep the 1; only. As Blademaster^^ said above.
No, that's not why. The SendClientMessage only returns if the player isn't an admin, the return true; will be performed if the command is successful.

It's most likely caused because of an invalid array size, as you stated the command did execute but still returns false regardless. I've had a similar issue before.

Can you show us what you have defined as "ADMIN"? What DaniceMcHarley said is still somewhat right.

Also, there is no point using a size 128 string when you're only using max. 60 characters.
Reply
#7

The problem is in GetVehicleName function and it goes out of bounds (run time error 4). In order to solve that, check if the modelid is valid (between 400-611) and change to AND and not OR:
pawn Код:
if(vehid >= 400 && vehid <= 611)
Reply
#8

So only way is problem in GetVehicleName function, show GetVehicleName
Reply
#9

pawn Код:
CMD:veh(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    if(Player[playerid][AdminLevel] >= 4)
    {
        new string[128], vehid, color1, color2;
        if(sscanf(params, "iii", vehid, color1, color2)) return SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
        if(vehid >= 400 && vehid <= 611)
        {
            new Float:pX, Float:pY, Float:pZ, Float:pA;
            GetPlayerPos(playerid, pX, pY, pZ);
            GetPlayerFacingAngle(playerid, pA);
            CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
            format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
        else
        {
            SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
        }
    }
    else
    {
         SendClientMessage(playerid, -1, ""ADMIN"");
    }
    return 1;
}
I did some structure changes and about ADMIN if it's defined something like this:
#define ADMIN "you are not an admin"
Then you should script it as I have done in the message
I hope that it will work any feedback would be appreciated!.
Reply
#10

Does the command work ?
Reply
#11

Quote:
Originally Posted by DTV
Посмотреть сообщение
Could you explain it a little more? I don't understand from this example.
What I ment was that you add
pawn Код:
printf("DEBUG: 1");
After each line to see which line that fails.




EDIT: Also don't forget to do DEBUG: 1
DEBUG: 2
DEBUG: 3 etc etc.. So you don't just do DEBUG: 1 under each line since that would be impossible to know which one it was
Reply
#12

Quote:
Originally Posted by Stanford
Посмотреть сообщение
pawn Код:
CMD:veh(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    if(Player[playerid][AdminLevel] >= 4)
    {
        new string[128], vehid, color1, color2;
        if(sscanf(params, "iii", vehid, color1, color2)) return SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
        if(vehid >= 400 && vehid <= 611)
        {
            new Float:pX, Float:pY, Float:pZ, Float:pA;
            GetPlayerPos(playerid, pX, pY, pZ);
            GetPlayerFacingAngle(playerid, pA);
            CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
            format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
        else
        {
            SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
        }
    }
    else
    {
         SendClientMessage(playerid, -1, ""ADMIN"");
    }
    return 1;
}
I did some structure changes and about ADMIN if it's defined something like this:
#define ADMIN "you are not an admin"
Then you should script it as I have done in the message
I hope that it will work any feedback would be appreciated!.
Why you're doubling the (") in that case you'll have 3 (").
it must be only ,ADMIN it's right.
Reply
#13

Quote:
Originally Posted by Don_Cage
Посмотреть сообщение
What I ment was that you add
pawn Код:
printf("DEBUG: 1");
After each line to see which line that fails.




EDIT: Also don't forget to do DEBUG: 1
DEBUG: 2
DEBUG: 3 etc etc.. So you don't just do DEBUG: 1 under each line since that would be impossible to know which one it was
Alright, I did that and it ended on this line:

pawn Код:
format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
pawn Код:
//what "GetVehicleName(vehid)" is

stock GetVehicleName(vehicleid)
{
    new string[28];
    format(string, sizeof(string), "%s", VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return string;
}
pawn Код:
//What I have for VehicleNames

new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
    "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};
Reply
#14

Instead of this:
Код:
stock GetVehicleName(vehicleid)
{
    new string[28];
    format(string, sizeof(string), "%s", VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return string;
}
You can do just this:
Код:
#define GetVehicleName(%0) VehicleNames[GetVehicleModel(%0) - 400];
Which is much more efficient.

It doesn't fix your problem though. Try installing the Crashdetect plugin (you can find it on ****** or on these forums in the Plugins section). It might print valuable crash information in your console when you try to run the command again.
Reply
#15

Quote:
Originally Posted by DTV
Посмотреть сообщение
Alright, I did that and it ended on this line:

pawn Код:
format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
pawn Код:
//what "GetVehicleName(vehid)" is

stock GetVehicleName(vehicleid)
{
    new string[28];
    format(string, sizeof(string), "%s", VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return string;
}
pawn Код:
//What I have for VehicleNames

new VehicleNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
    "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
    "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
    "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
    "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};
Show me the "debugged" cmd
Reply
#16

pawn Код:
CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
You pass the modelid as vehicleid which is incorrect and if you had checked in GetVehicleName the modelid, you could prevent it.

Change to:
pawn Код:
new veh_ID = CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(veh_ID));
pawn Код:
stock GetVehicleName(vehicleid)
{
    new string[28] = "N/A";
    if (GetVehicleModel(vehicleid)) strcat((string[0] = '\0', string), VehicleNames[GetVehicleModel(vehicleid) - 400], sizeof (string));
    return string;
}
Reply
#17

Try this.
Код:
CMD:veh(playerid, params[])
{
	new vehid, color1, color2;
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, -1, "ERROR: You are not logged in.");
    if(Player[playerid][AdminLevel] < 4) return SendClientMessage(playerid, -1, "ERROR: Admin 4+!");
    if(sscanf(params, "iii", vehid, color1, color2)) return SendClientMessage(playerid, -1, "Command Usage: /veh [vehicle id] [color1] [color2]");
	if(400 < (vehid) > 611) return SendClientMessage(playerid, -1, "ERROR: For vehicle id use from 400 to 611!");
	else
	{
        new string[128], Float:p[4];
        GetPlayerPos(playerid, p[0], p[1], p[2]);
		GetPlayerFacingAngle(playerid, p[3]);
        CreateVehicle(vehid, p[0]+5, p[1]+5, p[2], p[3], color1, color2, 180);
        format(string, sizeof(string), "[AdminCMD] You have just spawned a vehicle.");
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Reply
#18

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(vehid));
You pass the modelid as vehicleid which is incorrect and if you had checked in GetVehicleName the modelid, you could prevent it.

Change to:
pawn Код:
new veh_ID = CreateVehicle(vehid, pX+5, pY+5, pZ, pA, color1, color2, 180);
format(string, sizeof(string), "[AdminCMD] You have just spawned a %s.", GetVehicleName(veh_ID));
pawn Код:
stock GetVehicleName(vehicleid)
{
    new string[28] = "N/A";
    if (GetVehicleModel(vehicleid)) strcat((string[0] = '\0', string), VehicleNames[GetVehicleModel(vehicleid) - 400], sizeof (string));
    return string;
}
This fixed it. Thanks man.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)