/createpayphone <-- Check this!
#1

Hey guys so Im creating a dynamic payphone command /createpayphone. The Savephone() writes to the file but for some reason its not loading them. Do you guys see an issue you here?


LOAD PHONE
Код:
LoadPhones()
{
//	new string[256];
    new arrCoords[4][64];
    new strFromFile2[260];
    new File: file = fopen("payphones.cfg", io_read);
    if(file)
    {
        new idx;
        while (idx < sizeof(PhoneInfo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, '|');
            PhoneIDTaken[idx] = strval(arrCoords[0]);
            PhoneInfo[idx][PhoneX] = floatstr(arrCoords[1]);
            PhoneInfo[idx][PhoneY] = floatstr(arrCoords[2]);
            PhoneInfo[idx][PhoneZ] = floatstr(arrCoords[3]);
        	if(HouseIDTaken[idx])
        	{
				CreateStreamed3DTextLabel(PAYPHONE_LABEL, HOUSE_COLOR,PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ] , 10.0, idx);
                phones++;
			}
			idx++;
		}
	}
	return 1;
}
SAVE PHONE
Код:
SavePhones()
{
    new idx = 1;
    new File: file2;
    while (idx < sizeof(GarageInfo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "|%d|%f|%f|%f|\n",
       	GarageIDTaken[idx],
   	   	PhoneInfo[idx][PhoneX],
	   	PhoneInfo[idx][PhoneY],
	   	PhoneInfo[idx][PhoneZ]);
     	if(idx == 0)
		{
			file2 = fopen("payphones.cfg", io_write);
		}
		else
		{
			file2 = fopen("payphones.cfg", io_append);
		}
		fwrite(file2, coordsstring);
		idx++;
		fclose(file2);
    }
    return 1;
}
COMMAND
Код:
   	if(strcmp(cmd, "/createphone", true) == 0)
	{
	    if(PlayerInfo[playerid][pAdmin] >= 1337)
	    {
	        new id = GetAvailableID(TYPE_PHONE);
			new Float:x, Float:y, Float:z;
			GetPlayerPos(playerid, x, y, z);
			PhoneIDTaken[id] = 1;
            PhoneInfo[id][PhoneX] = x;
            PhoneInfo[id][PhoneY] = y;
            PhoneInfo[id][PhoneZ] = z;
			SavePhones();
            CreateStreamed3DTextLabel(PAYPHONE_LABEL, HOUSE_COLOR, x, y, z, 10.0, 0);
		}
		return 1;
	}
Reply
#2

pawn Код:
SavePhones()
{
    new coordsstring[50],idx = -1;
    new File:file = fopen("payphones.cfg", io_write);
    while(++idx < sizeof(GarageInfo))
    {
        format(coordsstring, sizeof(coordsstring), "%d|%.4f|%.4f|%.4f\r\n",GarageIDTaken[idx],PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ]);
        fwrite(file, coordsstring);
    }
    fclose(file);
    return;
}

LoadPhones()
{
    new arrCoords[4][64];
    new strFromFile[100];
    new File:file = fopen("payphones.cfg", io_read);
    if(file)
    {
        new idx = -1;
        while(++idx < sizeof(PhoneInfo) && fread(file, strFromFile))
        {
            split(strFromFile, arrCoords, '|');
            PhoneIDTaken[idx] = strval(arrCoords[0]);
            PhoneInfo[idx][PhoneX] = floatstr(arrCoords[1]);
            PhoneInfo[idx][PhoneY] = floatstr(arrCoords[2]);
            PhoneInfo[idx][PhoneZ] = floatstr(arrCoords[3]);
            printf("%s = %d, %.4f, %.4f, %.4f",strFromFile,PhoneIDTaken[idx],PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ]);
            if(HouseIDTaken[idx])
            {
                CreateStreamed3DTextLabel(PAYPHONE_LABEL, HOUSE_COLOR, PhoneInfo[idx][PhoneX], PhoneInfo[idx][PhoneY], PhoneInfo[idx][PhoneZ], 10.0, idx);
                phones++;
            }
        }
    }
    return;
}

if(strcmp(cmd, "/createphone", true) == 0)
{
    if(PlayerInfo[playerid][pAdmin] >= 1337)
    {
        new id = GetAvailableID(TYPE_PHONE); // must returns 0 - sizeof(PhoneInfo)-1
        PhoneIDTaken[id] = 1;
        GetPlayerPos(playerid, PhoneInfo[id][PhoneX], PhoneInfo[id][PhoneY], PhoneInfo[id][PhoneZ]);
        CreateStreamed3DTextLabel(PAYPHONE_LABEL, HOUSE_COLOR, PhoneInfo[id][PhoneX], PhoneInfo[id][PhoneY], PhoneInfo[id][PhoneZ], 10.0, 0);
        SavePhones();
    }
    return 1;
}
and show printf in load and why is GarageIDTaken then PhoneIDTaken[idx] and HouseIDTaken[idx] ? 3 different arrays ?
Reply
#3

