Is player in range of an object
#1

Okay ive tryed making so you can use this command near a ATM (object 2942), and i can't see anything wrong and there is no warnings or errors. It all works, just when i go to the atm it keeps giving me the "Message3" even tho im near it. So i guess i did something wrong. But what?

pawn Код:
command(awithdraw, playerid, params[])
{
    new Amount, string[ 128 ], Float:X, Float:Y, Float:Z;
    if( sscanf( params, "d", Amount) )
    {
        SendClientMessage( playerid, WHITE, "Message1" );
    }
    else
    {
        if(Amount < 1)
        {
        }
        else
        {
            GetObjectPos(2942, X, Y, Z);
            if(IsPlayerInRangeOfPoint( playerid, 5.0, X, Y, Z) )
            {
                if(Amount > Player[playerid][BankMoney])
                {
                    SendClientMessage( playerid, WHITE, "Message2" );
                }
                else
                {
                    SendClientMessage( playerid, WHITE, "It Works." );
                }
            }
            else
            {
                SendClientMessage( playerid, WHITE, "Message3" );
            }
        }
    }
    return 1;
}
Reply
#2

new atm;

atm = CreateObject(...


GetObjectPos(atm, X, Y, Z);

Dont mix model id with object id
Reply
#3

Quote:
Originally Posted by Voldemort
Посмотреть сообщение
new atm;

atm = CreateObject(...


GetObjectPos(atm, X, Y, Z);

Dont mix model id with object id
Oh okay thanks. But i have allot of atm machines so how could i make it for everyone without doing like this:

atm0 = CreateObject(...
atm1 = CreateObject(...
atm2 = CreateObject(...
And so on..
Reply
#4

It would be better to place all of your ATM objects into an array.
pawn Код:
new atm[3];
atm[0]=CreateObject(...
atm[1]=CreateObject(...
atm[2]=CreateObject(...
That way you can loop through them easily
pawn Код:
new Float:x,Float:y,Float:z;
for(new object;object<sizeof(atm);object++)
{
    GetObjectPos(atm[object],x,y,z);
    if(IsPlayerInRangeOfPoint(playerid,5.0,x,y,z))
    {
        //code
        break;
    }
}
Reply
#5

pawn Код:
new atm[50];

atm[0] = CreateObject(...)
atm[1] = CreateObject(...)
atm[2] = CreateObject(...)
atm[49] = CreateObject(...)

// command
new x = 0;
for(new i = 0; i < sizeof(atm); i++)
{
    new Float:Pos[3];
    GetObjectPos(atm[i], Pos[0], Pos[1], Pos[2]);
    if(IsPlayerInRangeOfPoint(playerid, 3.0, Pos[0], Pos[1], Pos[2])) x++;
}
if(x == 0) return SendClientMessage(playerid, 0xFF0000FF, "You are not near the ATM machine!");
// rest of code (if is near the atm machine)
Reply
#6

Thanks Pooh7, SilentHuntR and Voldemort it really helped me allot thanks .
Reply
#7

Quote:
Originally Posted by Pooh7
Посмотреть сообщение
pawn Код:
for(new i = 0; i < sizeof(atm); i++)
{
    new Float:Pos[3];
}
You shouldn't create variables inside of a loop, in this instance it won't do much harm, but it's good general practice. Under harsh circumstances, allocating memory per loop causes speed reduction
Reply
#8

For some reason it doesn't work all it does is spamming the text "You have to be at a ATM to complete such a transaction." 9 times, even if im near or not. Here is what i did:

pawn Код:
new atm[9];
pawn Код:
atm[0] = CreateDynamicObject(2942, 2055.6823730469, -1897.5423583984, 13.19670009613, 0, 0, 0);
atm[1] = CreateDynamicObject(2942, 1451.9300537109, -1010.1575317383, 26.48664855957, 0, 0, 0);
atm[2] = CreateDynamicObject(2942, 1318.3095703125, -897.8076171875, 39.22102355957, 0, 0, 0);
atm[3] = CreateDynamicObject(2942, 2238.7265625, -1722.6788330078, 13.196180343628, 0, 0, 0);
atm[4] = CreateDynamicObject(2942, 1928.5771484375, -1770.76171875, 13.189774513245, 0, 0, 90);
atm[5] = CreateDynamicObject(2942, 1154.7824707031, -1456.0352783203, 15.439774513245, 0, 0, 270);
atm[6] = CreateDynamicObject(2942, 1000.8654174805, -922.52899169922, 41.97102355957, 0, 0, 280);
atm[7] = CreateDynamicObject(2942, 2314.2058105469, -1645.0303955078, 14.469946861267, 0, 0, 0);
atm[8] = CreateDynamicObject(2942, 19.167484283447, -697.08135986328, 2338.0517578125, 0, 0, 90);
pawn Код:
command(atmwithdraw, playerid, params[])
{
    new Amount, string[ 128 ], Float:x,Float:y,Float:z;
    if( sscanf( params, "d", Amount) )
    {
        SendClientMessage( playerid, WHITE, "SYNTAX: /atmwithdraw [amount]" );
    }
    else
    {
        if(Amount < 1)
        {
        }
        else
        {
            for(new object;object<sizeof(atm);object++)
            {
                GetObjectPos(atm[object],x,y,z);
                if(IsPlayerInRangeOfPoint(playerid,5.0,x,y,z) )
                {
                    if( Player[playerid][BankStatus] == 1)
                    {
                        SendClientMessage( playerid, WHITE, "The authorities have suspended your bank account." );
                    }
                    else
                    {
                        if(Amount > Player[playerid][BankMoney])
                        {
                            SendClientMessage( playerid, WHITE, "You don't have that much in your bank account." );
                        }
                        else
                        {
                            Player[playerid][Money] += Amount;
                            Player[playerid][BankMoney] -= Amount;
                            format( string, sizeof( string ), "You have successfully withdrawn $%d from your bank account.", Amount);
                            SendClientMessage( playerid, WHITE, string);
                            break;
                        }
                    }
                }
                else
                {
                    SendClientMessage( playerid, WHITE, "You have to be at a ATM to complete such a transaction." );
                }
            }
        }
    }
    return 1;
}
Reply
#9

Try using this, http://pastebin.com/u337PdcV
Reply
#10

Quote:
Originally Posted by CyNiC
Посмотреть сообщение
Hmm, still doesn't work it just keep saying "You have to be at a ATM to complete such a transaction." :/. But atleast it doesn't spam it now.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)