20.09.2018, 08:50
Quote:
Hello. In a house system, when player stands near the entrance pickup of a house, and types /buyhouse, he gets a dialog, which he should either submit or cancel, if player submits it, then on response of this dialog there should be all the stuff with money and mysql queries. The problem is that when player types /buyhouse, server loops through all houses (which might be over 2000 on a server), to find at which house's entrance the player is at, then on respone of the dialog there is the same loop, to get id of the house again. So this is kind of ineficcient to do those 2 loops, a solution that comes to my mind is to store the id of the house in a special variable in player's enum when he types /buyhouse, then use the value in it in the ondialogresponse function, but is this a bad practice?
P.S. by id of house i mean the index of it in the array of houses, and i obviously need to change variables in it after it's purchased. |
pawn Код:
// looping through all rows
// create a global variable and set value equal to the houses loaded.
// Let's call it "HousesLoaded". Say you have loaded 1500 houses so "HousesLoaded" is equal to 1500
House[i][Pickup] = CreateDynamicPickup(...);
Streamer_SetIntData(STREAMER_TYPE_PICKUP, House[i][Pickup], E_STREAMER_EXTRA_ID, i + 2000);
// native Streamer_SetIntData(type, id, data, value);
There is entrance pickup, when OnPlayerPickUpDynamicPickup is called you check for the type.
pawn Код:
// native Streamer_GetIntData(type, id, data);
new extra_id = Streamer_GetIntData(STREAMER_TYPE_PICKUP, House[i][Pickup], E_STREAMER_EXTRA_ID);
// now we want to check if subtracting 2000 from it will give us a range of 0-HousesLoaded.
if (0 <= (extra_id - 2000) <= HousesLoaded)
{
// okay, the type of pickup is house. alternative way might be to check the pickup modelid.
// now we'll store to another global variable the last house.
Player[playerid][Last_House] = extra_id - 2000;
// whenever you want to check now if the player is near a house, you can check if the player is in range with the last house
// you know the house index and you know the position
// show dialog to submit or cancel
}