Spawn somewhere near -
MerryDeer - 22.07.2016
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
Re: Spawn somewhere near -
Freaksken - 22.07.2016
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?
Re: Spawn somewhere near -
MerryDeer - 22.07.2016
Yes but how to put him somewhere else? i don't want closest edge, i want to spawn out from area but near
Re: Spawn somewhere near -
Stinged - 22.07.2016
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?
Re: Spawn somewhere near -
Freaksken - 22.07.2016
Do you have he coordinates where you want to spawn the player? Just use
SetPlayerPos.
Re: Spawn somewhere near -
UltraScripter - 22.07.2016
PHP код:
SetPlayerPos(playerid, areax+10, areax+10, z);
Re: Spawn somewhere near -
MerryDeer - 22.07.2016
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
Re: Spawn somewhere near -
Stinged - 22.07.2016
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;
}
Re: Spawn somewhere near -
MerryDeer - 22.07.2016
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
Re: Spawn somewhere near -
Nero_3D - 22.07.2016
I didn't that test that but it should return a random position outside of the rectangle
PHP код:
GetPosOutsideRectangle(Float: x1, Float: y1, Float: x2, Float: y2, Float: distance, & Float: x, & Float: y) {
new
Float: mid_x = (x1 + x2) / 2.0,
Float: mid_y = (y1 + y2) / 2.0,
Float: offset_x = floatabs(x1 - mid_x),
Float: offset_y = floatabs(y1 - mid_x),
Float: rand = (random(2001) - 1000) / 1000.0;
switch(random(4)) {
case 0: // north
x = min_x + offset_x * rand,
y = min_y + offset_y + distance;
case 1: // east
x = min_x + offset_x + distance,
y = min_y + offset_y * rand;
case 2: // south
x = min_x - offset_x * rand,
y = min_y - offset_y - distance;
case 3: // west
x = min_x - offset_x - distance,
y = min_y - offset_y * rand;
}
}
PHP код:
public OnPlayerEnterDynamicArea(playerid, areaid)
{
if (areaid == area_id)
{
new Float: x, Float: y;
GetPosOutsideRectangle(Area_X1, Area_Y1, Area_X2, Area_Y2, 25.0, x, y);
SetPlayerPosFindZ(playerid, x, y, 1000.0);
}
return 1;
}