/Spawncar is not functional
#1

Basically I have been working on a /spawncar command that will spawn a car for administrators upon a command. Each time I type /spawncar it will give the error message stating I have not filled in the other required fields, although I have.

Here is the script:
pawn Код:
command(spawncar, playerid, vehicleid, params[])
{
    new carid, string[128], Float: CarToX, Float: CarToY, Float: CarToZ, physical_car_id, c1, c2;
    if(sscanf(params, "ddd", carid, c1, c2))
    {
        if(Player[playerid][AdminLevel] >= 1)
        {
            SendClientMessage(playerid, ERROR, "SYNTAX: /spawncar [vehicleid] [colour 1] [colour 2]");
        }
        else
        {
            SendClientMessage(playerid, ERROR, "ERROR: You are not authorized to use this command!");
        }
    }
    else
    {
        if(Player[playerid][AdminLevel] >= 1)
        {
            if(CarCount < MAX_VEHICLES)
            {
                if(carid < 400 || carid > 611)
                {
                    SendClientMessage(playerid, ERROR, "ERROR: Valid car IDs start from 400, ending at 611.");
                    return 1;
                }

                GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
                physical_car_id = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, -1, -1, -1);
                ChangeVehicleColor(carid, c1, c2);

                SendClientMessage(playerid, WHITE, string);

                AdminSpawned[SpawnedVehicles] = physical_car_id;
                SpawnedVehicles++;

                PutPlayerInVehicle(playerid, physical_car_id, 0);
                LinkVehicleToInterior(physical_car_id, GetPlayerInterior(playerid));
                SetVehicleVirtualWorld(physical_car_id, GetPlayerVirtualWorld(playerid));
                new engine, lights, alarm, doors, bonnet, boot, objective;
                GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
            }
            else
            {
                SendClientMessage(playerid, WHITE, "Despawn the current spawned vehicles before spawning any more (or attempting to do so).");
            }
        }
    }
    return 1;
}
Reply
#2

pawn Код:
command(spawncar, playerid, vehicleid, params[])
{
    new carid, string[128], Float: CarToX, Float: CarToY, Float: CarToZ, physical_car_id, c1, c2;

    if(Player[playerid][AdminLevel] < 1)
        return SendClientMessage(playerid, ERROR, "ERROR: You are not authorized to use this command!");

    if(sscanf(params, "ddd", carid, c1, c2))
        return SendClientMessage(playerid, ERROR, "SYNTAX: /spawncar [vehicleid] [colour 1] [colour 2]");

    if(CarCount >= MAX_VEHICLES)
        return SendClientMessage(playerid, WHITE, "Despawn the current spawned vehicles before spawning any more (or attempting to do so).");

    if(carid < 400 || carid > 611)
        return SendClientMessage(playerid, ERROR, "ERROR: Valid car IDs start from 400, ending at 611.");

    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    physical_car_id = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, -1, -1, -1);
    ChangeVehicleColor(carid, c1, c2);

    SendClientMessage(playerid, WHITE, string);

    AdminSpawned[SpawnedVehicles] = physical_car_id;
    SpawnedVehicles++;

    PutPlayerInVehicle(playerid, physical_car_id, 0);
    LinkVehicleToInterior(physical_car_id, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(physical_car_id, GetPlayerVirtualWorld(playerid));
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
    return 1;
}
Reply
#3

May I ask what was changed so I can avoid this problem in the future?
Reply
#4

Well, to be honest, I don't know what you did wrong. This is the way I work and it probably should work. Check yourself out what I did and see what you did wrong.

I found it's easier to work this way. First check if the stats / variables / etc are false and return the command and then do the command part. I find it much more easier this way.

ps: Does the command work ?
Reply
#5

I am going to test it now.
Reply
#6

Ok. Let me know how it ended up. I can't guarantee the command I made works... I'll make it work if it doesn't, don't worry.
Reply
#7

No, it did not work...
Reply
#8

You get any error or ?
Reply
#9

Nope, it is the same problem as before, it keeps saying "SYNTAX: /spawncar [Vehicle ID] [Color 1] [Color 2]".
Reply
#10

Ops, sorry. Here's the working version:
pawn Код:
command(spawncar, playerid, vehicleid, params[])
{
    new carid, string[128], Float: CarToX, Float: CarToY, Float: CarToZ, physical_car_id, c1, c2;

    if(Player[playerid][AdminLevel] < 1)
        return SendClientMessage(playerid, ERROR, "ERROR: You are not authorized to use this command!");

    if(sscanf(params, "ddd", carid, c1, c2))
        return SendClientMessage(playerid, ERROR, "SYNTAX: /spawncar [vehicleid] [colour 1] [colour 2]");

    if(CarCount >= MAX_VEHICLES)
        return SendClientMessage(playerid, WHITE, "Despawn the current spawned vehicles before spawning any more (or attempting to do so).");

    if(carid < 400 || carid > 611)
        return SendClientMessage(playerid, ERROR, "ERROR: Valid car IDs start from 400, ending at 611.");

    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    physical_car_id = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, -1, -1, -1);
    ChangeVehicleColor(carid, c1, c2);

    SendClientMessage(playerid, WHITE, string);

    AdminSpawned[SpawnedVehicles] = physical_car_id;
    SpawnedVehicles++;

    PutPlayerInVehicle(playerid, physical_car_id, 0);
    LinkVehicleToInterior(physical_car_id, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(physical_car_id, GetPlayerVirtualWorld(playerid));
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
    return 1;
}
LE: Wait, that won't work either, let me see what's wrong with sscanf plugin. I think I did something wrong, I get "sscanf error: System not initialised." error in log.

LE2: Alright, tested the command myself and it works for me perfectly. Try to update your sscanf2 to last version from here.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)