01.05.2013, 18:19
How do i code that when the user presses F near a door, he enters it without writing /enter, same with /exit.
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & KEY_SECONDARY_ATTACK)
{
if (IsPlayerInRangeOfPoint(playerid, 3.0, 0.0, 0.0, 0.0)) // Replace 0.0, 0.0, 0.0 with your coords.
{
SetPlayerPos(playerid, 10.0, 20.0, 30.0);
}
}
return 1;
}
#define INVALID_AREA_ID (0xFFFF)
new CurrArea[MAX_PLAYERS] = { INVALID_AREA_ID, ... };
new myarea1, myarea2, myarea3;
public OnGameModeInit()
{
myarea1 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
myarea2 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
myarea3 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
}
public OnPlayerEnterDynamicArea(playerid, areaid) { CurrArea[playerid] = areaid; }
public OnPlayerLeaveDynamicArea(playerid, areaid) { CurrArea[playerid] = INVALID_AREA_ID ; }
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & KEY_SECONDARY_ATTACK)
{
if(CurrArea[playerid] != INVALID_AREA_ID)
{
switch(CurrArea[playerid])
{
case myarea1: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
case myarea2: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
case myarea3: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
}
}
}
return 1;
}
stock SetPlayerPosEx(playerid, Float:x, Float:y, Float:z, Float:fa, vw, int)
{
SetPlayerPos(playerid, x, y, z);
SetPlayerFacingAngle(playerid, fa);
SetPlayerVirtualWorld(playerid, vw);
SetPlayerInterior(playerid, int);
SetCameraBehindPlayer(playerid);
}
This way will work but is not very efficient if you have a lot of areas your better off using using the streamer plugin and adding areas in there then doing this.
pawn Код:
|
No real need for that since if they're not in an area it will only do two if statements although if they're in an area that is not an area that you can enter a building say it's a drop point then you'd have to weigh the trade off between checking through your foreach iterator vs doing the switch I think overall you'd actually be better off leaving it out since if your in an area that you can enter a building you wouldn't need to check the foreach iterator and still have to do the switch() anyways unless I'm missing something about your idea.
|