IsPlayerNearObject problem
#1

Hi!

I got a problem with my function:

Here's an command.
pawn Код:
CMD:atm(playerid, cmdtext[])
{
    if(!IsPlayerNearObject(playerid, 2942, 2.0))return SendClientMessage(playerid, COLOR_RED, "* You're not near a ATM.");
    ShowPlayerDialog(playerid, DIALOG_BANK, [...]);
    return true;
}
Function IsPlayerNearObject:
pawn Код:
stock IsPlayerNearObject(playerid, objectid, Float:range)
{
    new Float:X, Float:Y, Float:Z;
    GetObjectPos(objectid, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
    return false;
}
So.. my problem is, when i'm near ATM the message sends to me. It shouldn't send. Any suggestions?
Reply
#2

Are you sure that you're not confusing the objectid with the object model? The objectid is a specific integer that references to the unique instance of an object, which is why most functions deal with the objectid and not the model, otherwise how can the script tell which object you want to move if you're only specifying the model?

An example of how to store an object's id and use it in another function later can be seen here:

https://sampwiki.blast.hk/wiki/MoveObject
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Are you sure that you're not confusing the object model with the objectid? The objectid is a specific integer that references to the unique instance of an object, which is why most functions deal with the objectid and not the model, otherwise how can the script tell which object you want to move if you're only specifying the model?

An example of how to store an object's id and use it in another function later can be seen here:

https://sampwiki.blast.hk/wiki/MoveObject
i was wondering if there was a way to do it with object models
Reply
#4

I'm sure it's object ID. And i wasn't say i wan't to move object. I need only to check if is player near ATM object. That's all and i'll not use PlayerToPoint or something like this shit. I need only to check when player is near object.
Reply
#5

You're definetly using model instead of ID. What you can do, like the person above said, define ATM Objects like:

pawn Код:
new ATM;

ATM = CreateObject(2942, X, Y, Z);
And when you check if the player is near object, use:
pawn Код:
CMD:atm(playerid, cmdtext[])
{
    if(!IsPlayerNearObject(playerid, ATM, 2.0))return SendClientMessage(playerid, COLOR_RED, "* You're not near a ATM.");
    ShowPlayerDialog(playerid, DIALOG_BANK, [...]);
    return true;
}
Thats how you should do it.
Reply
#6

Antonio he's asking about how to get it from the model not the id so is there a way or not

cause with that code antonio and he has like 10 atms it will be like :

if(!IsPlayerNearObject(playerid, ATM, 2.0) || !IsPlayerNearObject(playerid,ATM2,2.0 .........))
Reply
#7

That function doesn't support checking by the modelid by the looks of it, although I don't really know since I didn't make that function and it's not a default SA-MP function

Either way you could easily make a loop to achieve the same thing as having an if statement with several logical OR operators, for example:

pawn Код:
#define ATM_COUNT 10
new ATM[ATM_COUNT];

ATM[0] = CreateObject(); // First ATM
ATM[1] = CreateObject(); // Second ATM
// And so on...

stock IsPlayerNearATM(playerid)
{
    for(new i; i < ATM_COUNT; i++) if(IsPlayerNearObject(playerid, ATM[i], 2.0)) return i;
    return -1;
}

if(IsPlayerNearATM(playerid) != -1) // Player is near an ATM!
Reply
#8

i've already made it with new variable but not working too. I was done it before i made thread.

@JaTochNietDan
I'll try with your proposal and i'll edit this post.
Reply
#9

I didn't edit but reason is here:

I'm so fucking stupid. I lost about that - i'm used CreateDynamicObject and wan't to use GetObjectPos. I was need to use GetDynamicObjectPos xD I'm really sorry for you all.

P.S
You can delete this topic for ever :d..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)