Password array bug
#1

Well, I was looking on the Adminscript tutorial, but I have problem with command.
pawn Код:
dcmd_password(playerid, params[])
{
  if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
    return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register and login.");
  else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 0)
        return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must be logged-in to do that! Use /login [password] to login.");
  else
  {
    new tmp[128],
      tmp2[128],
      index;
    tmp = strtok(params, index);
    if(!strlen(tmp))
    return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
    tmp2 = strtok(params, index);
    if(!strlen(tmp2))
    return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
  new oldpassword = num_hash(tmp), newpassword = num_hash(tmp2);
    if(gPlayerInfo[playerid][PLAYER_PASS] == oldpassword)
    {
      if(oldpassword == newpassword)
        return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Your old password can not be the same as your new password.");
        else if(strlen(tmp2) < gSettings[PASS_MIN] || strlen(tmp2) > gSettings[PASS_MAX])
        {
            new string[100]; format(string, sizeof(string), "ERROR: Your new password must be between %d and %d characters long!", gSettings[PASS_MIN], gSettings[PASS_MAX]);
            return SendClientMessage(playerid, COLOUR_ORANGE, string);
        }
      gPlayerInfo[playerid][PLAYER_PASS] = newpassword;
      new string[256]; format(string, sizeof(string), "You have successfully changed your password from \'%s\' to \'%s\'.", tmp, tmp2);
      return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
    }
    else
      return SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Incorrect password.");
  }
}
It gives those errors:
Код:
C:\Documents and Settings\Janar\Desktop\SAMP\filterscripts\myadmin.pwn(468) : error 047: array sizes do not match, or destination array is too small
C:\Documents and Settings\Janar\Desktop\SAMP\filterscripts\myadmin.pwn(471) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
What's wrong with the array sizes? I don't understand it...
Reply
#2

WTF? You are using DCMD + strtok? that's the wrong methode dude.. use sscanf.
Reply
#3

What are you talking about? Donґt post things that you donґt know.
Topic: Post the lines 468 and 471 please
Reply
#4

Quote:
Originally Posted by WackoX
WTF? You are using DCMD + strtok? that's the wrong methode dude.. use sscanf.
What? What's so wrong in using dcmd with strtok? Please specify the lines in your code.

EDIT: Why did you define new string two times?
Reply
#5

I copied it from https://sampwiki.blast.hk/wiki/Creating_...n_FilterScript.

468 - tmp = strtok(params, index);
471 - tmp2 = strtok(params, index);

Sorry, but I am just so beginner about that.
Reply
#6

Код:
test
edit:delete this
this is test



DELETE
Reply
#7

Код:
	tmp = strtok(params, index);
	if(!strlen(tmp))
	return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
	tmp2 = strtok(params, index);
	if(!strlen(tmp2))
	return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
to

Код:
	format(tmp,128,"%s",strtok(params, index));
	if(!strlen(tmp))
	return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
	format(tmp2,128,"%s",strtok(params, index));
	if(!strlen(tmp2))
	return SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /password [password] [new password]");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)