SA-MP Forums Archive
[Include] Polygonal Boundaries - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Polygonal Boundaries (/showthread.php?tid=661654)



Polygonal Boundaries - Altus - 10.12.2018

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 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


Re: Polygonal Boundaries - Altus - 10.12.2018

******, 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.


Re: Polygonal Boundaries - Gammix - 10.12.2018

Why not hook OnPlayerUpdate?

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


Re: Polygonal Boundaries - Pottus - 10.12.2018

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


Re: Polygonal Boundaries - Gammix - 10.12.2018

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.


Re: Polygonal Boundaries - Pottus - 10.12.2018

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.


Re: Polygonal Boundaries - Dudoso - 11.12.2018

Thanks dude, awesome.

EPS value?