Help on converting strcmp to zcmd!
#1

Can someone help me convert this long, strcmp commands to ZCMD?
P/S: I'm new in zcmd
Quote:
Код:
    if(strcmp(cmd, "/arrest", true) == 0 || strcmp(cmd, "/ar", true) == 0)
	{
	new string[250];
    if(IsSpawned[playerid] == 0)
	{
	SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
    return 1;
    }
    if(gTeam[playerid] != COP && gTeam[playerid] != SWAT && gTeam[playerid] != ARMY && gTeam[playerid] != FBI)
	{
    SendClientMessage(playerid,COLOR_ERROR,"You are not a Law Enforcement officer ");
    return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
	{
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ar (id)");
    return 1;
    }
    giveplayerid = strval(tmp);
    if(!IsNumeric(tmp))
	{
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ar (id)");
    return 1;
    }
    if(!IsPlayerConnected(giveplayerid))
	{
    format(string, sizeof(string), "ID (%d) is not an active player", giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }
    new oname[24];
    new pname[24];
    GetPlayerName(playerid,oname, 24);
	GetPlayerName(giveplayerid, pname, 24);
	if(GetPlayerWantedLevel(giveplayerid) <= 3)
	{
	format(string, sizeof(string), "%s(%d) Does not have a warrant. You cannot arrest a player without a warrant",pname,giveplayerid);
	SendClientMessage(playerid,COLOR_ERROR,string);
    return 1;
    }
    if(IsPlayerInAnyVehicle(playerid))
	{
    SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest a suspect if you are in a car");
    return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10)
	{
    format(string, sizeof(string), "%s(%d) Is too far away. You cannot arrest that player",pname,giveplayerid);
    SendClientMessage(playerid,COLOR_ERROR,string);
    return 1;
    }
    if(IsSpawned[giveplayerid] == 0)
	{
	format(string, sizeof(string), "%s(%d) Is dead. You cannot arrest a dead body",pname,giveplayerid);
    SendClientMessage(playerid,COLOR_ERROR,string);
    return 1;
    }
    SetPlayerVirtualWorld(giveplayerid,0);
    if(GetPlayerWantedLevel(playerid) >=1)
	{
    SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command if you are wanted by the police");
    return 1;
    }
    if(giveplayerid == playerid)
	{
    SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest yourself");
    return 1;
    }
    new spawn = random(sizeof(PrisonSpawn)), string2[250], Float:health, copname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME];
    GetPlayerName(playerid, copname, sizeof(copname));
    GetPlayerName(strval(tmp), arrested, sizeof(arrested));
    GetPlayerHealth(strval(tmp), health);
	SendClientMessage(strval(tmp), GREY, "|_| San Andreas Police Dept. |_|");
	format(string, sizeof(string), "Officer %s has arrested you.", copname);
	SendClientMessage(strval(tmp), WHITE, string);
	ResetPlayerWeapons(strval(tmp));
	SetPlayerPos(strval(tmp), PrisonSpawn[spawn][0], PrisonSpawn[spawn][1], PrisonSpawn[spawn][2]);
	SetPlayerFacingAngle(strval(tmp), PrisonSpawn[spawn][3]);
	SetCameraBehindPlayer(strval(tmp));
	if(GetPlayerWantedLevel(strval(tmp)) >= 4 && GetPlayerWantedLevel(strval(tmp)) <= 5)
	{
	PrisonTime[strval(tmp)] = 60;
	GivePlayerMoney(playerid,25000);
	GivePlayerScore(playerid,1);
	}
	else if(GetPlayerWantedLevel(strval(tmp)) >= 6 && GetPlayerWantedLevel(strval(tmp)) <= 8)
	{
	PrisonTime[strval(tmp)] = 120;
	GivePlayerMoney(playerid,35000);
	GivePlayerScore(playerid,1);
	}
	else if(GetPlayerWantedLevel(strval(tmp)) >= 9 && GetPlayerWantedLevel(playerid) <= 11)
	{
	PrisonTime[strval(tmp)] = 180;
	GivePlayerMoney(playerid,45000);
	GivePlayerScore(playerid,2);
	}
	else if(GetPlayerWantedLevel(strval(tmp)) >= 12 && GetPlayerWantedLevel(strval(tmp)) <= 14)
	{
	PrisonTime[strval(tmp)] = 240;
	GivePlayerMoney(playerid,55000);
	GivePlayerScore(playerid,2);
	}
	else if(GetPlayerWantedLevel(strval(tmp)) >= 15)
	{
	PrisonTime[strval(tmp)] = 300;
	GivePlayerMoney(playerid,65000);
	GivePlayerScore(playerid,3);
	}
	SetPlayerWantedLevel(strval(tmp), 0);
	SetPlayerInterior(strval(tmp),3);
	SetPlayerHealth(strval(tmp),99999);
	TogglePlayerControllable(strval(tmp), true);
	SetPlayerJailed(strval(tmp), true);
	format(string2, sizeof(string2), "Officer %s (%d) arrested %s (%d).", copname, playerid, arrested, strval(tmp));
	Announce(string2);
	if(health <= 90)
	{
    SendClientMessage(strval(tmp), GREY, "|_| San Andreas Police Dept. |_|");
    SendClientMessage(strval(tmp), WHITE, "SAPD has given you some food.");
    SetPlayerHealth(strval(tmp), health+10);
    ApplyAnimation(strval(tmp), "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0);
	}
    return 1;
    }
And this /tk (/ticket) command

Quote:
Код:
    if(strcmp(cmd, "/ticket", true) == 0 || strcmp(cmd, "/tk", true) == 0)
    {
    new string[128];
    if(IsSpawned[playerid] == 0)
	{
	SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
    return 1;
    }
    if(gTeam[playerid] != COP && gTeam[playerid] != SWAT && gTeam[playerid] != ARMY && gTeam[playerid] != FBI)
	{
    SendClientMessage(playerid,COLOR_ERROR,"You are not Law Enforcement");
    return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) {
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /tk (id)");
    return 1;
    }
    if(!IsNumeric(tmp))
	{
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /tk (id) ID Must be a number");
    return 1;
    }
    giveplayerid = strval(tmp);
    if(!IsPlayerConnected(giveplayerid))
	{
    format(string, sizeof(string), "ID (%d) is not an active player", giveplayerid);
    SendClientMessage(playerid, COLOR_ERROR, string);
    return 1;
    }
    new oname[24];
    new pname[24];
    GetPlayerName(playerid,oname, 24);
	GetPlayerName(giveplayerid, pname, 24);
	if(GetPlayerWantedLevel(giveplayerid) == 0)
	{
	format(string, sizeof(string), "%s(%d) is innocent. You cannot issue a ticket!",pname,giveplayerid);
	SendClientMessage(playerid,COLOR_ERROR,string);
    return 1;
    }

    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10)
	{
    format(string, sizeof(string), "%s(%d) Is too far away. You cannot issue a ticket",pname,giveplayerid);
    SendClientMessage(playerid,COLOR_ERROR,string);
    return 1;
    }
    if(GetPlayerWantedLevel(giveplayerid) == 1)
	{
    format(string, sizeof(string), "Officer %s(%d) has give you a ticket. Type /pay for pay! ",oname,playerid);
    SendClientMessage(giveplayerid,LIGHT_BLUE, string);
    format(string, sizeof(string), "~b~Officer ~r~%s(%d)~n~~w~has give you a ticket.~n~~w~Type ~b~/pay ~w~for pay!",oname,playerid);
    GameTextForPlayer(giveplayerid, string,10000, 5);
    ticketmen[giveplayerid] = playerid;
	tkat[giveplayerid] = 1;
	SendClientMessage(playerid,LIGHT_BLUE,"You have give an ticket");
    return 1;
    }
    if(GetPlayerWantedLevel(giveplayerid) == 2)
	{
    format(string, sizeof(string), "Officer %s(%d) has give you a ticket. Type /pay for pay! ",oname,playerid);
    SendClientMessage(giveplayerid,LIGHT_BLUE, string);
    format(string, sizeof(string), "~b~Officer ~r~%s(%d)~n~~w~has give you a ticket.~n~~w~Type ~b~/pay ~w~for pay!",oname,playerid);
    GameTextForPlayer(giveplayerid, string,10000, 5);
    ticketmen[giveplayerid] = playerid;
	tkat[giveplayerid] = 2;
	SendClientMessage(playerid,LIGHT_BLUE,"You have give an ticket");
    return 1;
    }
    if(GetPlayerWantedLevel(giveplayerid) == 3)
	{
    format(string, sizeof(string), "Officer %s(%d) has give you a ticket. Type /pay for pay! ",oname,playerid);
    SendClientMessage(giveplayerid,LIGHT_BLUE, string);
    format(string, sizeof(string), "~b~Officer ~r~%s(%d)~n~~w~has give you a ticket.~n~~w~Type ~b~/pay ~w~for pay!",oname,playerid);
    GameTextForPlayer(giveplayerid, string,10000, 5);
    ticketmen[giveplayerid] = playerid;
	tkat[giveplayerid] = 3;
	SendClientMessage(playerid,LIGHT_BLUE,"You have give an ticket");
    }
    if(GetPlayerWantedLevel(giveplayerid) >= 4)
	{
    format(string, sizeof(string), "~r~%s(%d) ~w~Has a warrant. ~n~~w~You cannot issue a fine.~n~~w~Take the suspect into custody",pname,giveplayerid);
    GameTextForPlayer(playerid, string,10000, 5);
    }
    return 1;
    }
Reply
#2

Bump
Reply
#3

This should work, but you will need to install sscanf
pawn Код:
CMD:ar(playerid, params[]) return cmd_arrest(playerid, params);

CMD:arrest(playerid, params[])
{
    new string[128];
    if(IsSpawned[playerid] == 0)
    {
        SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
        return 1;
    }
    if(gTeam[playerid] != COP && gTeam[playerid] != SWAT && gTeam[playerid] != ARMY && gTeam[playerid] != FBI)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You are not a Law Enforcement officer ");
        return 1;
    }
    new giveplayerid;
    if(sscanf(params, "u", giveplayerid))
    {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ar (id)");
        return 1;
    }
    if(id == INVALID_PLAYER_ID))
    {
        SendClientMessage(playerid, COLOR_ERROR, "That is not an active player.");
        return 1;
    }
    new oname[24];
    new pname[24];
    GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);
    if(GetPlayerWantedLevel(giveplayerid) <= 3)
    {
        format(string, sizeof(string), "%s(%d) Does not have a warrant. You cannot arrest a player without a warrant",pname,giveplayerid);
        SendClientMessage(playerid,COLOR_ERROR,string);
        return 1;
    }
    if(IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest a suspect if you are in a car");
        return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10)
    {
        format(string, sizeof(string), "%s(%d) Is too far away. You cannot arrest that player",pname,giveplayerid);
        SendClientMessage(playerid,COLOR_ERROR,string);
        return 1;
    }
    if(IsSpawned[giveplayerid] == 0)
    {
        format(string, sizeof(string), "%s(%d) Is dead. You cannot arrest a dead body",pname,giveplayerid);
        SendClientMessage(playerid,COLOR_ERROR,string);
    return 1;
    }
    SetPlayerVirtualWorld(giveplayerid,0);
    if(GetPlayerWantedLevel(playerid) >=1)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command if you are wanted by the police");
        return 1;
    }
    if(giveplayerid == playerid)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest yourself");
        return 1;
    }
    new spawn = random(sizeof(PrisonSpawn)), string2[250], Float:health, copname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME];
    GetPlayerName(playerid, copname, sizeof(copname));
    GetPlayerName(giveplayerid, arrested, sizeof(arrested));
    GetPlayerHealth(giveplayerid, health);
    SendClientMessage(giveplayerid, GREY, "|_| San Andreas Police Dept. |_|");
    format(string, sizeof(string), "Officer %s has arrested you.", copname);
    SendClientMessage(giveplayerid, WHITE, string);
    ResetPlayerWeapons(giveplayerid);
    SetPlayerPos(giveplayerid, PrisonSpawn[spawn][0], PrisonSpawn[spawn][1], PrisonSpawn[spawn][2]);
    SetPlayerFacingAngle(giveplayerid, PrisonSpawn[spawn][3]);
    SetCameraBehindPlayer(giveplayerid);
    if(GetPlayerWantedLevel(giveplayerid) >= 4 && GetPlayerWantedLevel(giveplayerid) <= 5)
    {
        PrisonTime[giveplayerid] = 60;
        GivePlayerMoney(playerid,25000);
        GivePlayerScore(playerid,1);
    }
    else if(GetPlayerWantedLevel(strval(tmp)) >= 6 && GetPlayerWantedLevel(strval(tmp)) <= 8)
    {
        PrisonTime[strval(tmp)] = 120;
        GivePlayerMoney(playerid,35000);
        GivePlayerScore(playerid,1);
    }
    else if(GetPlayerWantedLevel(giveplayerid) >= 9 && GetPlayerWantedLevel(playerid) <= 11)
    {
        PrisonTime[giveplayerid] = 180;
        GivePlayerMoney(playerid,45000);
        GivePlayerScore(playerid,2);
    }
    else if(GetPlayerWantedLevel(giveplayerid) >= 12 && GetPlayerWantedLevel(giveplayerid) <= 14)
    {
        PrisonTime[giveplayerid] = 240;
        GivePlayerMoney(playerid,55000);
        GivePlayerScore(playerid,2);
    }
    else if(GetPlayerWantedLevel(giveplayerid) >= 15)
    {
        PrisonTime[giveplayerid] = 300;
        GivePlayerMoney(playerid,65000);
        GivePlayerScore(playerid,3);
    }
    SetPlayerWantedLevel(giveplayerid, 0);
    SetPlayerInterior(giveplayerid,3);
    SetPlayerHealth(giveplayerid,99999);
    TogglePlayerControllable(giveplayerid, true);
    SetPlayerJailed(giveplayerid, true);
    format(string2, sizeof(string2), "Officer %s (%d) arrested %s (%d).", copname, playerid, arrested, giveplayerid);
    Announce(string2);
    if(health <= 90)
    {
        SendClientMessage(giveplayerid, GREY, "|_| San Andreas Police Dept. |_|");
        SendClientMessage(giveplayerid, WHITE, "SAPD has given you some food.");
        SetPlayerHealth(giveplayerid, health+10);
        ApplyAnimation(giveplayerid, "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0);
    }
    return 1;
}
pawn Код:
CMD:tk(playerid, params[]) return cmd_ticket(playerid, params);

