new iAreaID = CreateDynamicRectangle(0.0, 0.0, 10.0, 10.0);
OnPlayerEnterDynamicArea(playerid, areaid); // When a player enters an area. OnPlayerLeaveDynamicArea(playerid, areaid); // When a player exits an area.
#define MAX_HOUSES 2000 enum HInfo { Float:HouseExteriorX, Float:HouseExteriorY, Float:HouseExteriorZ, Float:HouseInteriorX, Float:HouseInteriorY, Float:HouseInteriorZ } new House[MAX_HOUSES][HInfo]; CMD:enterhouse(playerid, params[]) { for(new h; h < MAX_HOUSES; h++) { if(IsPlayerInRangeOfPoint(playerid, 2.0, House[h][HouseExteriorX], House[h][HouseExteriorY], House[h][HouseExteriorZ])) { // Virtual World checks are left out. SetPlayerPos(playerid, House[h][HouseInteriorX], House[h][HouseInteriorY], House[h][HouseInteriorZ]); // etc. } } return 1; } CMD:exithouse(playerid, params[]) { for(new h; h < MAX_HOUSES; h++) { if(IsPlayerInRangeOfPoint(playerid, 2.0, House[h][HouseInteriorX], House[h][HouseInteriorY], House[h][HouseInteriorZ])) { // Virtual World checks are left out. SetPlayerPos(playerid, House[h][HouseExteriorX], House[h][HouseExteriorY], House[h][HouseExteriorZ]); // etc. } } return 1; }
#define MAX_HOUSES 2000 enum HInfo { Float:HouseExteriorX, // I prefer Float:HousePos[3], but to be clear I use the linguistically more understandable version. Float:HouseExteriorY, Float:HouseExteriorZ, Float:HouseInteriorX, Float:HouseInteriorY, Float:HouseInteriorZ, bool:bExists, // I'd use a bitvar for this, but I won't make it too complicated just yet. iAreaID[2] // We create 2, one for the enter location and one for the exit location. } new House[MAX_HOUSES][HInfo]; House[h][iAreaID][0] = CreateDynamicSphere(House[h][HouseExteriorX], House[h][HouseExteriorY], House[h][HouseExteriorZ], 3.0, House[h][HouseVW]); // The house exterior. House[h][iAreaID][1] = CreateDynamicSphere(House[h][HouseInteriorX], House[h][HouseInteriorY], House[h][HouseInteriorZ], 3.0, House[h][HouseVW]); // The house interior.
OnPlayerEnterDynamicArea(playerid, areaid) // -> The areaid that we receive is the ID of the house exterior area.
Streamer_SetIntData(type, STREAMER_ALL_TAGS id, data, value);
CreateHouse(h) { // Let's say this is where the house is created. Streamer_SetIntData(STREAMER_TYPE_AREA, House[h][iAreaID][0], E_STREAMER_EXTRA_ID, h); Streamer_SetIntData(STREAMER_TYPE_AREA, House[h][iAreaID][1], E_STREAMER_EXTRA_ID, h); }
OnPlayerEnterDynamicArea(playerid, areaid) { // If you plan on using this in more systems, make sure the areaid equals that of the respective propery too! new h = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID); if(0 <= h < MAX_HOUSES) { // A bounds check if(House[h][bExists]) SetPVarInt(playerid, "AtHouse", h); // Just make sure that the house actually exists. For example with a variable. } } OnPlayerExitDynamicArea(playerid, areaid) { new h = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID); if(0 <= h < MAX_HOUSES) { // A bounds check if(House[h][bExists]) DeletePVar(playerid); // Make sure to delete the PVar when they go out of the enter/exit point. } }
CMD:enterhouse(playerid, params[]) { if(GetPVarType(playerid, "AtHouse")) { new h = GetPVarInt(playerid, "AtHouse"); SetPlayerPos(playerid, House[h][HouseInteriorX], House[h][HouseInteriorY], House[h][HouseInteriorZ], 3.0, House[h][HouseVW]); // etc. } else SendClientMessage(playerid, 0xFFFFFFFF, "You are not at a house."); return 1; }
Originally Posted by Jingles
// If you plan on using this in more systems, make sure the areaid equals that of the respective propery too!
|
CreateHouse(index)
{
new array[2];
array[0] = 1; /* House */
array[1] = index;
h_Info[index][Area] = CreateDynamicSphere(...);
Streamer_SetArrayData(STREAMER_TYPE_AREA, h_Info[index][Area], E_STREAMER_EXTRA_ID, array, 2);
return 1;
}
CreateBusiness(index)
{
new array[2];
array[0] = 2; /* Business */
array[1] = index;
b_Info[index][Area] = CreateDynamicSphere(...);
Streamer_SetArrayData(STREAMER_TYPE_AREA, b_Info[index][Area], E_STREAMER_EXTRA_ID, array, 2);
return 1;
}
public OnPlayerEnterDynamicArea(playerid, areaid)
{
new array[2];
Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, array, 2);
switch(array[0])
{
case 1: /* House */
{
SetPlayerPos(playerid, h_Info[array[1]][IntPos][0], ...);
}
case 2: /* Business */
{
SetPlayerPos(playerid, b_Info[array[1]][IntPos][0], ...);
}
}
return 1;
}
Really good tutorial, as Cryder said, Incognito's streamer is an amazing tool.
I wonder what method would you use in order to identify different properties, for example, differentiate between houses and businesses. I used arrays in order to save two values, the first one indicates the property type and the second one the id of the property. PHP Code:
PHP Code:
|
Can you give us example when player can enter and EXIT house pls ?
|
// global:
new gPlayer_InHouse[MAX_PLAYERS];
// OnPlayerConnect:
gPlayer_InHouse[playerid] = -1;
// OnPlayerPickUpDynamicPickup:
switch (Streamer_GetIntData(STREAMER_TYPE_PICKUP, pickupid, E_STREAMER_MODEL_ID))
{
case 1272, 1273:
{
// getting the "index" of the house to access the array
new houseid = Streamer_GetIntData(STREAMER_TYPE_PICKUP, pickupid, E_STREAMER_EXTRA_ID) - MAX_HOUSES;
if (gPlayer_InHouse[playerid] == -1) // player is not in any house, so this is "entering"
{
gPlayer_InHouse[playerid] = houseid;
// set position for interior of house.
SetPlayerPos(...);
}
else // player is in a house, so this is "exiting"
{
// set position for exterior of house and set some offset (for x, y) so the player won't be teleported on top of the pickup
SetPlayerPos(...);
gPlayer_InHouse[playerid] = -1;
}
}
}