How do i make this cmd to save into a .cfg file ?
#1

Hello i got this command, but how do i make it saving it into a .cfg file or something alike that so when im doing /gmx it will stay the same registration plates ?

Код:
if(strcmp(cmd, "/regplate", true) == 0)
	{
  	tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /regplate [playerid/PartOfName] [xx-xxx-xxx]");
		}
		giveplayerid = ReturnUser(tmp);
		if (PlayerInfo[playerid][pAdmin] >= 1)
		{
			if(IsPlayerConnected(giveplayerid))
			{
			  if(giveplayerid != INVALID_PLAYER_ID)
			  {
				  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
					GetPlayerName(playerid, sendername, sizeof(sendername));
					new length = strlen(cmdtext);
					while ((idx < length) && (cmdtext[idx] <= ' '))
					{
						idx++;
					}
					new offset = idx;
					new result[64];
					while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
					{
						result[idx - offset] = cmdtext[idx];
						idx++;
					}
					result[idx - offset] = EOS;
					if(!strlen(result))
					{
						return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /regplate [playerid/PartOfName] [xx-xxx-xxx]");
					}
					if(IsPlayerInAnyVehicle(playerid))
					{
					  new vehicleid = GetPlayerVehicleID(playerid);
					  new Text3D:VText;
					  format(string,sizeof(string),"%s",(result));
						VText = Create3DTextLabel(string,0x008080FF,0.0,0.0,0.0,20,0,1);
						Attach3DTextLabelToVehicle(Text3D:VText, vehicleid, 0.0, 0.0, 0.0);
					}
					return 1;
				}
			}
			else
			{
				format(string, sizeof(string), "  %d is not an active player.", giveplayerid);
				SendClientMessage(playerid, COLOR_GRAD1, string);
			}
		}
		return 1;
	}
Reply
#2

bump
Reply
#3

Same problem here, i think that you just gotta make another line in your enum cars, and then make it insert into that line ( I load my cars from a file thats why )
Код:
strmid(DynamicCars[idcar][cReg], sendername, 0, strlen(sendername), 999);
Something like that, but you just gotta edit the sendername, because that was used to /v buy a car.
Reply
#4

Quote:
Originally Posted by Perker12345
Same problem here, i think that you just gotta make another line in your enum cars, and then make it insert into that line ( I load my cars from a file thats why )
Код:
strmid(DynamicCars[idcar][cReg], sendername, 0, strlen(sendername), 999);
Something like that, but you just gotta edit the sendername, because that was used to /v buy a car.
So what should i etc change ''sendername'' to ?
Reply
#5

Quote:
Originally Posted by Chivava
Quote:
Originally Posted by Perker12345
Same problem here, i think that you just gotta make another line in your enum cars, and then make it insert into that line ( I load my cars from a file thats why )
Код:
strmid(DynamicCars[idcar][cReg], sendername, 0, strlen(sendername), 999);
Something like that, but you just gotta edit the sendername, because that was used to /v buy a car.
So what should i etc change ''sendername'' to ?
Thats what i dont know We need a expert here please !
I just tested this, it did not work, could anybody else explain to us what we need?
Reply
#6

Quote:
Originally Posted by Perker12345
Quote:
Originally Posted by Chivava
Quote:
Originally Posted by Perker12345
Same problem here, i think that you just gotta make another line in your enum cars, and then make it insert into that line ( I load my cars from a file thats why )
Код:
strmid(DynamicCars[idcar][cReg], sendername, 0, strlen(sendername), 999);
Something like that, but you just gotta edit the sendername, because that was used to /v buy a car.
So what should i etc change ''sendername'' to ?
Thats what i dont know We need a expert here please !
I just tested this, it did not work, could anybody else explain to us what we need?
Would be nice if someone could answer on how to do this.
Reply
#7

You can use these functions.

