24.12.2011, 12:32
How to make a Command for vehicles with ZCMD and sscanf
pawn Код:
/veh [modelid/name]
/veh [modelid/name]
CMD:veh(playerid, params[])
{
if(!strlen(params)) return SendClientMessage(playerid, COLOUR_RED, "Error. Usage: /veh [modelid]"); //Check if the parameter exists.
if(strval(params) > 611 || strval(params) < 400) return SendClientMessage(playerid, COLOUR_RED, "Error. Models are between 400 and 611."); //Check if it's between 400 and 611.
new Float:x, Float:y, Float:z; //Declare position variables.
GetPlayerPos(playerid, x, y, z); //Get the players position, the vehicle will spawn in this position.
PutPlayerInVehicle(playerid, CreateVehicle(strval(params), x, y, z, 0.0, -1, -1, -1), 0); //Create the vehicle, put the player in it as the driver.
return 1; //Tell the server the command executed succesfully.
}
CMD:veh(playerid,params[])
{
new id,cor,cor1;
if(sscanf(params, "ddd", id, cor,cor1)) SendClientMessage(playerid,-1, ,"USO: /veh [model] [color1] [color2]");
else if (id < 400 || id > 611) SendClientMessage(playerid,-1, "Between 400 and 611");
else if (cor < 0 || cor1 > 126) SendClientMessage(playerid,-1, "Color between 0 and 126");
else
{
if(IsPlayerAdmin(playerid))
{
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid, X,Y,Z);
CreateVehicle(id,X+2,Y,Z,0.0,cor,cor1,-1);
}
}
return 1;
}
E:\SA-MP\SA-MP SERVERS\My Projects\0.3d\DM,STUNT,RACE\Live Stunting(ENG) [DM,STUNT,RACE,DERBY]\gamemodes\1.0.pwn(1775) : warning 211: possibly unintended assignment
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Warning.
CMD:v(playerid, params[])
{
if(IsInDm[playerid] == 1)
{
SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Deathmatch. Type /leavedm to leave deathmatch.");
}
else if(IsInDerby[playerid] == 1)
{
SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Derby. Type /leavederby to leave derby.");
}
else if(IsInRace[playerid] == 1)
{
SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Race. Type /leaverace to leave race.");
}
else if(IsInParkour[playerid] == 1)
{
SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Parkour. Type /leaveparkour to leave parkour.");
}
else if(IsInDrift[playerid] == 1)
{
SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Drift. Type /leavedrift to leave .");
}
else
{
if(!strlen(params)) return SendClientMessage(playerid, ERROR, "Usage: /veh [Name/Modelid]");
new iModel = 0;
if(!IsNumeric(params))
{
for(new i; i < sizeof(vNames); i++)
{
if(!strcmp(params, vNames[i]))
{
iModel = i;
break;
}
}
if(iModel == 0) return SendClientMessage(playerid, ERROR, "Invalid Vehicle.");
}
else iModel = strval(params);
if(iModel > 611 || iModel < 400) return SendClientMessage(playerid, ERROR, "Vehicle models are between 400 and 611.");
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
PutPlayerInVehicle(playerid, CreateVehicle(iModel, x, y, z, 0.0, -1, -1, -1), 0);
}
return 1;
}
iModel = i;
iModel = i+400;