Help converting large strcmp cmds to ZCMD
#1

Hello i have saw tutorials on how to convert but they dont solve the problem i need help on converting big commands such as this /pay command below.

Код:
if(strcmp(cmd, "/pay", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /pay [playerid/PartOfName] [amount]");
				return 1;
			}
			//giveplayerid = strval(tmp);
	        giveplayerid = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /pay [playerid/PartOfName] [amount]");
				return 1;
			}
			moneys = strval(tmp);
			if(moneys > 1000 && PlayerInfo[playerid][pLevel] < 3)
			{
				SendClientMessage(playerid, COLOR_GRAD1, "You must be level 3 to pay over 1000");
				return 1;
			}
			if(moneys < 1 || moneys > 99999)
			{
			    SendClientMessage(playerid, COLOR_GRAD1, "Dont go below 1, or above 99999 at once.");
			    return 1;
			}
			if (IsPlayerConnected(giveplayerid))
			{
			    if(giveplayerid != INVALID_PLAYER_ID)
			    {
			        if(PlayerInfo[giveplayerid][pLocal] == 106)
					{
						SendClientMessage(playerid, COLOR_GRAD1, "Command not allowed in this location");
						return 1;
					}
					if (ProxDetectorS(5.0, playerid, giveplayerid))
					{
						GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						playermoney = GetPlayerMoney(playerid);
						if (moneys > 0 && playermoney >= moneys)
						{
						    ConsumingMoney[giveplayerid] = 1;
							GivePlayerMoney(playerid, (0 - moneys));
							GivePlayerMoney(giveplayerid, moneys);
							format(string, sizeof(string), "   You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
							PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
							SendClientMessage(playerid, COLOR_GRAD1, string);
							format(string, sizeof(string), "   You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
							SendClientMessage(giveplayerid, COLOR_GRAD1, string);
							format(string, sizeof(string), "%s has paid $%d to %s", sendername, moneys, giveplayer);
							PayLog(string);
							if(moneys >= 1000000)
							{
								ABroadCast(COLOR_YELLOW,string,1);
							}
							PlayerPlaySound(giveplayerid, 1052, 0.0, 0.0, 0.0);
							format(string, sizeof(string), "* %s takes out some cash, and hands it to %s.", sendername ,giveplayer);
							ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
						}
						else
						{
							SendClientMessage(playerid, COLOR_GRAD1, "   Invalid transaction amount.");
						}
					}
					else
					{
						SendClientMessage(playerid, COLOR_GRAD1, "   Your too far away.");
					}
				}//invalid id
			}
			else
			{
				format(string, sizeof(string), "   %d is not an active player.", giveplayerid);
				SendClientMessage(playerid, COLOR_GRAD1, string);
			}
		}
		return 1;
	}
Reply
#2

