[Include] Polygonal Boundaries
#1

Description
This include allows you to create polygonal boundaries on your server. They work just like the default boundaries (which are set with SetPlayerWorldBounds), but their shape can be an arbitrary polygon. It can be pretty useful to make custom restricted maps.

How to use
You should follow these simple steps to start using the polygonal boundaries:
  1. Include the file to your gamemode/filterscript;
  2. Open the include and change two macroconstants located at the third and the fourth line:
    • B_MAXLENGTH is the maximum number of vertices in your polygonal boundaries;
    • B_NUMBER is the maximum amount of different polygonal boundaries which can be used in your script;
  3. Call InitBoundaries() in the OnFilterScriptInit/OrGameModeInit callback:
    Код:
    public OnFilterScriptInit() {
    	InitBoundaries();
    	...
    }
  4. Call ProcessBoundaries(playerid) in the OnPlayerUpdate(playerid) callback:
    Код:
    public OnPlayerUpdate(playerid) {
    	ProcessBoundaries(playerid);
    	...
    }
  5. Create your boundaries using CreateBoundaries(Float: array[], points).
    The first argument, array, is an array of vertices of your polygon. It should be filled according to the following format: { x1, y1, x2, y2, ..., xn, yn }.
    The second argument, points, is the number of the vertices (n).
    The function returns the ID of the polygonal boundaries which should be used later with the AssignBoundaries function or B_NONE if you tried to create more than B_NUMBER boundaries.
    Example. Say, you want to make El Quebrados the only accessible location and you saved the coordinates of the vertices (image).

    So, CreateBoundaries should be called this way:
    Код:
    new Float: ElQuebradosBoundaries[12] = { -1550.0, 2672.0, -1549.0, 2551.0, -1496.0, 2549.0, -1490.0, 2595.0, -1416.0, 2597.0, -1420.0, 2669.0 };
    new ElQuebradosBoundariesID = CreateBoundaries(ElQuebradosBoundaries, 12);
    (those coordinates are rough, please, don't use them in your scripts )
  6. Set the boundaries for players with AssignBoundaries(playerid, boundaries_id). playerid is the ID of a player, boundaries_id is the value returned by CreateBoundaries. To set a player free from the boundaries, use RemoveBoundaries(playerid).
Notes
  • Keep it mind that the boundaries work in all the interiors and virtual worlds
  • The bugs which can be used to bypass the default boundaries, do not work with these ones
  • Hasn't been properly tested with self-intersecting or too small polygons
  • The planes do not normally stall after hitting the boundaries, but are reflected without losing momentum with the same angle they hit the boundaries (which can lead to stalling in some cases, though)
Afterword
All credits go to yours truly Altus, as known as Altus_Demens. I will be glad if someone finds this code useful.

Source code
Download
Reply
#2

******, thank you!
You are right, it is my mistake. I use the polygonal boundaries as a separate filterscript, but I decided to assemble it as an include to post it here. Corrected.
Reply
#3

Why not hook OnPlayerUpdate?

https://sampforum.blast.hk/showthread.php?tid=574534
Reply
#4

How about adding streamer support? Then you don't need timers.
Reply
#5

Quote:
Originally Posted by Pottus
Посмотреть сообщение
How about adding streamer support? Then you don't need timers.
Streamer already have "CreateDynamicPolygon", so what would be left for him to do, all his include will be, showing and hiding textdraw under streamer's OnPlayerEnter/LeaveDynamicArea callback.
Reply
#6

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Streamer already have "CreateDynamicPolygon", so what would be left for him to do, all his include will be, showing and hiding textdraw under streamer's OnPlayerEnter/LeaveDynamicArea callback.
Pretty much, unless you don't want to use the streamer but who these days does not the streamer? It's pretty standard.
Reply
#7

Thanks dude, awesome.

EPS value?



Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)