dcmd_house(playerid, params[]) { new command[128], owner[255]; if(Account[playerid][pAdminLevel] >= 20) { if (sscanf(params, "s", command)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /house <add>"); else { if(strcmp(command,"add", true ) == 0) { if (sscanf(command, "s", owner)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /house add <owner>"); else { new Float:x,Float:y,Float:z,Float:angle; GetPlayerPos(playerid,x,y,z); GetPlayerFacingAngle(playerid,angle); AddHouse(owner,x,y,z,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),angle,0/*exitx*/,0/*exity*/,0/*exitz*/,1337/*exitinterior*/,0/*exitangle*/,0/*owned*/,0/*rentable*/,0/*rentcost*/,0/*houseprice*/,0/*locked*/); } } else { return SendClientMessage(playerid, 0xFF0000AA, "Invalid house command."); } } } return 1; }
sscanf(command, "s", owner)
sscanf(command,"ss",command,owner)
Originally Posted by JaTochNietDan
pawn Код:
pawn Код:
|
Originally Posted by JaTochNietDan
Actually my code makes no sense either. I appear to have misread your original code.
What exactly does it do wrong with the original code you posted? |
sscanf(params,"ss",command,owner)
Originally Posted by JaTochNietDan
Actually try:
pawn Код:
|
// somewhere on the top of the script:
#define COLOR_RED 0xFF0000AA
dcmd_house(playerid, params[])
{
new
cmd2[64], // second command will be stored in this array
string[128]; // for additional parameters in the second commands (see below)
if (Account[playerid][pAdminLevel] >= 20) // admin level check
{
if (sscanf(params, "s ", cmd2) != 0) // cmd2 will become the first parameter, sscanf is tricked with the extra space to stop processing the string
{
// send proper command syntax for player, include only the first parameters (the second commands):
SendClientMessage(playerid, COLOR_RED, "Usage: /house <add / whatever more params here>");
return 1; // exit
}
if (strcmp("add", cmd2, true, 3) == 0) // check if the first 3 (!) characters of cmd2 are the same as 'add'
{
if (sscanf(params, "ss", cmd2, string) != 0) // read the additional parameters after the second command
{
// send proper syntax again, now with the needed parameters for the second command the player typed (in this case 'add'):
SendClientMessage(playerid, COLOR_RED, "Usage: /house <add> <owner>"); // we are expecting only one extra parameter, the 'owner'
return 1; // exit
}
/*
// you may want to add this extra check for more security ^^
if (strlen (string) > MAX_PLAYER_NAME) return SendClientMessage(playerid, COLOR_RED, "The given owner name is too long!");
*/
// command code follows (yours), note that string is now the owner
new
Float:x,
Float:y,
Float:z,
Float:angle;
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,angle);
AddHouse(owner,x,y,z,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),angle,0/*exitx*/,0/*exity*/,0/*exitz*/,1337/*exitinterior*/,0/*exitangle*/,0/*owned*/,0/*rentable*/,0/*rentcost*/,0/*houseprice*/,0/*locked*/);
return 1; // successful, exit
}
/*
// additional second commands may come here in this format:
else if (strcmp("remove", cmd2, true, 6) == 0)
{
// check for other params if any
// check validness of other params
// code follows
}
else if (strcmp("info", cmd2, true, 4) == 0)
{
// check for other params if any
// check validness of other params
// code follows
}
// you may add as many as you want
*/
}
/*
// you may want to send this warning if player if not a level 20 admin:
else SendClientMessage(playerid, SOME_COLOR, "This is a level 20 admin command!");
*/
return 1; // end of command
}