error 001: expected token ";", but found "if"
#1

Hello, I am trying to make a /vcreate and /v

/vcreate is to create voucher codes to be redeemed, and /v is to redeem the code created by an admin.

I tried making the commands, but after I compile it, I get an error.

Код:
C:\Roleplay\gamemodes\Roleplay.pwn(27117) : error 029: invalid expression, assumed zero
C:\Roleplay\gamemodes\Roleplay.pwn(27117) : warning 215: expression has no effect
C:\Roleplay\gamemodes\Roleplay.pwn(27117) : error 001: expected token: ";", but found "if"
Here are my codes:
Код:
CMD:vcreate(playerid, params[])
{
    new choice[32], code;
    new fstring[32], nstring[156];
    if(sscanf(params, "s[32]d", choice, code))
	{
		SendClientMessage(playerid, COLOR_GREY, "[USAGE] /vcreate [type] [vouchercode]");
		SendClientMessageEx(playerid, COLOR_WHITE, "________________Voucher Types________________");
		SendClientMessageEx(playerid, COLOR_PURPLE, "TYPES: vip, cash");
		return 1;
	}
	
	if(PlayerInfo[playerid][pAdmin] >= 3)
	{
		if(strcmp(choice, "vip", true) == 0)
		{
			new viprank, viptime;
			if(sscanf(params, "s[32]d", viprank, viptime)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vcreate vip [rank] [duration]");
			format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
			if(dini_Exists(fstring)) return SendClientMessage(playerid, COLOR_GREY, "[ERROR] That code already exist.");
			dini_Create(fstring);
			dini_Set(fstring, "viprank", PlayerInfo[playerid][pDonateRank]);
			dini_Set(fstring, "viptime", PlayerInfo[playerid][pVIPLeft]);
			format(nstring, sizeof(nstring), "Voucher %d created.", code);
		}
		else
		{
			SendClientMessageEx(playerid, COLOR_GREY, "Invalid voucher types.");
		}
		else if(strcmp(choice, "cash", true) == 0)
		{
			new money;
			if(sscanf(params, "s[32]", money)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vcreate cash [amount]");
			format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
			if(dini_Exists(fstring)) return SendClientMessage(playerid, COLOR_GREY, "[ERROR] That code already exist.");
			dini_Create(fstring);
			dini_IntSet(fstring, "Money", money);
			format(nstring, sizeof(nstring), "Voucher %d created.", code);
			SendClientMessage(playerid, COLOR_WHITE, nstring);
		}
		else
		{
			SendClientMessageEx(playerid, COLOR_GREY, "Invalid voucher types.");
		}
	}
	else return SendClientMessage(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
	return 1;
}

CMD:v(playerid, params[])
{
	new string[128], choice[32], code;
	new fstring[32], nstring[156];
	if(sscanf(params,"s[32]d", choice, code))
	{
		SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /v [type] [vouchercode]");
		SendClientMessageEx(playerid, COLOR_WHITE, "________________Redeem Choice________________");
		SendClientMessageEx(playerid, COLOR_PURPLE, "CHOICE: vip, cash");
		return 1;
	}
	
	if(strcmp(choice, "vip", true) == 0)
	{
		format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
		if(dini_Exists(fstring))
		{
			new viprank, viptime;
			PlayerInfo[playerid][pDonateRank] = dini_Int(fstring, "viprank");
			PlayerInfo[playerid][pVIPLeft] = dini_Int(fstring, "viptime");
			format(nstring, sizeof(nstring), "You are now a part of %s VIP.", viprank);
			SendClientMessage(playerid, COLOR_YELLOW, nstring);
			dini_Remove(fstring);
		}
		else
		{
			SendClientMessage(playerid, COLOR_RED, "This voucher is invalid or already redeemed.");
		}
	}
	else if(strcmp(params,"cash",true) == 0)
	{
		format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
		if(dini_Exists(fstring))
		{
			PlayerInfo[playerid][pCash] += dini_Int(fstring, "Money");
			format(nstring, sizeof(nstring), "You received %d for redeeming that code.");
			SendClientMessage(playerid, COLOR_YELLOW, nstring);
			dini_Remove(fstring);
		}
		else
		{
			SendClientMessage(playerid, COLOR_RED, "This voucher is invalid or already redeemed.");
		}
	}
	else return SendClientMessage(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
	return 1;
}
this is line 27117:
Код:
		else if(strcmp(choice, "cash", true) == 0)
Reply
#2

You cannot have an else, and then after that an else if. It is expecting a statement after the else { } because the syntax of the language is like that, is what I'd guess is the reason.

So either move the else-if above the else, or recreate the whole structure of this code.

EDIT: I think you meant to just close the previous if-statements. Add a "}" before the line with the error.
Reply
#3

Would this fix the code?

Код:
CMD:vcreate(playerid, params[])
{
    new choice[32], code;
    new fstring[32], nstring[156];
    if(sscanf(params, "s[32]d", choice, code))
	{
		SendClientMessageEx(playerid, COLOR_GREY, "[USAGE] /vcreate [type] [vouchercode]");
		SendClientMessageEx(playerid, COLOR_WHITE, "________________Voucher Types________________");
		SendClientMessageEx(playerid, COLOR_PURPLE, "TYPES: vip, cash");
		return 1;
	}
	
	if(strcmp(choice, "cash", true) == 0)
	{
		if(sscanf(params, "s[32]", money)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vcreate cash [amount]");
		format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
		if(dini_Exists(fstring)) return SendClientMessage(playerid, COLOR_GREY, "[ERROR] That code already exist.");
		dini_Create(fstring);
		dini_IntSet(fstring, "Money", money);
		format(nstring, sizeof(nstring), "Voucher %d created.", code);
		SendClientMessage(playerid, COLOR_WHITE, nstring);
	}
	
	else if(strcmp(choice, "vip", true) == 0)
	{
		if(sscanf(params, "s[32]d", viprank, viptime)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vcreate vip [rank] [duration]");
		format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
		if(dini_Exists(fstring)) return SendClientMessage(playerid, COLOR_GREY, "[ERROR] That code already exist.");
		dini_Create(fstring);
		dini_Set(fstring, "viprank", PlayerInfo[playerid][pVIPRank]);
		dini_Set(fstring, "viptime", PlayerInfo[playerid][pVIPLeft]);
		format(nstring, sizeof(nstring), "Voucher %d created.", code);
	}
	else
	{
		SendClientMessageEx(playerid, COLOR_GREY, "Invalid voucher types.");
		return 1;
	}
}

CMD:v(playerid, params[])
{
	new string[128], choice[32], code;
	new fstring[32], nstring[156];
	if(sscanf(params,"s[32]d", choice, code))) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /v [type] [vouchercode]");
	{
		SendClientMessageEx(playerid, COLOR_WHITE, "________________Redeem Choice________________");
		SendClientMessageEx(playerid, COLOR_PURPLE, "CHOICE: vip, cash");
		SendClientMessageEx(playerid, COLOR_WHITE, "________________Redeem Choice________________");
		return 1;
	}
	
	if(strcmp(choice, "vip", true) == 0)
	{
	    format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
		if(dini_Exists(fstring))
		{
			PlayerInfo[playerid][pVIPRank] = dini_Int(fstring, "viprank");
			PlayerInfo[playerid][pVIPLeft] = dini_Int(fstring, "viptime");
			format(nstring, sizeof(nstring), "You are now a part of %s VIP.", viprank);
			SendClientMessage(playerid, COLOR_YELLOW, nstring);
			dini_Remove(fstring);
		}
	}
	else if(strcmp(params,"cash",true) == 0)
	{
		format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
		if(dini_Exists(fstring))
		{
			PlayerInfo[playerid][pCash] += dini_Int(fstring, "Money");
			format(nstring, sizeof(nstring), "You received %d for redeeming that code.");
			SendClientMessage(playerid, COLOR_YELLOW, nstring);
			dini_Remove(fstring);
		}
		else
		{
			SendClientMessage(playerid, COLOR_RED, "This voucher is invalid or already redeemed.");
		}
	}
	return 1;
}
Reply
#4

Yes probably that error at least, why not compile and see how it goes?
Reply
#5

I think it's abit messy, because it doesn't send the "Voucher '%d' created", "This voucher is invalid or already redeemed" if the code is invalid, "You received %d for redeeming that code.". <<< Didn't get any of these messages when redeeming. Can you fix it for me maybe?
Reply
#6

bump.
Reply
#7

Try this:

pawn Код:
CMD:vcreate(playerid, params[])
{
    new choice[32], code;
    new fstring[32], nstring[156];
    if(sscanf(params, "s[32]d", choice, code))
    {
        SendClientMessage(playerid, COLOR_GREY, "[USAGE] /vcreate [type] [vouchercode]");
        SendClientMessage(playerid, COLOR_WHITE, "________________Voucher Types________________");
        SendClientMessage(playerid, COLOR_PURPLE, "TYPES: vip, cash");
        return 1;
    }
   
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {
        if(strcmp(choice, "vip", true) == 0)
        {
            new viprank, viptime;
            if(sscanf(params, "s[32]d", viprank, viptime)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vcreate vip [rank] [duration]");
            format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
            if(dini_Exists(fstring)) return SendClientMessage(playerid, COLOR_GREY, "[ERROR] That code already exist.");
            dini_Create(fstring);
            dini_Set(fstring, "viprank", PlayerInfo[playerid][pDonateRank]);
            dini_Set(fstring, "viptime", PlayerInfo[playerid][pVIPLeft]);
            format(nstring, sizeof(nstring), "Voucher %d created.", code);
            SendClientMessage(playerid, COLOR_WHITE, nstring);
        }
        else if(strcmp(choice, "cash", true) == 0)
        {
            new money;
            if(sscanf(params, "s[32]", money)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vcreate cash [amount]");
            format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
            if(dini_Exists(fstring)) return SendClientMessage(playerid, COLOR_GREY, "[ERROR] That code already exist.");
            dini_Create(fstring);
            dini_IntSet(fstring, "Money", money);
            format(nstring, sizeof(nstring), "Voucher %d created.", code);
            SendClientMessage(playerid, COLOR_WHITE, nstring);
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "Invalid voucher types.");
        }
    }
    else return SendClientMessage(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
    return 1;
}

CMD:v(playerid, params[])
{
    new string[128], choice[32], code;
    new fstring[32], nstring[156];
    if(sscanf(params,"s[32]d", choice, code))
    {
        SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /v [type] [vouchercode]");
        SendClientMessageEx(playerid, COLOR_WHITE, "________________Redeem Choice________________");
        SendClientMessageEx(playerid, COLOR_PURPLE, "CHOICE: vip, cash");
        return 1;
    }
   
    if(strcmp(choice, "vip", true) == 0)
    {
        format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
        if(dini_Exists(fstring))
        {
            new viprank, viptime;
            PlayerInfo[playerid][pDonateRank] = dini_Int(fstring, "viprank");
            PlayerInfo[playerid][pVIPLeft] = dini_Int(fstring, "viptime");
            format(nstring, sizeof(nstring), "You are now a part of %s VIP.", viprank);
            SendClientMessage(playerid, COLOR_YELLOW, nstring);
            dini_Remove(fstring);
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "This voucher is invalid or already redeemed.");
        }
    }
    else if(strcmp(choice,"cash",true) == 0)
    {
        format(fstring, sizeof(fstring), SERVER_VOUCHER_FILE, code);
        if(dini_Exists(fstring))
        {
            PlayerInfo[playerid][pCash] += dini_Int(fstring, "Money");
            format(nstring, sizeof(nstring), "You received %d for redeeming that code.");
            SendClientMessage(playerid, COLOR_YELLOW, nstring);
            dini_Remove(fstring);
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "This voucher is invalid or already redeemed.");
        }
    }
    else return SendClientMessage(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
    return 1;
}
If that does not work, you should consider doing that function from the scratch, it is indeed messy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)