Код:
	LoadPhones();
	printf("[OnGameModeInit] payphone.cfg loaded.(gate count: %d)", phones);
Like this?
Reply
#4

yes but i dont see my printf("%s = %d, %.4f, %.4f, %.4f",strFromFile,PhoneIDTaken[idx],PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ]);
Reply
#5

Oh sorry, okay i've added it now this is what I'm getting. In the log

Код:
[22:47:47] |1|2308.125488|-1636.242431|14.827047|
 = 14, 1.0000, 2308.1254, -1636.2424
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:47] |1|2308.125488|-1636.242431|14.827047|
 = 14, 1.0000, 2308.1254, -1636.2424
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] |1|0.000000|0.000000|0.000000|
 = 0, 1.0000, 0.0000, 0.0000
[22:47:48] |0|0.000000|0.000000|0.000000|
 = 0, 0.0000, 0.0000, 0.0000
[22:47:48] [OnGameModeInit] payphone.cfg loaded.(gate count: 2)
Reply
#6

Does anyone see the problem with this system? Really stuck on this!
Reply
#7

You must save as ID|X|Y|Z not |ID|X|Y|Z|
Reply
#8

Where is the error
Reply
#9

Okay I've changed that to this now the Savephones() is crashing, once I do /createphone it goes to that function then stops and then i can't type anything into the server no commands or anything. so somethings wrong with this im pretty sure.

Код:
SavePhones()
{
    new idx = 1;
    new File:file = fopen("payphones.cfg", io_write);
    while (idx < sizeof(PhoneInfo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "%d|%.4f|%.4f|%.4f\r\n",PhoneIDTaken[idx],PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ]);
	}
	fclose(file);
    return;
}
Reply
#10

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
SavePhones()
{
    new coordsstring[50],idx = -1;
    new File:file = fopen("payphones.cfg", io_write);
    while(++idx < sizeof(GarageInfo))
    {
        format(coordsstring, sizeof(coordsstring), "%d|%.4f|%.4f|%.4f\r\n",GarageIDTaken[idx],PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ]);
        fwrite(file, coordsstring);
    }
    fclose(file);
    return;
}

LoadPhones()
{
    new arrCoords[4][64];
    new strFromFile[100];
    new File:file = fopen("payphones.cfg", io_read);
    if(file)
    {
        new idx = -1;
        while(++idx < sizeof(PhoneInfo) && fread(file, strFromFile))
        {
            split(strFromFile, arrCoords, '|');
            PhoneIDTaken[idx] = strval(arrCoords[0]);
            PhoneInfo[idx][PhoneX] = floatstr(arrCoords[1]);
            PhoneInfo[idx][PhoneY] = floatstr(arrCoords[2]);
            PhoneInfo[idx][PhoneZ] = floatstr(arrCoords[3]);
            printf("%s = %d, %.4f, %.4f, %.4f",strFromFile,PhoneIDTaken[idx],PhoneInfo[idx][PhoneX],PhoneInfo[idx][PhoneY],PhoneInfo[idx][PhoneZ]);
            if(HouseIDTaken[idx])
            {
                CreateStreamed3DTextLabel(PAYPHONE_LABEL, HOUSE_COLOR, PhoneInfo[idx][PhoneX], PhoneInfo[idx][PhoneY], PhoneInfo[idx][PhoneZ], 10.0, idx);
                phones++;
            }
        }
    }
    return;
}

if(strcmp(cmd, "/createphone", true) == 0)
{
    if(PlayerInfo[playerid][pAdmin] >= 1337)
    {
        new id = GetAvailableID(TYPE_PHONE); // must returns 0 - sizeof(PhoneInfo)-1
        PhoneIDTaken[id] = 1;
        GetPlayerPos(playerid, PhoneInfo[id][PhoneX], PhoneInfo[id][PhoneY], PhoneInfo[id][PhoneZ]);
        CreateStreamed3DTextLabel(PAYPHONE_LABEL, HOUSE_COLOR, PhoneInfo[id][PhoneX], PhoneInfo[id][PhoneY], PhoneInfo[id][PhoneZ], 10.0, 0);
        SavePhones();
    }
    return 1;
}
and show printf in load and why is GarageIDTaken then PhoneIDTaken[idx] and HouseIDTaken[idx] ? 3 different arrays ?
all what you need, only replace Garage...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)