Bugged FilterScript
#1

Hello! I am using an House Filterscript for SAMP 0.2, but I edited it to work in 0.3, but when I use it my server lags very much.. (objects and cars load to slow, etc...)

I'll leave here the code of the the FS if you can help me.


Код:
Code deleted
Reply
#2

Perhaps it laggs so much because of the timer ReadPlayerHouseData(playerid).

In that timer, you're looping through ALL houses (200 of them) for every player every second.
You're also checking if the file exists, so with 50 players online, you're checking if the housefile exist for 200 houses, multiplied with 50 players.
That's 200*50 = 10.000 checks on your harddrive every second.

Besides that, you're doing 10.000 distance checks too every second.

Wouldn't it be easier to use a streamer and setup 3DTextLabels at every house's location, instead of using this timer and displaying huge texts over the player's screen to inform him if this house is owned, and who's the owner?

Also, you have a bug in your OnFilterScriptInit callback:
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        SetTimer("ReadPlayerHouseData", 1000, true);
    }
You didn't supply the timer with a playerid parameter, so it would only work for playerid 0.
Use this if you want to keep that timer:
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        SetTimerEx("ReadPlayerHouseData", 1000, true, "d", i);
    }
Reply
#3

For the server doesnґt nedd to check the 200 homes or the maximum nunmber of houses, I'll try to edit the script so that it only check for existing homes.

Thank you.
Reply
#4

Can you help me doing that?


I had created a file (housecount.ini), and I want that when I create a new house, the server adds 1 to the housecount, so, if are just 20 houses created, the server will only check the files with ID between 1 and 20.

I'll leave here the code where it checks the files ..



Код:
public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("Stefan's House System");
	print("--------------------------------------\n");

	for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        SetTimerEx("ReadPlayerHouseData", 1000, true, "d", i);
    }
	for(new h = 0; h <= MAX_HOUSES; h++) // Player Homes
	{
	    LoadPlayerHouse(h);
	}
 	SetTimer("SaveAllPlayerData",60000,true);
	return true;
}
Код:
public ReadPlayerHouseData(playerid)
{
	new string[256], house[64];
	for(new h = 0; h <= MAX_HOUSES; h++)
	{
		format(house, sizeof(house), "/Houses/%d.dini.save", h);
	    if(dini_Exists(house))
		{
			if(HouseInfo[h][hSellable] == 1)
			{
	  			if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]))
	  			{
					format(string, sizeof(string), "~g~] House for Sale ]~n~~w~Level:~y~ %d~n~~w~Sell Price:~r~ %d", HouseInfo[h][hLevel], HouseInfo[h][hSell]);
					GameTextForPlayer(playerid,string, 3000, 3);
				}
			}
			else if(HouseInfo[h][hSellable] == 0 && HouseInfo[h][hRentable] == 0)
			{
				if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]))
				{
					format(string, sizeof(string), "~w~Owner:~y~ %s~n~~w~Level:~r~ %d", HouseInfo[h][hName], HouseInfo[h][hLevel]);
					GameTextForPlayer(playerid,string, 3000, 3);
				}
			}
   			else if(HouseInfo[h][hSellable] == 0 && HouseInfo[h][hRentable] == 1)
			{
				if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]))
				{
					format(string, sizeof(string), "~w~Owner:~y~ %s~n~~w~Level:~r~ %d~n~~w~Rent Cost:~r~ %d", HouseInfo[h][hName], HouseInfo[h][hLevel], HouseInfo[h][hRent]);
					GameTextForPlayer(playerid,string, 3000, 3);
				}
			}
		}
	}
}
Reply
#5

>> Help me please <<
Reply
#6

Just load all the houses when the filterscript starts.
You could add a new field in the enum, which states if the house was loaded or not.
This would also indicate that the house has a valid, existing file.

You could still loop through all the houses, just by checking the new field instead of checking if the housefile exists.
Since you'll get rid of the file-check on your harddrive, you'll reduce alot of lagg, since harddrive access is way slower than memory access.
Reply
#7

Ok, thank you.

Itґs working
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)