Spawn somewhere near
#1

Hi,

I have area where i don't want player to came. I check every 1 sec is player in that area and i want to set him pos near that area but of course he couldn't go there i don't want use setplayerworldboundries
Reply
#2

So you already have a timer that checks if a player is in an area? Well if he is in that area, use SetPlayerPos to put him somewhere else.
Or is your question that you want to put him to the closest edge of the area?
Reply
#3

Yes but how to put him somewhere else? i don't want closest edge, i want to spawn out from area but near
Reply
#4

First of all, checking every 1 second is very bad.
The best option to create a restricted area is to use Incognito's streamer.

Use the area functions, and then use this callback:
Код:
public OnPlayerEnterDynamicArea(playerid, areaid)
I can't answer your question because I don't understand what you want.
Do you mean you want to spawn the player somewhere near when the player enters the area? Or do you mean something else?
Reply
#5

Do you have he coordinates where you want to spawn the player? Just use SetPlayerPos.
Reply
#6

PHP код:
SetPlayerPos(playeridareax+10areax+10z); 
Reply
#7

Yes , i use now onplayerenterdynamicarea, i know all area 4 corners i have them in variables. I don't know what you don't understand

Reply
#8

You could do something like this:
Код:
const
    Float: AreaTeleports[][] = 
    {
        {X, Y, Z, A},
        {X, Y, Z, A}
        //...
    };

public OnPlayerEnterDynamicArea(playerid, areaid)
{
    if (areaid == area_id)
    {
        new Float: last = 10000.0, Float: current, teleid;
        for (new i = 0; i < sizeof (AreaTeleports); i++)
        {
            current = GetPlayerDistanceFromPoint(playerid, AreaTeleports[i][0], AreaTeleports[i][1], AreaTeleports[i][2]);
            if (current < last)
            {
                last = current;
                teleid = i;
            }
        }
        SetPlayerPos(playerid, AreaTeleports[teleid][0], AreaTeleports[teleid][1], AreaTeleports[teleid][2]);
        SetPlayerFacingAngle(playerid, AreaTeleports[teleid][3]);
    }
    return 1;
}
Reply
#9

Yes i know but i want smth smarter calculations, maths that i don't need for everyarea write positions.. + maybe something like i could write what distance from that area player could by teleported
Reply
#10

I didn't that test that but it should return a random position outside of the rectangle
PHP код:
GetPosOutsideRectangle(Floatx1Floaty1Floatx2Floaty2Floatdistance, & Floatx, & Floaty) {
    new
        
Floatmid_x = (x1 x2) / 2.0,
        
Floatmid_y = (y1 y2) / 2.0,
        
Floatoffset_x floatabs(x1 mid_x),
        
Floatoffset_y floatabs(y1 mid_x),
        
Floatrand = (random(2001) - 1000) / 1000.0;
    switch(
random(4)) {
        case 
0// north
            
min_x offset_x rand,
            
min_y offset_y distance;
        case 
1// east
            
min_x offset_x distance,
            
min_y offset_y rand;
        case 
2// south
            
min_x offset_x rand,
            
min_y offset_y distance;
        case 
3// west
            
min_x offset_x distance,
            
min_y offset_y rand;
    }

PHP код:
public OnPlayerEnterDynamicArea(playeridareaid)
{
    if (
areaid == area_id)
    {
        new 
FloatxFloaty;
        
GetPosOutsideRectangle(Area_X1Area_Y1Area_X2Area_Y225.0xy);
        
SetPlayerPosFindZ(playeridxy1000.0);
    }
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)