How do I load locally instead of globally?
#1

Hey guys. I am trying to make a system that basically stores a point in individual user files using DINI. I know dini is old and not really recommended by you guys to be used, but I've decided to do it just because some of the older scripts that I have lying around use it, and I'm trying to get a hang of it. I basically have the made it so that it stores the coordinates in individual files with the players name within a folder. The problem I have is however that anyone with any name can make use of that point, where it should only be the person that has the same name as on the dini file. In other words anyone can make use of the point one individually has put, where as I want it to be so that only people with the right name can make use of the point that has been set. How do I do that?

Code:
CMD:housepoint(playerid, params[])
{
    new file[256], name[24];
 	GetPlayerName(playerid, name, sizeof(name));
	format(file,sizeof(file),"HousePoint/%s.ini",name);
	if(!fexist(file))
	{
		new PlayerText3D:playertextid;
		new Float:X, Float:Y, Float:Z;
		GetPlayerPos(playerid, X, Y, Z);
		playertextid = CreatePlayer3DTextLabel(playerid,"Housepoint",0x008080FF,X,Y,Z,40.0);
		dini_Create(file);
		HousePoint[playerid][PosX] = dini_Float(file, "X");
	    HousePoint[playerid][PosY] = dini_Float(file, "Y");
	    HousePoint[playerid][PosZ] = dini_Float(file, "Z");
		HousePoint[playerid][PosX] = X;
		HousePoint[playerid][PosY] = Y;
		HousePoint[playerid][PosZ] = Z;
		dini_FloatSet(file, "X", HousePoint[playerid][PosX]);
		dini_FloatSet(file, "Y", HousePoint[playerid][PosY]);
		dini_FloatSet(file, "Z", HousePoint[playerid][PosZ]);
		//format(string1,sizeof(string1),"Position = X: %.0f , Y: %.0f , Z: %.0f",HousePoint[playerid][PosX],HousePoint[playerid][PosY],HousePoint[playerid][PosZ]);
        //SendClientMessage(playerid, -1, string1);
		SendClientMessage(playerid, -1, "You have set a house point!");
		
	}
	else
	{
		SendClientMessage(playerid, -1, "You already have a house point!");
	}
	return 1;
}

CMD:furniture(playerid, params[])
{
	if(!IsPlayerInRangeOfPoint(playerid, 4.0, HousePoint[playerid][PosX], HousePoint[playerid][PosY], HousePoint[playerid][PosZ])) return SendClientMessage(playerid, -1, "You are not at the area of your house point!");
	ShowPlayerDialog(playerid, DIALOG_FURNITURE_MENU, DIALOG_STYLE_LIST, "Furnitures", "Buy Furniture\nEdit Furniture\nSell Furniture\nSell All Furnitures (admin only)", "Choose", "Back");
	return 1;
}
Reply
#2

Quote:

The problem I have is however that anyone with any name can make use of that point
What do you mean by the part in bold. Give a code example of where a player can currently use the point of another player.
Because now, the only thing you have in the given code, is the creation of the file and the accessing of the personal point.

EDIT:
You don't need this when creating the point.
Code:
HousePoint[playerid][PosX] = dini_Float(file, "X");
HousePoint[playerid][PosY] = dini_Float(file, "Y");
HousePoint[playerid][PosZ] = dini_Float(file, "Z");
Reply
#3

Quote:
Originally Posted by Freaksken
View Post
What do you mean by the part in bold. Give a code example of where a player can currently use the point of another player.
Because now, the only thing you have in the given code, is the creation of the file and the accessing of the personal point.

EDIT:
You don't need this when creating the point.
Code:
HousePoint[playerid][PosX] = dini_Float(file, "X");
HousePoint[playerid][PosY] = dini_Float(file, "Y");
HousePoint[playerid][PosZ] = dini_Float(file, "Z");
Basically, when a player uses the command /housepoint, it creates a .ini file under the players name, which saves the players location and assigns a housepoint in which ONLY the player is able to use the command /furniture.

However, if a second player was to come to the server, the command /furniture would work in the previously assigned position, and the player would have to assign a new housepoint again, and it would keep going.

How do I make it so when a player uses the command /housepoint, only he can use the command /furniture in the area, instead of everyone being able to use the command in the assigned position?
Reply
#4

You probably forgot to reset the variables.

Code:
//OnPlayerConnect
new file[256], name[24];
GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"HousePoint/%s.ini",name);
if(!fexist(file)) { //The player does have a HousePoint already, so get the coordinates
    HousePoint[playerid][PosX] = dini_Float(file, "X");
    HousePoint[playerid][PosY] = dini_Float(file, "Y");
    HousePoint[playerid][PosZ] = dini_Float(file, "Z");
} else { //The player doesn't have a HousePoint yet, so reset the coordinates
    HousePoint[playerid][PosX] = 0.0;
    HousePoint[playerid][PosY] = 0.0;
    HousePoint[playerid][PosZ] = 0.0;
}

//Furniture command
if(HousePoint[playerid][PosX] == 0.0 && HousePoint[playerid][PosY] == 0.0 && HousePoint[playerid][PosZ] == 0.0) {
    SendClientMessage(playerid, -1, "You don't have a house point yet! Use /housepoint to set a house point.");
    return 1; //Stop the command
}
//Other furniture code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)