pawn Код:
CMD:pay(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new giveplayerid, moneys;
        if(sscanf(params, "ui", giveplayerid, moneys)) return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /pay [playerid/partofname] [money]");
        if(moneys > 1000 && PlayerInfo[playerid][pLevel] < 3) return SendClientMessage(playerid, COLOR_GRAD1, "You must be level 3 to pay over 1000");
        if(moneys < 1 || moneys > 99999) return SendClientMessage(playerid, COLOR_GRAD1, "Dont go below 1, or above 99999 at once.");
        if(giveplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD1, "That player is not an active one.");
        if(PlayerInfo[giveplayerid][pLocal] == 106) return SendClientMessage(playerid, COLOR_GRAD1, "Command not allowed in this location");
        if (ProxDetectorS(5.0, playerid, giveplayerid))
        {
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            playermoney = GetPlayerMoney(playerid);
            if (moneys > 0 && playermoney >= moneys)
            {
                ConsumingMoney[giveplayerid] = 1;
                GivePlayerMoney(playerid, (0 - moneys));
                GivePlayerMoney(giveplayerid, moneys);
                format(string, sizeof(string), "   You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
                PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                SendClientMessage(playerid, COLOR_GRAD1, string);
                format(string, sizeof(string), "   You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
                SendClientMessage(giveplayerid, COLOR_GRAD1, string);
                format(string, sizeof(string), "%s has paid $%d to %s", sendername, moneys, giveplayer);
                PayLog(string);
                if(moneys >= 1000000)
                {
                    ABroadCast(COLOR_YELLOW,string,1);
                }
                PlayerPlaySound(giveplayerid, 1052, 0.0, 0.0, 0.0);
                format(string, sizeof(string), "* %s takes out some cash, and hands it to %s.", sendername ,giveplayer);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                return 1;
            }
            else return SendClientMessage(playerid, COLOR_GRAD1, "   Invalid transaction amount.");
        }
        else return SendClientMessage(playerid, COLOR_GRAD1, "   Your too far away.");
    }
    return 1;
}
Reply
#3

@ fordawinzz
pawn Код:
if(giveplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD1, "That player is not an active one.");
If the player isn't invalid it will return the message that he is.
@malcomjones
pawn Код:
CMD:pay( playerid, params[ ] )
{
    new giveplayerid, moneys, giveplayerid[ MAX_PLAYER_NAME ], sendername[ MAX_PLAYER_NAME ], string[ 128 ];
    GetPlayerName( giveplayerid, giveplayer, sizeof( giveplayer ) );
    GetPlayerName( playerid, sendername, sizeof( sendername ) );
    if( isnull( params ) ) return SendClientMessage( playerid, COLOR_GRAD1, "USAGE: /pay [playerid/PartOfName] [amount]" );
    if( moneys < 1000 && PlayerInfo[ playerid ][ pLevel ] < 3 ) return SendClientMessage( playerid, COLOR_GRAD1, "You must be level 3 to pay over 1000" );
    if( moneys < 1 || moneys > 99999 ) return SendClientMessage( playerid, COLOR_GRAD1, "Dont go below 1, or above 99999 at once." );
    if( giveplayerid == INVALID_PLAYER_ID ) return format( string, sizeof( string ), "%d is not an active player.", giveplayerid ), SendClientMessage( playerid, COLOR_GRAD1, string );
    if( PlayerInfo[ giveplayerid ][ pLocal ] == 106 ) return SendClientMessage( playerid, COLOR_GRAD1, "Command not allowed in this location" );
    if( ProxDetectorS( 5.0, playerid, giveplayerid ) )
    {
        playermoney = GetPlayerMoney( playerid );
        if( moneys < 0 && playermoney < moneys ) return SendClientMessage(playerid, COLOR_GRAD1, "Invalid transaction amount.");
        ConsumingMoney[giveplayerid] = 1;
        GivePlayerMoney(playerid, (0 - moneys));
        GivePlayerMoney(giveplayerid, moneys);
        format(string, sizeof(string), "   You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
        PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
        SendClientMessage(playerid, COLOR_GRAD1, string);
        format(string, sizeof(string), "   You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
        SendClientMessage(giveplayerid, COLOR_GRAD1, string);
        format(string, sizeof(string), "%s has paid $%d to %s", sendername, moneys, giveplayer);
        PayLog(string);
        if(moneys >= 1000000) {
            ABroadCast(COLOR_YELLOW,string,1);
        }
        PlayerPlaySound(giveplayerid, 1052, 0.0, 0.0, 0.0);
        format(string, sizeof(string), "* %s takes out some cash, and hands it to %s.", sendername ,giveplayer);
        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
    }
    else SendClientMessage(playerid, COLOR_GRAD1, "Your too far away.");
    return 1;
}
Reply
#4

So basically what did you change? + rep both of you for helping
Reply
#5

Quote:
Originally Posted by malcomjones
Посмотреть сообщение
So basically what did you change? + rep both of you for helping
This is what he changed
pawn Код:
if(giveplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD1, "That player is not an active one.");
Now your cmd will work on zcmd n sscanf2!
Reply
#6

Ok thanks +rep
Reply
#7

Don't forget to download and place sscanf in your plugins folder, and add it in server.cfg
You can download it in the Plugins board.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)