SA-MP Forums Archive
Distance range of a place - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Distance range of a place (/showthread.php?tid=662942)



Distance range of a place - Volumen - 16.01.2019

How can I do so that when a player is near a black market, a 'textdraws' appears saying to the player: "Black market is a few meters near your position", and when the player moves away from that area the' textdraw 'is hidden.


Re: Distance range of a place - Lokii - 16.01.2019

Use DynamicArea

PHP код:
native STREAMER_TAG_AREA CreateDynamicCircle(Float:xFloat:yFloat:sizeworldid = -1interiorid = -1playerid = -1);
native STREAMER_TAG_AREA CreateDynamicCylinder(Float:xFloat:yFloat:minzFloat:maxzFloat:sizeworldid = -1interiorid = -1playerid = -1);
native STREAMER_TAG_AREA CreateDynamicSphere(Float:xFloat:yFloat:zFloat:sizeworldid = -1interiorid = -1playerid = -1);
native STREAMER_TAG_AREA CreateDynamicRectangle(Float:minxFloat:minyFloat:maxxFloat:maxyworldid = -1interiorid = -1playerid = -1);
native STREAMER_TAG_AREA CreateDynamicCuboid(Float:minxFloat:minyFloat:minzFloat:maxxFloat:maxyFloat:maxzworldid = -1interiorid = -1playerid = -1);
native STREAMER_TAG_AREA CreateDynamicCube(Float:minxFloat:minyFloat:minzFloat:maxxFloat:maxyFloat:maxzworldid = -1interiorid = -1playerid = -1);
native STREAMER_TAG_AREA CreateDynamicPolygon(Float:points[], Float:minz = -FLOAT_INFINITYFloat:maxz FLOAT_INFINITYmaxpoints sizeof pointsworldid = -1interiorid = -1playerid = -1);
native DestroyDynamicArea(STREAMER_TAG_AREA areaid);
native IsValidDynamicArea(STREAMER_TAG_AREA areaid); 



Re: Distance range of a place - Volumen - 16.01.2019

Create an area and then call it in "OnPlayerEnterDynamicArea"?


Re: Distance range of a place - Lokii - 16.01.2019

Quote:
Originally Posted by Volumen
Посмотреть сообщение
Create an area and then call it in "OnPlayerEnterDynamicArea"?
Yes.


Re: Distance range of a place - Volumen - 16.01.2019

It's okay. By the way, and if I want to check the distance between two players as I would (IsPlayerInRangeOfPoint)?

When a player is near a player who is working as a seller of "Hot dog" also show a 'textdraw'. It occurred to me to use "IsPlayerInRangeOfPoint" with a timer to compare the distance of the 2 players, but that would flood messages.


Re: Distance range of a place - Lokii - 16.01.2019

use boolean once you're near one set it to true and check if allready true do nothing if not true show td
then when leaving check if the boolean is true hide td and set it to false

example

PHP код:
new bool:on[MAX_PLAYERS];
CMD:superman(playerid)
{
    if(!
on[playerid])
    {
       
SetPlayerHealth(playerid999999);
       
on[playerid] = true;
    }
    else 
//or if(on[playerid])
    
{
        
SetPlayerHealth(playerid100);
        
on[playerid] = false;
    }
    return 
1;




Re: Distance range of a place - Volumen - 16.01.2019

So, should I start the timer every time the player spawns (OnPlayerSpawn)?


Re: Distance range of a place - Lokii - 16.01.2019

You can do it without timers;

PHP код:
new player_time[MAX_PLAYERS];

public 
OnPlayerUpdate(playerid)
{
    new 
time gettime();
    if(
player_time[playerid] != time)
    {
        
player_time[playerid] = time;
        
//code here
    
}
    return 
1;