25.03.2013, 17:56
Yeah I know I could do like
CMD:button(playerid,params[]) but I know it wouldn work on here if (!cmdtext[arg1])
So how it's possible to do this in zcmd?
CMD:button(playerid,params[]) but I know it wouldn work on here if (!cmdtext[arg1])
So how it's possible to do this in zcmd?
pawn Код:
if(!strcmp(cmdtext, "/button", .length = 7))
{
if (!IsPlayerAdmin(playerid))
return true;
new arg1 = argpos(cmdtext);
if (!cmdtext[arg1])
{
SendClientMessage(playerid, 0xFF0000FF, "Button Editor's commands:");
SendClientMessage(playerid, 0xFFFFFFFF, "\"/button create\" - Create a button at your position, then type \"/button select\" to move this button.");
SendClientMessage(playerid, 0xFFFFFFFF, "\"/button select <opt:buttonid>\" - If you don't use the optional parameter, it will select the closest button.");
SendClientMessage(playerid, 0xFFFFFFFF, "\"/button save <opt:comment>\" - Save the positions of the selected button, optionally with a short comment.");
SendClientMessage(playerid, 0xFFFFFFFF, "\"/button deselect\" - Deselect the selected button, this stops the editing mode.");
SendClientMessage(playerid, 0xFF0000FF, "Button Editor's keys:");
SendClientMessage(playerid, 0xFFFFFFFF, "Use Directional key to move the selected button forward, backward, to the left and to the right.");
SendClientMessage(playerid, 0xFFFFFFFF, "Use Look Behind + Left or Right to rotate the selected button.");
SendClientMessage(playerid, 0xFFFFFFFF, "Use Secondary Fire to change the movement speed.");
SendClientMessage(playerid, 0xFFFFFFFF, "Use Walk to toggle Deselect/Select closest button.");
return true;
}
else if (!strcmp(cmdtext[arg1], "create", .length = 6))
{
new Float:PlayerPos[4], buttonid;
GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
GetPlayerFacingAngle(playerid, PlayerPos[3]);
buttonid = FS_CreateButton(PlayerPos[0],PlayerPos[1],PlayerPos[2] + 0.63,PlayerPos[3]);
format(String, sizeof(String), "Buttonid %d created! Select it with \"/button select\"", buttonid);
SendClientMessage(playerid, 0x00FF00FF, String);
return true;
}
else if (!strcmp(cmdtext[arg1], "select", .length = 6))
{
new arg2 = argpos(cmdtext, arg1),
buttonid;
if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
KillTimer(PlayerInfo[playerid][TimerID]);
if (!cmdtext[arg2])
{
new Float:PlayerPos[3];
GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
buttonid = GetClosestButton(PlayerPos);
if (buttonid == INVALID_BUTTON_ID)
SendClientMessage(playerid, 0xFF0000FF, "Can't find a button! You may need to create one!");
else
{
PlayerInfo[playerid][SelectedButton] = buttonid;
PlayerInfo[playerid][TimerID] = SetTimerEx("ButtonEditor_Timer", 50, true, "ii", playerid, PlayerInfo[playerid][SelectedButton]);
TogglePlayerControllable(playerid, false);
format(String, sizeof(String), "Buttonid %d selected! Once you placed it where you want, save it with \"/button save <comment>\"", buttonid);
SendClientMessage(playerid, 0x00FF00FF, String);
}
}
else
{
buttonid = strval(cmdtext[arg2]);
if (FS_IsValidButton(buttonid))
{
PlayerInfo[playerid][SelectedButton] = buttonid;
PlayerInfo[playerid][TimerID] = SetTimerEx("ButtonEditor_Timer", 50, true, "ii", playerid, PlayerInfo[playerid][SelectedButton]);
TogglePlayerControllable(playerid, false);
format(String, sizeof(String), "Buttonid %d selected! Once you placed it where you want, save it with \"/button save\"", buttonid);
SendClientMessage(playerid, 0x00FF00FF, String);
}
else
SendClientMessage(playerid, 0xFF0000FF, "This buttonid is invalid!");
}
return true;
}
else if (!strcmp(cmdtext[arg1], "save", .length = 4))
{
new arg2 = argpos(cmdtext, arg1),
buttonid = PlayerInfo[playerid][SelectedButton];
if (buttonid != INVALID_BUTTON_ID)
{
new File:savedbuttons_file = fopen("savedbuttons.txt", io_append);
if (!cmdtext[arg2])
{
format
(
String,
sizeof(String),
"CreateButton(%.2f, %.2f, %.2f, %.1f);\r\n",
ButtonInfo[buttonid][Pos][0],
ButtonInfo[buttonid][Pos][1],
ButtonInfo[buttonid][Pos][2],
float(floatround(ButtonInfo[buttonid][Pos][3])%360)
);
}
else
{
format
(
String,
sizeof(String),
"CreateButton(%.2f, %.2f, %.2f, %.1f); // %s\r\n",
ButtonInfo[buttonid][Pos][0],
ButtonInfo[buttonid][Pos][1],
ButtonInfo[buttonid][Pos][2],
float(floatround(ButtonInfo[buttonid][Pos][3])%360),
cmdtext[arg2]
);
}
fwrite(savedbuttons_file,String);
fclose(savedbuttons_file);
SendClientMessage(playerid, 0x00FF00FF, "Button's informations saved in \"/scriptfiles/savedbuttons.txt\"!");
}
else
SendClientMessage(playerid, 0xFF0000FF, "Umm..Select a button first?");
return true;
}
else if (!strcmp(cmdtext[arg1], "deselect", .length = 6))
{
if (PlayerInfo[playerid][SelectedButton] != INVALID_BUTTON_ID)
{
format(String, sizeof(String), "Buttonid %d deselected!", PlayerInfo[playerid][SelectedButton]);
SendClientMessage(playerid, 0x00FF00FF, String);
PlayerInfo[playerid][SelectedButton] = INVALID_BUTTON_ID;
TogglePlayerControllable(playerid, true);
KillTimer(PlayerInfo[playerid][TimerID]);
}
else
SendClientMessage(playerid, 0xFF0000FF, "Umm..Select a button first?");
return true;
}
return false;
}