CMD:ticket(playerid, params[])
{
    new string[128];
    if(IsSpawned[playerid] == 0)
    {
        SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
        return 1;
    }
    if(gTeam[playerid] != COP && gTeam[playerid] != SWAT && gTeam[playerid] != ARMY && gTeam[playerid] != FBI)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You are not Law Enforcement");
        return 1;
    }
    new giveplayerid;
    if(sscanf(params, "u", giveplayerid))
    {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /tk (id)");
        return 1;
    }
    if(giveplayerid == INVALID_PLAYER_ID)
    {
        format(string, sizeof(string), "ID (%d) is not an active player", giveplayerid);
        SendClientMessage(playerid, COLOR_ERROR, string);
        return 1;
    }
    new oname[24];
    new pname[24];
    GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);
    if(GetPlayerWantedLevel(giveplayerid) == 0)
    {
        format(string, sizeof(string), "%s(%d) is innocent. You cannot issue a ticket!",pname,giveplayerid);
        SendClientMessage(playerid,COLOR_ERROR,string);
        return 1;
    }

    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10)
    {
        format(string, sizeof(string), "%s(%d) Is too far away. You cannot issue a ticket",pname,giveplayerid);
        SendClientMessage(playerid,COLOR_ERROR,string);
        return 1;
    }
    if(GetPlayerWantedLevel(giveplayerid) == 1)
    {
        format(string, sizeof(string), "Officer %s(%d) has give you a ticket. Type /pay for pay! ",oname,playerid);
        SendClientMessage(giveplayerid,LIGHT_BLUE, string);
        format(string, sizeof(string), "~b~Officer ~r~%s(%d)~n~~w~has give you a ticket.~n~~w~Type ~b~/pay ~w~for pay!",oname,playerid);
        GameTextForPlayer(giveplayerid, string,10000, 5);
        ticketmen[giveplayerid] = playerid;
        tkat[giveplayerid] = 1;
        SendClientMessage(playerid,LIGHT_BLUE,"You have give an ticket");
        return 1;
    }
    if(GetPlayerWantedLevel(giveplayerid) == 2)
    {
        format(string, sizeof(string), "Officer %s(%d) has give you a ticket. Type /pay for pay! ",oname,playerid);
        SendClientMessage(giveplayerid,LIGHT_BLUE, string);
        format(string, sizeof(string), "~b~Officer ~r~%s(%d)~n~~w~has give you a ticket.~n~~w~Type ~b~/pay ~w~for pay!",oname,playerid);
        GameTextForPlayer(giveplayerid, string,10000, 5);
        ticketmen[giveplayerid] = playerid;
        tkat[giveplayerid] = 2;
        SendClientMessage(playerid,LIGHT_BLUE,"You have give an ticket");
        return 1;
    }
    if(GetPlayerWantedLevel(giveplayerid) == 3)
    {
        format(string, sizeof(string), "Officer %s(%d) has give you a ticket. Type /pay for pay! ",oname,playerid);
        SendClientMessage(giveplayerid,LIGHT_BLUE, string);
        format(string, sizeof(string), "~b~Officer ~r~%s(%d)~n~~w~has give you a ticket.~n~~w~Type ~b~/pay ~w~for pay!",oname,playerid);
        GameTextForPlayer(giveplayerid, string,10000, 5);
        ticketmen[giveplayerid] = playerid;
        tkat[giveplayerid] = 3;
        SendClientMessage(playerid,LIGHT_BLUE,"You have give an ticket");
    }
    if(GetPlayerWantedLevel(giveplayerid) >= 4)
    {
        format(string, sizeof(string), "~r~%s(%d) ~w~Has a warrant. ~n~~w~You cannot issue a fine.~n~~w~Take the suspect into custody",pname,giveplayerid);
        GameTextForPlayer(playerid, string,10000, 5);
    }
    return 1;
}
Reply
#4

I still like using strcmp. But I'm aware that the DCMD, ZCMD and the rest are faster. But still, I rather stay with strcmp. The original.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)