File problem...
#1

I've got a command that makes a file with the title-number you choosed.

Command:

pawn Код:
cmd(createnumber, playerid, params[])
{
  if(IsPlayerConnected(playerid))
  {
    new number;
    new string[128];
    new string2[32];
    if(sscanf(params, "d",number))
    {
       SendClientMessage(playerid, COLOR_HELP, "USAGE: /createnumber [number]");
       return 1;
    }
    if(number < 1000 || number > 9999999)
    {
       SendClientMessage(playerid, COLOR_ERROR, "INFO: Number can't begin with 0 and can't have less than 4 or more than 7 digits.");
       return 1;
    }
    format(string2, sizeof(string2), "Numbers/%s.ini", number);
    if(fexist(string2))
    {
       SendClientMessage(playerid, COLOR_ERROR, "INFO: The number you entered already exists. Please try another one.");
       return 1;
    }
    fopen(string2, io_write);
    format(string, sizeof(string), "INFO: You have successfully created number %d.", number);
    SendClientMessage(playerid, COLOR_INFO, string);
    PlayerPlaySound(playerid, 1052, 0.0,0.0,0.0);      
  }
  return 1;
}
Well, when i type in /createnumber 8000 it says that i successfully created that number, but when i go into the Numbers folder i see strange characters and not numbers that i typed in.

Can somebody point out the error in this code ? Thank you.
Reply
#2

Search for the IntToStr function here at the forums, and change
pawn Код:
format(string2, sizeof(string2), "Numbers/%s.ini", number);
to:
pawn Код:
format(string2, sizeof(string2), "Numbers/%s.ini", IntToStr(number));
 //If you have windows, you should change the format to "Numbers\\%s.ini"
Reply
#3

Or just:
pawn Код:
format(string2, sizeof(string2), "Numbers/%i.ini", number);
Reply
#4

Quote:
Originally Posted by Don Correlli
Or just:
pawn Код:
format(string2, sizeof(string2), "Numbers/%i.ini", number);
Hahaha, UBER fail by me, lol.
I should get some sleep xD
Reply
#5

Quote:
Originally Posted by Don Correlli
Or just:
pawn Код:
format(string2, sizeof(string2), "Numbers/%i.ini", number);
Thanks Correlli, it works great.
Reply
#6

You're welcome.
Reply
#7

I have another problem. xD

A player who created the number gets the number assigned to them so if they want another number the old one should delete.

I've got this:

pawn Код:
cmd(createnumber, playerid, params[])
{
  if(IsPlayerConnected(playerid))
  {
    new number;
    new oldnumber = PlayerInfo[playerid][pNumber];
    new string[128];
    new string2[32];
    new string3[32];
    if(sscanf(params, "d",number))
    {
       SendClientMessage(playerid, COLOR_HELP, "USAGE: /createnumber [number]");
       return 1;
    }
    if(number < 1000 || number > 9999999)
    {
       SendClientMessage(playerid, COLOR_ERROR, "INFO: Number can't begin with 0 and can't have less than 4 or more than 7 digits.");
       return 1;
    }
    format(string2, sizeof(string2), "Numbers/%s.ini", number);
    format(string3, sizeof(string3), "Numbers/%i.ini", oldnumber);
    if(fexist(string2))
    {
       SendClientMessage(playerid, COLOR_ERROR, "INFO: The number you entered already exists. Please try another one.");
       return 1;
    }
    if(fexist(string3)) { fremove(string3); } // Old number gets deleted ?
    fopen(string2, io_write);
    PlayerInfo[playerid][pNumber] = number;
    format(string, sizeof(string), "INFO: You have successfully created number %d.", number);
    SendClientMessage(playerid, COLOR_INFO, string);
    PlayerPlaySound(playerid, 1052, 0.0,0.0,0.0);      
  }
  return 1;
}
This works only one time (right before server restart) and afterwards it doesn't work (the new file is created without deleting the old one)

Help please. :P
Reply
#8

BUMP !
Reply
#9

BUMP !
Reply
#10

Debug your code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)