29.12.2016, 06:32
You're using "new a" which is always set to 0.
Which means you have to be close to the ATM that's occupying index 0.
You need to loop through your ATMs and check if the player is close to one of them.
For optimization, you should create a global variable which stores the number of ATMs (So you don't have to loop using MAX_ATM)
Also, there are two things you should note:
You can just have those two inside of the enum.
And that's not how you're supposed to check for keys.
Carefully read this: https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Which means you have to be close to the ATM that's occupying index 0.
You need to loop through your ATMs and check if the player is close to one of them.
For optimization, you should create a global variable which stores the number of ATMs (So you don't have to loop using MAX_ATM)
PHP Code:
#define MAX_ATM 51
#define ATM_OBJECT 2942
enum aInfo
{
aID,
Float:aPosX,
Float:aPosY,
Float:aPosZ,
Float:aAngle,
aInt,
aVW,
bool: AtmExist,
}
new AtmInfo[MAX_ATM][aInfo],
Text3D:AtmLabel[MAX_ATM],
AtmObject[MAX_ATM],
Iterator: i_ATM<MAX_ATM>,
Atm_Count;
// Whenever you add an ATM
Atm_Count++;
// OnPlayerKeyStateChange
printf("Passed key");
new a = 0;
for (; a < Atm_Count; a++)
{
if (IsPlayerInRangeOfPoint(playerid, 2.0, AtmInfo[a][aPosX], AtmInfo[a][aPosY], AtmInfo[a][aPosZ]))
break;
}
if (a != Atm_Count) // if a didn't reach Atm_Count, then the player is near an ATM
{
printf("First passed");
if(PlayerInfo[playerid][AtmCard] != 1)
{
ERROR(playerid, "You need to purchase Atm Card");
return 1;
}
SPD(playerid, DIALOG_BANK, DIALOG_STYLE_LIST, "Bank", "Withdraw money\nPut in bank", "Select", "Leave");
printf("Dialog shown");
return 1;
}
PHP Code:
Text3D:AtmLabel[MAX_ATM]
AtmObject[MAX_ATM]
And that's not how you're supposed to check for keys.
Carefully read this: https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange