10.12.2018, 06:49
(
Последний раз редактировалось Altus; 10.12.2018 в 16:44.
)
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:
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
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:
- Include the file to your gamemode/filterscript;
- 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;
- Call InitBoundaries() in the OnFilterScriptInit/OrGameModeInit callback:
Код:public OnFilterScriptInit() { InitBoundaries(); ... }
- Call ProcessBoundaries(playerid) in the OnPlayerUpdate(playerid) callback:
Код:public OnPlayerUpdate(playerid) { ProcessBoundaries(playerid); ... }
- 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);
- 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).
- 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)
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