06.09.2013, 15:42
how to make if player Close to this object.
get message like this
get message like this
if(IsPlayerInRangeOfPoint(playerid, 5.0, XObjectPOS, YObjectPOS, ZObjectPOS))
{
// TEXTDRAW
}
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 |
#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;
}
Try something like this.
Note: You will need YSI specifically y_hooks pawn Код:
- 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 |