16.09.2013, 10:53
(
Последний раз редактировалось Threshold; 05.10.2013 в 15:55.
Причина: Missing Bracket, fixed issue with only 1 gate closing.
)
He is talking about the callback from Incognito's Streamer Plugin, OnPlayerEnterDynamicArea.
This is a very effective way of detecting a player entering, and another related callback used for detecting exiting, an area. I've written up this simple code (which can be more efficient, but I haven't gone to extreme lengths to keep the simplicity of it) for this case:
You will need to download the Streamer plugin and include it in your script.
Download/View Thread Here: https://sampforum.blast.hk/showthread.php?tid=102865
This is a very effective way of detecting a player entering, and another related callback used for detecting exiting, an area. I've written up this simple code (which can be more efficient, but I haven't gone to extreme lengths to keep the simplicity of it) for this case:
pawn Код:
#include <streamer>
new gatearea1;
new gatearea2;
new gatearea3;
//Gates are closed, so set 'Open' to false
new bool:gate1open = false;
new bool:gate2open = false;
new bool:gate3open = false;
public OnGameModeInit()
{
//Creating the areas
gatearea1 = CreateDynamicSphere(935.7413, 2403.9702, 12.2024, 7);
gatearea2 = CreateDynamicSphere(958.7637, 2403.9702, 12.1801, 7);
gatearea3 = CreateDynamicSphere(981.9069, 2403.9702, 12.2417, 7);
return 1;
}
public OnPlayerEnterDynamicArea(playerid, areaid)
{
if(areaid == gatearea1)
{
if(gate1open == false)
{
MoveObject(g1,2.50,935.7413, 2403.9702, 15.6253);
gate1open = true; //Gate 1 is now open, so true
}
}
if(areaid == gatearea2)
{
if(gate2open == false)
{
MoveObject(g2,2.50,958.7637, 2403.9702, 15.6253);
gate2open = true;
}
}
if(areaid == gatearea3)
{
if(gate3open == false)
{
MoveObject(g3,2.50,981.9069, 2403.9702, 15.6253);
gate3open = true;
}
}
return 1;
}
public OnPlayerLeaveDynamicArea(playerid, areaid)
{
if(areaid == gatearea1)
{
if(gate1open == true)
{
if(!PlayersInGateArea(playerid, 1))
{
MoveObject(g1,2.50,935.7413, 2403.9702, 12.2024);
gate1open = false;
}
}
}
if(areaid == gatearea2)
{
if(gate2open == true)
{
if(!PlayersInGateArea(playerid, 2))
{
MoveObject(g2,2.50,958.7637, 2403.9702, 12.1801);
gate2open = false;
}
}
}
if(areaid == gatearea3)
{
if(gate3open == true)
{
if(!PlayersInGateArea(playerid, 3))
{
MoveObject(g3,2.50,981.9069, 2403.9702, 12.2417);
gate3open = false;
}
}
}
return 1;
}
stock PlayersInGateArea(playerid, gatearea)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(i == playerid) continue;
switch(gatearea)
{
case 1: if(IsPlayerInDynamicArea(i, gatearea1)) return 1;
case 2: if(IsPlayerInDynamicArea(i, gatearea2)) return 1;
case 3: if(IsPlayerInDynamicArea(i, gatearea3)) return 1;
}
}
return 0;
}
Download/View Thread Here: https://sampforum.blast.hk/showthread.php?tid=102865

