10.07.2010, 11:23
Код:
//------------------------------------------------------------------------------------------------------
public cmdGetArgInt(args[], &idx, &intvalue)
{
new i = 0;
// skip spaces
while (args[idx] && (args[idx] <= ' ')) idx++;
// copy value
while (args[idx] && (args[idx] > ' '))
{
tmp[i] = args[idx];
idx++;
i++;
// Слишком большое число!
if (i >= sizeof(tmp)) return 0;
}
if (i == 0) return 0;
tmp[i] = EOS;
intvalue = strval(tmp);
if (intvalue == 0)
{
if (args[idx - 1] == '0' && args[idx] == EOS)
return 1;
else
return 0;
}
return 1;
}
//------------------------------------------------------------------------------------------------------
public cmdGetArgHex(args[], &idx, &hexvalue)
{
new digits = 0;
// skip spaces
while (args[idx] && (args[idx] <= ' ')) idx++;
// check hex format 0x
if ((args[idx] != EOS) && (args[idx + 1] != EOS) && (args[idx] == '0') && ((args[idx + 1] == 'x') || (args[idx + 1] == 'X'))) {}
else return 0;
idx += 2;
hexvalue = 0;
// copy value
while (args[idx] && (args[idx] > ' '))
{
switch (args[idx])
{
case '0' .. '9':
{
hexvalue = (hexvalue << 4) | (args[idx] - '0');
}
case 'a' .. 'f':
{
hexvalue = (hexvalue << 4) | (args[idx] - ('a' - 10));
}
case 'A' .. 'F':
{
hexvalue = (hexvalue << 4) | (args[idx] - ('A' - 10));
}
default:
{
return 0;
}
}
idx++;
digits++;
if (digits > 8) return 0;
}
//if (hexvalue == 0 && digits == 0) return 0;
if (digits != 8) return 0;
return 1;
}
//------------------------------------------------------------------------------------------------------
public cmdGetArgPla(args[], &idx, &pid)
{
new i = 0;
// skip spaces
while (args[idx] && (args[idx] <= ' ')) idx++;
// copy value
while (args[idx] && (args[idx] > ' '))
{
tmp[i] = args[idx];
idx++;
i++;
// Слишком большое число!
if (i >= sizeof(tmp)) return 0;
}
if (i == 0) return 0;
tmp[i] = EOS;
pid = ReturnUser(tmp);
if (pid == INVALID_PLAYER_ID) return 0;
return 1;
}
//------------------------------------------------------------------------------------------------------
public cmdGetArgFlo(args[], &idx, &Float:floatvalue)
{
new i = 0;
// skip spaces
while (args[idx] && (args[idx] <= ' ')) idx++;
// copy value
while (args[idx] && (args[idx] > ' '))
{
tmp[i] = args[idx];
idx++;
i++;
// Слишком большое число!
if (i >= sizeof(tmp)) return 0;
}
if (i == 0) return 0;
tmp[i] = EOS;
floatvalue = floatstr(tmp);
return 1;
}
//------------------------------------------------------------------------------------------------------
public cmdGetArgStr(args[], &idx, retstr[])
{
new i = 0;
// skip spaces
while (args[idx] && (args[idx] <= ' ')) idx++;
// copy value
while (args[idx] && (args[idx] > ' '))
{
retstr[i] = args[idx];
idx++;
i++;
// Слишком большая строка
if (i >= 32) return 0;
}
if (i == 0) return 0;
retstr[i] = EOS;
return 1;
}
//------------------------------------------------------------------------------------------------------
public cmdGetArgZtr(args[], &idx)
{
// skip spaces
while (args[idx] && (args[idx] <= ' ')) idx++;
if (args[idx] == EOS) return 0;
return 1;
}
//------------------------------------------------------------------------------------------------------
тут ктото писал насчет сишных строковых функиях что они быстрее) полностью согласен)
но неизменил код.. так как есть антифлуд команд) так что выигрыш в скорости не такой уж большой)
USAGE:
examples from gamemode...
Код:
////////////////////////////////////////////////////////////////////////////////////////////
case 40:
{
new Float:r = 7.0,
Float:x, Float:y, Float:z;
cmdGetArgFlo(args, idx, r);
GetPlayerPos(gpid, x, y, z);
DisablePlayerCheckpoint(gpid);
SetPlayerCheckpoint(gpid, x, y, z, r);
format(string, sizeof(string), "SetPlayerCheckpoint(%d, %.1f, %.1f, %.1f, %.1f)", gpid, x, y, z, r);
SendClientMessage(playerid, 0xCC55FFFF, string);
}
////////////////////////////////////////////////////////////////////////////////////////////
Код:
if (!cmdGetArgPla(args, idx, gpid))
{
SendClientMessage(playerid, COLOR_WRONG_ARG, cs_ThisPlayerIsNotOnline);
return 1;
}
Код:
////////////////////////////////////////////////////////////////////////////////////////////
case 31:
{
new veh;
new Float:x = 0,
Float:y = 0,
Float:z = 0;
if (!cmdGetArgInt(args, idx, veh) || !GetVehicleModel(veh))
{
SendClientMessageRus(playerid, COLOR_WRONG_ARG, " Введите ид тачки.");
return 1;
}
cmdGetArgFlo(args, idx, x);
cmdGetArgFlo(args, idx, y);
cmdGetArgFlo(args, idx, z);
SetVehicleVelocity(veh, x, y, z);
format(string, sizeof(string), " SetVehicleVelocity(%d, %.2f, %.2f, %.2f)", veh, x, y, z);
SendClientMessage(playerid, 0x7FFF30FF, string);
}
////////////////////////////////////////////////////////////////////////////////////////////
Код:
//-----------------------------------------------------------------------------------------------------
// Шаблон редакторов !!!
#define Case0(%0) case %0: if ((res = editor_fn(id, %0)) == 0)
#define Case1(%0,%1) case %0: if ((res = editor_fn(id, %0, %1)) == 0)
#define Case2(%0,%1,%2) case %0: if ((res = editor_fn(id, %0, %1, %2)) == 0)
#define Case3(%0,%1,%2,%3) case %0: if ((res = editor_fn(id, %0, %1, %2, %3)) == 0)
#define Case4(%0,%1,%2,%3,%4) case %0: if ((res = editor_fn(id, %0, %1, %2, %3, %4)) == 0)
#define Case5(%0,%1,%2,%3,%4,%5) case %0: if ((res = editor_fn(id, %0, %1, %2, %3, %4, %5)) == 0)
public OnCmd_Adm_TpEdit(pid, tid, cmd[], args[]) // tpedit
{
#define editor_fn teleportEdit
#define en cs_NameEditorTp
new ploc = gPI[pid][pLoc],
idx = 0,
cmdid,
id = tid,
Float:f1 = 0.0, Float:f2 = 0.0,
res = -100,
t1 = 0,
t2 = 0;
for (cmdid = 0; cmdid < tpeditor_CmdCount; cmdid++)
{
if ( strcmp(cmd, cTpEditorCmd [ cmdid ] ) == 0) break;
}
cmdGetArgInt(args, idx, t1);
cmdGetArgInt(args, idx, t2);
idx = 0;
cmdGetArgFlo(args, idx, f1);
cmdGetArgFlo(args, idx, f2);
GetPlayerPos(pid, fpos[0], fpos[1], fpos[2]);
GetPlayerFacingAngle(pid, fpos[3]);
format(string, sizeof(string), " cmdid = %d", cmdid);
SendClientMessageRus(pid, COLOR_TP_EDIT, string);
switch (cmdid)
{
Case4(tpeditor_P0, fpos[0], fpos[1], fpos[2], ploc)
{
format(string, sizeof(string), " %s: ID: %d, p0 = (%.1f, %.1f, %.1f), loc: %d.", en, id, fpos[0], fpos[1], fpos[2], ploc);
}
Case5(tpeditor_P1, fpos[0], fpos[1], fpos[2], fpos[3], ploc)
{
format(string, sizeof(string), " %s: ID: %d, p1 = (%.1f, %.1f, %.1f, %.1f), loc: %d.", en, id, fpos[0], fpos[1], fpos[2], fpos[3], ploc);
}
Case0(tpeditor_SaveAll)
{
format(string, sizeof(string), " %s: Телепорты сохранены в файл: %s.", en, FILENAME_TELEPORTS);
}
Case0(tpeditor_Update)
{
format(string, sizeof(string), " %s: ID: %d, Обновлен.", en, id);
}
Case0(tpeditor_TogSilent)
{
format(string, sizeof(string), " %s: ID: %d, (FLAG) Режим тихой телепортации: %s.", en, id, cOnOff[res]);
}
Case0(tpeditor_TogVis)
{
format(string, sizeof(string), " %s: ID: %d, (FLAG) Видимость: %s.", en, id, cOnOff[res]);
}
Case0(tpeditor_TogVeh)
{
format(string, sizeof(string), " %s: ID: %d, (FLAG) Разрешить телепорт ТС: %s.", en, id, cOnOff[res]);
}
Case0(tpeditor_TogEdit)
{
format(string, sizeof(string), " %s: ID: %d, (FLAG) Редактирование: %s.", en, id, cOnOff[res]);
}
Case0(tpeditor_TogEnabled)
{
format(string, sizeof(string), " %s: ID: %d, (FLAG) Состояние: %s.", en, id, cOnOff[res]);
}
Case0(tpeditor_TogObjPickup)
{
format(string, sizeof(string), " %s: ID: %d, Тип объекта телепорта сменен. Пикап: %s.", en, id, cYesNo[res]);
}
Case1(tpeditor_GotoP0, pid)
{
format(string, sizeof(string), " %s: ID: %d, Телепорт к входу.", en, id);
}
Case1(tpeditor_GotoP1, pid)
{
format(string, sizeof(string), " %s: ID: %d, Телепорт к выходу.", en, id);
}
Case0(tpeditor_Delete)
{
format(string, sizeof(string), " %s: ID: %d, Удален.", en, id);
}
Case1(tpeditor_Rad, f1)
{
format(string, sizeof(string), " %s: ID: %d, Радиус: %d.", en, id, f1);
}
Case1(tpeditor_Model, t1)
{
format(string, sizeof(string), " %s: ID: %d, Модель: %d.", en, id, t1);
}
Case1(tpeditor_Info, pid)
{
return 1;
}
default:
{
format(string, sizeof(string), " %s: Неправильная команда!", en);
SendClientMessageRus(pid, COLOR_WRONG_ARG, string);
return 1;
}
}
if (res >= 0)
{
SendClientMessageRus(pid, COLOR_TP_EDIT, string);
return 1;
}
else
{
switch (res)
{
case tpeditor_err_not_editable:
{
format(string, sizeof(string), " %s: ID: %d, Редактирование запрещено", en, id);
}
case tpeditor_err_invalid_rad:
{
format(string, sizeof(string), " %s: ID: %d, Введен недопустимый радиус", en, id);
}
case tpeditor_err_invalid_p0:
{
format(string, sizeof(string), " %s: ID: %d, Возник конфликт зон! Внимание: ставьте телепорты подальше друг от друга и от сублокаций!", en, id);
}
case tpeditor_err_invalid_tpid:
{
//format(string, sizeof(string), " Редактор телепортов: ID: %d, Введите корректный идентификатор телепорта.", id);
format(string, sizeof(string), " Номер телепорта: [%d, %d].", 0, MAX_TELEPORTS - 1);
}
default:
{
format(string, sizeof(string), " %s: ID: %d, Ошибка: %d", en, id, res);
}
}
SendClientMessageRus(pid, COLOR_WRONG_ARG, string);
}
#undef editor_fn
#undef en
return 1;
}