pawn Код:
LoadPlates()
{
    new line[256];
    new Text3D:VText;
    new File: file = fopen("carplates.cfg", io_read);
    if (file)
    {
        new idx = 1;
        while (fread(file, line))
        {
            format(CarPlate[idx], sizeof(CarPlate[]), line);
            VText = Create3DTextLabel(CarPlate[idx],0x008080FF,0.0,0.0,0.0,20,0,1);
            Attach3DTextLabelToVehicle(VText, idx, 0.0, 0.0, 0.0);
            idx++;
        }
        fclose(file);
    }
    return 1;
}
pawn Код:
SavePlates()
{
    new File: file = fopen("carplates.cfg", io_write);
    new idx = 1;
    while (idx < sizeof(CarPlate))
    {
        fwrite(file, CarPlate[idx]);
        fwrite(file, "\r\n");
        idx++;
    }
    fclose(file);
    return 1;
}
Also put this top of script:

pawn Код:
new CarPlate[MAX_VEHICLES][24];
And then in your /regplate command

pawn Код:
if(IsPlayerInAnyVehicle(playerid))
                {
                    new vehicleid = GetPlayerVehicleID(playerid);
                    new Text3D:VText;
                    format(CarPlate[vehicleid], sizeof(CarPlate[]), result);
                    VText = Create3DTextLabel(CarPlate[vehicleid],0x008080FF,0.0,0.0,0.0,20,0,1);
                    Attach3DTextLabelToVehicle(VText, vehicleid, 0.0, 0.0, 0.0);
                    SavePlates();
                }
Also put LoadPlates(); in OnGameModeInit.
Reply
#8


Just 1 thing,
symbol is assigned a value that is never used: "line"

Код:
public SavePlates()
{
new line[256];
new File: file = fopen("carplates.cfg", io_write);
new idx = 1;
Reply
#9

Yes, you can delete that.
Reply
#10

Alright
Does this also happen to you?
Everytime i register a plate, i look in my carplates.cfg and then there is like 10 spaces between each car plate
-
Thats how it looks like
Код:
52-999-123








52-432-123
Reply
#11

Do the plates load correctly?
Reply
#12

After restart i could not see the plates, but they are still in the file.
I can't /regplate now, the 3dtext doesn't show up
Reply
#13

There is a limit of 1024 3D texts, I think that's the problem.
Reply
#14

How should i define SavePlates and LoadPlates ?
Reply
#15

I made it a bit better. You need 2 other functions in your script. Maybe you already have them.

pawn Код:
stock ini_GetKey( line[] )
{
    new keyRes[256];
    keyRes[0] = 0;
    if ( strfind( line , "=" , true ) == -1 ) return keyRes;
    strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
    return keyRes;
}

stock ini_GetValue( line[] )
{
    new valRes[256];
    valRes[0]=0;
    if ( strfind( line , "=" , true ) == -1 ) return valRes;
    strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
    return valRes;
}
pawn Код:
LoadPlates()
{
    new line[256], value[256];
    new vehicleid;
    new Text3D:VText;
    new File: file = fopen("carplates.cfg", io_read);
    if (file)
    {
        while (fread(file, line))
        {
            vehicleid = strval(ini_GetKey(line));
            value = ini_GetValue(line);
            format(CarPlate[vehicleid], sizeof(CarPlate[]), value);
            VText = Create3DTextLabel(CarPlate[vehicleid],0x008080FF,0.0,0.0,0.0,20,0,1);
            Attach3DTextLabelToVehicle(VText, vehicleid, 0.0, 0.0, 0.0);
        }
        fclose(file);
    }
    return 1;
}

SavePlates()
{
    new line[128];
    new File: file = fopen("carplates.cfg", io_write);
    new idx = 1;
    while (idx < sizeof(CarPlate))
    {
        if(strlen(CarPlate[idx]) != 0)
        {
            format(line, sizeof(line), "%d=%s\r\n", idx, CarPlate[idx]);
            fwrite(file, line);
        }
        idx++;
    }
    fclose(file);
    return 1;
}
Reply
#16

It says undefined symbol ''SavePlates'' and ''LoadPlates'' how should i define it ?
Reply
#17

huh...still need help,i've tried to repair bugs but no succes
Reply
#18

help
Reply
#19

It doesn't work for me!My pawno doesn't respond when i compile with those lines...need some help...the plates don't save..

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)