Close to object
#1

how to make if player Close to this object.




get message like this


Reply
#2

WIKI SAMP.

pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5.0, XObjectPOS, YObjectPOS, ZObjectPOS))
{
    // TEXTDRAW
}
Reply
#3

I would use dynamic areas it's probably the best way to do it.

@Matnix IsPlayerInRangeOfPoint() is a really bad choice you would have to keep updating every second to see if the player is actually near a sprunk machine.

https://sampforum.blast.hk/showthread.php?tid=102865
Reply
#4

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
I would use dynamic areas it's probably the best way to do it.

@Matnix IsPlayerInRangeOfPoint() is a really bad choice you would have to keep updating every second to see if the player is actually near a sprunk machine.

https://sampforum.blast.hk/showthread.php?tid=102865
thanks i have that Plugin but what should i do
Reply
#5

Try something like this.

Note: You will need YSI specifically y_hooks


pawn Код:
#include <YSI\y_hooks>

new MAX_VENDING 100

forward OnPlayerNearVending(playerid);

new VendingMachines[MAX_VENDING] = { -1, ... };

hook OnGameModeInit()
{
    // AddVending(Float:x, Float:y, Float:z, Float:size);
    return 1;
}

stock AddVending(Float:x, Float:y, Float:z, Float:size)
{
    for(new i = 0; i < MAX_VENDING; i++)
    {
        if(VendingMachines[i] != -1) continue;
        VendingMachines[i] = CreateDynamicSphere(x, y, z, size);
        return VendingMachines[i];
    }
    return -1;
}

hook OnPlayerEnterDynamicArea(playerid, areaid)
{
    for(new i = 0; i < MAX_VENDING; i++)
    {
        if(VendingMachines[i] == -1) continue;
        if(VendingMachines[i] == areaid)
        {
            CallLocalFunction("OnPlayerNearVending", "i", playerid);
            return 1;
        }
    }
    return 1;
}
So let me explain how it works:

- when you add a new vending machine it will create the dynamic area
- entering the dynamic area will loop through the vending machine list to see if the player is in a vending machine area
- when an area is found CallLocalFunction will call OnPlayerNearVending() this should be put where you want it in your script do whatever you want to do in here

Advantages of this system:

- No need to keep checking if a player is near a vending machine (let the streamer do the work!)
- When a player does enter a dynamic area the loop check is very simple no need for IsPlayerInRangeOfPoint()

Disadvantages:

- Streamer might be delayed when updating
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Try something like this.

Note: You will need YSI specifically y_hooks


pawn Код:
#include <YSI\y_hooks>

new MAX_VENDING 100

forward OnPlayerNearVending(playerid);

new VendingMachines[MAX_VENDING] = { -1, ... };

hook OnGameModeInit()
{
    // AddVending(Float:x, Float:y, Float:z, Float:size);
    return 1;
}

stock AddVending(Float:x, Float:y, Float:z, Float:size)
{
    for(new i = 0; i < MAX_VENDING; i++)
    {
        if(VendingMachines[i] != -1) continue;
        VendingMachines[i] = CreateDynamicSphere(x, y, z, size);
        return VendingMachines[i];
    }
    return -1;
}

hook OnPlayerEnterDynamicArea(playerid, areaid)
{
    for(new i = 0; i < MAX_VENDING; i++)
    {
        if(VendingMachines[i] == -1) continue;
        if(VendingMachines[i] == areaid)
        {
            CallLocalFunction("OnPlayerNearVending", "i", playerid);
            return 1;
        }
    }
    return 1;
}
So let me explain how it works:

- when you add a new vending machine it will create the dynamic area
- entering the dynamic area will loop through the vending machine list to see if the player is in a vending machine area
- when an area is found CallLocalFunction will call OnPlayerNearVending() this should be put where you want it in your script do whatever you want to do in here

Advantages of this system:

- No need to keep checking if a player is near a vending machine (let the streamer do the work!)
- When a player does enter a dynamic area the loop check is very simple no need for IsPlayerInRangeOfPoint()

Disadvantages:

- Streamer might be delayed when updating
i just do ur code in my gamemode for got that message ?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)