SA-MP Forums Archive
OnPlayerKey - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerKey (/showthread.php?tid=625172)



OnPlayerKey - Micko123 - 29.12.2016

PHP Code:
if(newkeys == KEY_YES)
    {
        
printf("Passed key");
        new 
a;
        if(
IsPlayerInRangeOfPoint(playerid2.0AtmInfo[a][aPosX], AtmInfo[a][aPosY], AtmInfo[a][aPosZ]))
        {
            
printf("First passed");
            if(
PlayerInfo[playerid][AtmCard] != 1)
            {
                
ERROR(playerid"You need to purchase Atm Card");
                return 
1;
            }
            
SPD(playeridDIALOG_BANKDIALOG_STYLE_LIST"Bank""Withdraw money\nPut in bank""Select""Leave");
            
printf("Dialog shown");
            return 
1;
        }
    } 
In log it says this

After
printf("Passed key");
nothing gets executed.. It looks like I am not in range of point but I am...

But Nothing after that.. Here is the enum
PHP Code:
#define MAX_ATM        51
#define ATM_OBJECT    2942
enum aInfo
{
    
aID,
    
Float:aPosX,
    
Float:aPosY,
    
Float:aPosZ,
    
Float:aAngle,
    
aInt,
    
aVW,
    
boolAtmExist,
}
new 
AtmInfo[MAX_ATM][aInfo],
Text3D:AtmLabel[MAX_ATM],
AtmObject[MAX_ATM],
Iteratori_ATM<MAX_ATM>; 
Everything is created and loaded as it should be.. I jus don't understand why it won't work..


Re: OnPlayerKey - Stinged - 29.12.2016

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)

PHP Code:
#define MAX_ATM        51 
#define ATM_OBJECT    2942 
enum aInfo 

    
aID
    
Float:aPosX
    
Float:aPosY
    
Float:aPosZ
    
Float:aAngle
    
aInt
    
aVW
    
boolAtmExist

new 
AtmInfo[MAX_ATM][aInfo], 
Text3D:AtmLabel[MAX_ATM], 
AtmObject[MAX_ATM], 
Iteratori_ATM<MAX_ATM>,
Atm_Count;
// Whenever you add an ATM
Atm_Count++;
// OnPlayerKeyStateChange
printf("Passed key"); 
new 
0
for (; 
Atm_Counta++)
{
    if (
IsPlayerInRangeOfPoint(playerid2.0AtmInfo[a][aPosX], AtmInfo[a][aPosY], AtmInfo[a][aPosZ]))
        break;
}
if (
!= 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(playeridDIALOG_BANKDIALOG_STYLE_LIST"Bank""Withdraw money\nPut in bank""Select""Leave"); 
    
printf("Dialog shown"); 
    return 
1

Also, there are two things you should note:

PHP Code:
Text3D:AtmLabel[MAX_ATM]
AtmObject[MAX_ATM
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


Re: OnPlayerKey - Micko123 - 29.12.2016

Okay but explain me then how is this working??
PHP Code:
if(newkeys == KEY_SECONDARY_ATTACK)
    {
        new 
orgOrgID OrgInfo[org][oID];
        if(
IsPlayerInRangeOfPoint(playerid2.0OrgInfo[org][oExitX], OrgInfo[org][oExitY], OrgInfo[org][oExitZ]))
        {
            if(
PlayerInfo[playerid][OrgJoined] != OrgID || PlayerInfo[playerid][OrgLeader] != OrgID)
            {
                
ERROR(playerid"You are not member of that org");
                return 
1;
            }
            
SetPlayerInterior(playeridOrgInfo[org][oInt]);
            
SetPlayerVirtualWorld(playeridOrgInfo[org][oVW]);
            
SPP(playeridOrgInfo[org][oIntX], OrgInfo[org][oIntY], OrgInfo[org][oIntZ]);
        }
        } 



Re: OnPlayerKey - RayBiH - 29.12.2016

Try it without returns, so in the first one try keeping only the second return, if that doesn't work than use only the first one. Hope its not counfusing.


Re: OnPlayerKey - Micko123 - 29.12.2016

Quote:
Originally Posted by RayBiH
View Post
Try it without returns, so in the first one try keeping only the second return, if that doesn't work than use only the first one. Hope its not counfusing.
Znam na sta mislis.. nasao sam nacin
Thx


Re: OnPlayerKey - RayBiH - 29.12.2016

Quote:
Originally Posted by Micko123
View Post
Znam na sta mislis.. nasao sam nacin
Thx
Tek sad skonto da si od nas hehe, pozz

Nema problema.


Re: OnPlayerKey - Stinged - 29.12.2016

Quote:
Originally Posted by Micko123
View Post
Okay but explain me then how is this working??
PHP Code:
if(newkeys == KEY_SECONDARY_ATTACK)
    {
        new 
orgOrgID OrgInfo[org][oID];
        if(
IsPlayerInRangeOfPoint(playerid2.0OrgInfo[org][oExitX], OrgInfo[org][oExitY], OrgInfo[org][oExitZ]))
        {
            if(
PlayerInfo[playerid][OrgJoined] != OrgID || PlayerInfo[playerid][OrgLeader] != OrgID)
            {
                
ERROR(playerid"You are not member of that org");
                return 
1;
            }
            
SetPlayerInterior(playeridOrgInfo[org][oInt]);
            
SetPlayerVirtualWorld(playeridOrgInfo[org][oVW]);
            
SPP(playeridOrgInfo[org][oIntX], OrgInfo[org][oIntY], OrgInfo[org][oIntZ]);
        }
        } 
Because you're probably standing near the coordinates of the one with index = 0.
Try it with another Org (Make sure that this one still exists)