SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 10/12/2018, 07:49 AM   #1
Altus
Little Clucker
 
Join Date: Oct 2017
Posts: 5
Reputation: 0
Default Polygonal Boundaries

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:
    Code:
    public OnFilterScriptInit() {
    	InitBoundaries();
    	...
    }
  4. Call ProcessBoundaries(playerid) in the OnPlayerUpdate(playerid) callback:
    Code:
    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:
    Code:
    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

Last edited by Altus; 10/12/2018 at 05:44 PM.
Altus is offline   Reply With Quote
Old 10/12/2018, 09:49 AM   #2
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,504
Reputation: 3206
Default Re: Polygonal Boundaries

The code looks good, but where is ProcessBoundaries called from? And why is it stock? That suppresses any warning that it isn't used when it clearly should be.
Y_Less is offline   Reply With Quote
Old 10/12/2018, 05:46 PM   #3
Altus
Little Clucker
 
Join Date: Oct 2017
Posts: 5
Reputation: 0
Default Re: Polygonal Boundaries

Y_Less, 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.
Altus is offline   Reply With Quote
Old 10/12/2018, 06:00 PM   #4
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,825
Reputation: 833
Default Re: Polygonal Boundaries

Why not hook OnPlayerUpdate?

https://forum.sa-mp.com/showthread.php?t=574534
__________________

My GitHub:

Gammix is offline   Reply With Quote
Old 10/12/2018, 11:02 PM   #5
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,504
Reputation: 3206
Default Re: Polygonal Boundaries

Or use a timer, there's really no need for the update speed of OnPlayerUpdate. If the response time is a few hundred milliseconds out no-one will notice.
Y_Less is offline   Reply With Quote
Old 10/12/2018, 11:28 PM   #6
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,248
Reputation: 1258
Default Re: Polygonal Boundaries

How about adding streamer support? Then you don't need timers.
Pottus is offline   Reply With Quote
Old 10/12/2018, 11:37 PM   #7
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,825
Reputation: 833
Default Re: Polygonal Boundaries

Quote:
Originally Posted by Pottus View Post
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.
__________________

My GitHub:

Gammix is offline   Reply With Quote
Old 10/12/2018, 11:49 PM   #8
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,248
Reputation: 1258
Default Re: Polygonal Boundaries

Quote:
Originally Posted by Gammix View Post
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.
Pottus is offline   Reply With Quote
Old 11/12/2018, 06:20 AM   #9
Dudoso
Little Clucker
 
Join Date: Apr 2010
Posts: 3
Reputation: 0
Cool Re: Polygonal Boundaries

Thanks dude, awesome.

EPS value?



Dudoso is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stay within' Boundaries! CameronThomaz Server Support 3 25/12/2014 06:21 AM
SA-MP map boundaries? Yasahiro General 2 04/06/2013 01:25 AM
[FilterScript] Polygonal area Seregamil1 Filterscripts 2 13/05/2013 11:42 AM
Help with world boundaries LiamM Help Archive 3 30/01/2011 05:25 PM
Boundaries bug Pooh7 Bug Reports 10 20/01/2011 03:21 PM


All times are GMT. The time now is 03:59 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.