ZCMD if string is empty help!
#1

Hi, I started making an admin script using ZCMD. It works fine but I wanted it so that if you typed in "/akill 0 test" it will print out you have been killed for a reason. But if the string "[reason]" was left blank it would print out " [No reason specified]". However I keep getting this error "bAdmin2.pwn(406) : error 033: array must be indexed (variable "str2")" And its probably something quite simple :/

Код:
CMD:akill(playerid, params[])
{
    if(Level[playerid] < 1) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: you are not level 1!");

    new str[256], str2[256], id, AdminName[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
    if(sscanf(params, "uS", id, str2))
    {
        SendClientMessage(playerid, 0xFF0000FF, "Usage: /akill [id] [reason]");
        return 1;
    }
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
    if(IsPlayerConnected(id))
    {

		GetPlayerName(playerid, AdminName, sizeof(AdminName));
		GetPlayerName(id, PlayerName, sizeof(PlayerName));
		SetPlayerHealth(id, 0);
		PlayCrimeReportForPlayer(id, id, 4);
		if(str2 == NULL){ // LINE 406
		format(str, sizeof(str), "Administrator %s has killed %s for: [No reason specified]", AdminName, PlayerName);
  		SendClientMessage(id, orange, str);
  		}
		else
		{
		format(str, sizeof(str), "Administrator %s has killed %s for: %s", AdminName, PlayerName, str2);
  		SendClientMessage(id, orange, str);
  		}
    }
    return 1;
}
Reply
#2

You cannot get a string that has multiple cells and compare it to something that would use one cell. Do this

pawn Код:
if(!str2[0])
or

pawn Код:
if(isnull(str2))
Reply
#3

Thanks works great!
Reply
#4

Why Don't You Simply Use STRCMP ?
Reply
#5

Quote:
Originally Posted by 0_o
Посмотреть сообщение
Why Don't You Simply Use STRCMP ?
He was finding if the string is null, not comparing it to a string.
Reply
#6

Quote:
Originally Posted by 0_o
Посмотреть сообщение
Why Don't You Simply Use STRCMP ?
Why Don't You Stop Typing Like This? Tarded IMO.

On topic: using isnull is easier than comparing if the string is empty with strcmp...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)