Please help, Small Saving problem.
#1

I have this saving co-ordinates script here, But even though i have folder called "attached", I get "Error saving" , I edited this to save automatically to a file with the same name of the player. I hope you can solve it. Thanks in advance

Код:
CMD:index(playerid,params[])
{
    if(!IsPlayerInRangeOfPoint(playerid,25.0,207.5627,-103.7291,1005.2578) || IsPlayerInRangeOfPoint(playerid,25.0,203.9068,-41.0728,1001.8047) || IsPlayerInRangeOfPoint(playerid,30.0,214.4470,-7.6471,1001.2109) || IsPlayerInRangeOfPoint(playerid,50.0,161.3765,-83.8416,1001.8047))
    {
	        SendClientMessage(playerid,COLOR,"You are not at any Clothing store");
			return 1;
    }
	if(isnull(params))
	{
	    SendClientMessage(playerid,COLOR,"{FFFFFF}/index [1-5] {AFAFAF}                - switch to exiting the object on that index");
	    SendClientMessage(playerid,COLOR,"{FFFFFF}/index [1-5] 0{AFAFAF}               - clear the object on that index");
	    SendClientMessage(playerid,COLOR,"{FFFFFF}/index [1-5] [model#] [bone]{AFAFAF} - add / change object on that index");
	    return 1;
	}
	new iindex,tmp[12],imodel,ibone;
	new string[128];
	if(sscanf(params,"iS()[12]I(2)",iindex,tmp,ibone))
	{
	    SendClientMessage(playerid,COLOR,"USAGE: /index [index 1-5] [model# / 0-clear ] [bone 1-18]");
	    return 1;
	}
	if(iindex < 1 || iindex > 5)
	{
	    SendClientMessage(playerid,COLOR,"USAGE: /index [index 1-5] [model# / 0-clear ] [bone 1-18]");
	    return 1;
	}
	if(!strlen(tmp))
	{
	    if(stats[playerid][iindex][model] == 0)
	    {
			format(string,sizeof(string),"There is no model attached to index %d",iindex);
			SendClientMessage(playerid,COLOR,string);
			return 1;
		}
		format(string,sizeof(string),"now editing index %d",iindex);
		SendClientMessage(playerid,COLOR,string);
		pindex[playerid] = iindex;
		DisplayIndex(playerid, iindex);
		return 1;
	}
	imodel = strval(tmp);
	if(imodel <= 0)
	{
	    RemovePlayerAttachedObject(playerid,(iindex - 1));
	    stats[playerid][iindex][model] = 0;
	    stats[playerid][iindex][bone] = 0;

	    format(string,sizeof(string),"Attach index %d cleared",iindex);
	    RemovePlayerAttachedObject(playerid,(iindex - 1));
	    ResetArray(playerid,iindex);
		SendClientMessage(playerid,COLOR,string);
		return 1;
	}
	if(ibone < 1 || ibone > 18)
	{
	    SendClientMessage(playerid,COLOR,"Invalid bone selected 1 - 18");
	    return 1;
	}
	pindex[playerid] = (iindex);
	ResetArray(playerid,iindex);
	DisplayIndex(playerid,iindex);
	stats[playerid][iindex][model] = imodel;
	stats[playerid][iindex][bone] = ibone;
	SetPlayerAttachedObject(playerid,(pindex[playerid]-1),
		stats[playerid][pindex[playerid]][model],
		stats[playerid][pindex[playerid]][bone],
		stats[playerid][pindex[playerid]][ox],
		stats[playerid][pindex[playerid]][oy],
		stats[playerid][pindex[playerid]][oz],
		stats[playerid][pindex[playerid]][rx],
		stats[playerid][pindex[playerid]][ry],
		stats[playerid][pindex[playerid]][rz],
		stats[playerid][pindex[playerid]][sx],
		stats[playerid][pindex[playerid]][sy],
		stats[playerid][pindex[playerid]][sz]
	);
	format(string,sizeof(string),"Attached object# %d to bone %d index %d",imodel,ibone,iindex);
	SendClientMessage(playerid,COLOR,string);
	return 1;
}
Reply
#2

I think you posted the wrong script, or where is the saving-to-file part?
Reply
#3

ROFL, i posted the wrong script, Sorry my bad , idk why it happened any this is the right one:-


Код:
CMD:asave(playerid,params[])
{
	new ref[6],string[128];
	new code = 0;
	for(new i = 1; i <= 5;i++)
	{
	    if(stats[playerid][i][model] > 0 && stats[playerid][i][bone] > 0)
	    {
	        code++;
	        ref[i] = 1;
		}
	}
	if(!code)
	{
	    SendClientMessage(playerid,COLOR,"You don't have any attachments added ( /editor )");
	    return 1;
	}
    new name[MAX_PLAYER_NAME];
    name[playerid] = GetPlayerName(playerid, name, sizeof(name));
	format(string,sizeof(string),"%s%s.ini",SAVE_PATH,name);
	new File:oFile = fopen(string, io_write);
	if(oFile)
	{
		for(new i = 1; i <= 5; i++)
		{
		    if(stats[playerid][i][model] > 0 && stats[playerid][i][bone] > 0)
		    {
				format(string,sizeof(string),"%d,%d,%d,%.2f,%.2f,%.2f,%.1f,%.1f,%.1f,%.2f,%.2f,%.2f\n",
					(i -1),
					stats[playerid][i][model],
					stats[playerid][i][bone],
					stats[playerid][i][ox],
					stats[playerid][i][oy],
					stats[playerid][i][oz],
					stats[playerid][i][rx],
					stats[playerid][i][ry],
					stats[playerid][i][rz],
					stats[playerid][i][sx],
					stats[playerid][i][sy],
					stats[playerid][i][sz]
				);
				fwrite(oFile,string);
			}
		}
		fclose(oFile);
		format(string,sizeof(string),"%s%s.ini saved successfully",SAVE_PATH,GetPlayerName(playerid, name, sizeof(name)));
		SendClientMessage(playerid,COLOR,string);
		return 1;
	}
	SendClientMessage(playerid,COLOR,"ERROR: creating file");
	return 1;
}
Reply
#4

The only thing I can think of is that you might have placed the map "attached" in ../filterscripts/ and not in ../scriptfiles/ did you?

Show me how you defined SAVE_PATH
Reply
#5

Nope , I did place it in scriptfiles
Reply
#6

Well I don't know exactly know what
pawn Код:
if(oFile)
    {
does but I read on the wiki page it can have several values, not just 0 or 1, but the filehandling. I think that is an integer, but I'm not sure so try
pawn Код:
if(oFile > 0)
    {
Another thing,
pawn Код:
fclose(oFile);
is a bit nasty located. It only closes the file if the statement above is true, so if that isn't true the file will be opened but not closed. If you execute the command again the script will want to open a file which is allready opened. This means oFile must allways be true for the server not to crash. So reposition that file closing
Reply
#7

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string,sizeof(string),"%s%s.ini",SAVE_PATH,name);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)