PDA

View Full Version : /Spawncar is not functional


nmader
17/09/2012, 10:00 PM
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:
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;
}

antonio112
17/09/2012, 10:19 PM
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;
}

nmader
17/09/2012, 10:20 PM
May I ask what was changed so I can avoid this problem in the future?

antonio112
17/09/2012, 10:23 PM
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 ?

nmader
17/09/2012, 10:25 PM
I am going to test it now.

antonio112
17/09/2012, 10:29 PM
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. :)

nmader
17/09/2012, 10:33 PM
No, it did not work... ???

antonio112
17/09/2012, 10:39 PM
You get any error or ?

nmader
17/09/2012, 10:42 PM
Nope, it is the same problem as before, it keeps saying "SYNTAX: /spawncar [Vehicle ID] [Color 1] [Color 2]".

antonio112
17/09/2012, 11:18 PM
Ops, sorry. Here's the working version:
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 (http://forum.sa-mp.com/showthread.php?t=120356).

mamorunl
17/09/2012, 11:34 PM
command(spawncar, playerid, vehicleid, params[]) < What kind of syntax does this one belong to?

Also: !sscanf is if it was completed without error.

if(sscanf(params, "ddd", c, c1, c2)) return echo("Error");

This is the correct syntax.

nmader
17/09/2012, 11:50 PM
Getting this now: ERROR: Valid car IDs start from 400, ending at 611.