Problem
#1

For a mistake i deleted my old thread.

Thank you for that guy who answered me, i have another question, how to check if player is in range of points by that coordinates?

I made in this way:

pawn Код:
enum ShopCoordinates
{
    Float:XXX,
    Float:YYY,
    Float:ZZZ
}
pawn Код:
new const Coords[][ShopCoordinates] =
{
    {-29.1478,-184.3768,1003.5469}, // 24/7 - 1 - Int id 17 - VW0
    {2.3476,-28.2501,1003.5494}, // 24/7 - 2 - Int id 10 - VW0
};
I need to check if player is in range of this coordinates, how?
Reply
#2

You can use IsPlayerInRangeOfPoint.
Reply
#3

it should be float

PHP код:
new const Float:Coords[][ShopCoordinates] =
{
    {-
29.1478,-184.3768,1003.5469}, // 24/7 - 1 - Int id 17 - VW0
    
{2.3476,-28.2501,1003.5494// 24/7 - 2 - Int id 10 - VW0
}; 
PHP код:
for(new 0sizeof(ShopCoordinates); i++)
{
    if(
IsPlayerInRangeOfPoint(playerid20.0Coords[i][0], Coords[i][1], Coords[i][2])
    {
        
//code
        
break;
    }

Reply
#4

Why break;?
Reply
#5

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Why break;?
To stop the loop once we found a nearby store
Reply
#6

Код:
for(new i = 0; i<sizeof(Coords); i++)
{
      if(IsPlayerInRangeOfPoint(playerid, range, Coords[i][XXX], Coords[i][YYY], Coords[i][ZZZ]))
      {
            // so the if statement check if you are standing near these coords. 
            // here you can insert any action
            break;
      }
}
the question is how you want to check it?

Check when someone enter a command?
Check when someone gets close to these coords?
Reply
#7

I wanna check if a player press Y but i can do it alone, thanks.
Reply
#8

Using OnPlayerKeyStateChange this can be a simple task.

Код:
// PRESSED(keys)
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if (PRESSED(KEY_YES)) // default key is Y
	{
		if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z)) // plug in your range, X, Y, and Z coordinates here.
		{
			// do what ever you wish to do here.
		}
	}
	return 1;
}
I realise you said you would do it alone, but I figured I'd give you the bare bones code for your own reference or anyone else coming across this thread wanting to do a similar thing.
Reply
#9

Thank you very much

P.S You can also use:

pawn Код:
if (newkeys & KEY_YES)
Instead of pressed, works too.
Reply
#10

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Thank you very much

P.S You can also use:

pawn Код:
if (newkeys & KEY_YES)
Instead of pressed, works too.
While it might work, it isn't as accurate as the PRESSED define.

Quote:
Originally Posted by wiki
So, if the variable can contain multiple keys at once, how do you check for just a single one? The answer is bit masking. Each key has its own bit in the variable (some keys have the same bit, but they are onfoot/incar keys, so can never be pressed at the same time anyway) and you need to check for just that single bit:

Код:
if (newkeys & KEY_FIRE)
Note that the single "&" is correct - this is a bitwise AND, not a logical AND, which is what the two ampersands are called.

Now if you test this code it will work whether you are crouching or standing when you press the fire key. However there is still one slight problem - it will fire as long as you are holding the key. OnPlayerKeyStateChange is called every time a key changes and that code is true whenever the the fire key is held down. If you press fire the code will fire, if that key is held and you press crouch - that code will fire again because a key (crouch) has changed and fire is still held down How do you detect when a key is first pressed, but not trigger again when it's still held and another key changes?
PRESSED basically equals:

Код:
if ((newkeys & NEW_KEY) && !(oldkeys & OLD_KEY))
Which is more accurate than the example you just gave.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)