Close to object
#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


Messages In This Thread
Close to object - by BoU3A - 06.09.2013, 15:42
Re : Close to object - by Matnix - 06.09.2013, 15:46
Re: Close to object - by Pottus - 06.09.2013, 15:47
Re: Close to object - by BoU3A - 06.09.2013, 16:01
Re: Close to object - by Pottus - 06.09.2013, 16:32
Re: Close to object - by BoU3A - 06.09.2013, 17:36

Forum Jump:


Users browsing this thread: 1 Guest(s)