(if) your house system looks like
Код:
#define MAX_HOUSES 10000
new HouseOwner[MAX_HOUSES][MAX_PLAYER_NAME];
new HouseEnterPickup[MAX_HOUSES];
new HousePickupLinksToHouseID[MAX_HOUSES];
...then create a house for sale:
Код:
new id=12;//any house id, maybe serialized in a loop when loading, or Houses+1; when creating a new house.
new pick=CreateDynamicPickup(blablabla);//will return a pickupid like 134 - make sure that the max_pickups #define/array is ALWAYS bigger!
HouseEnterPickup[pick==134]=id;//134th pickup gets assigned the 12, as its pointing to the 12th house.
HousePickupLinksToHouseID[HouseEnterPickup[id]==134]=2070;// HouseEnterPickup[id] = 134 and 2070 is the target interior of the house
later, HouseEnterPickup[id] will get replaced by pickupid - it will serve as pointer to your houseid directly: HousePickupLinksToHouseID[pickupid]...
now a command to buy a house by setting the HouseOwner[HouseID] array to the players' name. lets say, (3)Babul will buy a house in pricke pine, and the houses interior ID is 2070:
you will need to use the OnPlayerPickUpDynamicPickup() callback and pickupid. since the entrances are using pickups, the pickups' id of the last (recently) touched pickup will be stored in a player variable.
btw: the pickup callback gets triggered each 2 or 3 seconds, as long you are standing in a pickup all time - this makes any timer obsolete.
Код:
//either a callback or command using playerid. not to forget the (P)Var set previously in the pickup callback. (when a player stepped into the pickup at the door)
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid,Name,sizeof(Name));
//now, the magic trick:
new pickupid=GetPVarInt(playerid,"PickupIDTouched");//see below... this is NOT meant to be in the pickup callback, thats why i need to create a pickupid.
new HouseID=HousePickupLinksToHouseID[pickupid];//remember when writing into cell HouseEnterPickup[id]=134 ? pickupid==134 now, so it "Links" to the cell 134's element, which contains 2070. the houses' interior!
HouseOwner[HouseID]=Name;//HouseID==2070 - lets assume i got enough cash. always test it without any limitations
now its time for the streamer plugin to do the dirty work for you (returning the pickupid you are touching):
Код:
forward OnPlayerPickUpDynamicPickup(playerid,pickupid); public OnPlayerPickUpDynamicPickup(playerid,pickupid){
{
SetPVarInt(playerid,"PickupIDTouched",pickupid);
return 1;
}
lets resume:
the 12th house (interior 2070) pickup got created, its the 134th pickup on the map.
when a player touches it, the pickupid will be the n-th pickupid (134) in the callback
if HouseEnterPickup[pickupid=134] links to a house id (>0 for a valid house), used as pointer in HousePickupLinksToHouseID[], then the resulting branch could be "decoded" as
HousePickupLinksToHouseID[HouseEnterPickup[pickupid==134]==12]==2070
this system is volatile to bugs, you need to polish it up a bit.