[Include] zone.inc - Zone management without other includes
#1

Zone management [zone.inc]


Intro
Hi, I state that my English is not very good.
This is the first that includes place on the forum. Initially I designed because I needed it for my GM, but then I decided to bring us some of the changes and publish it here.
This includes very simple, allows you to create and manage zones. Or you can create them using the minimum and maximum coordinates or using a center coordinate and a range.
The area will also be visible on the map thanks to the GangZoneCreate.
In addition to these there are some that allow you to check if a player is in a zone or area in which it is located.
And then there are two callbacks that are called when a player (or NPC) enters or leaves a zone.
Also, when a player is in an area it creates a small text draw on the minimap that shows the name of the area.
I hope this includes you may require. I am open to any criticism, suggestion or even to simple compliments.

Changelog
Code:
Version 1.0 - It includes the release.
Version 1.1 - Inserted: CreateRhombusZone() e CreateTriangleZone();
                  Changed: GetTypeZone() in GetZoneType();
Natives
Code:
native CreateZone(Float:minX, Float:minY, Float:maxX, Float:maxY, color = COLOR_WHITE, name[] = "None", type[] = "None");
native CreateZoneByRange(Float:X, Float:Y, Float:Range = 5.0, color = COLOR_WHITE, name[] = "None", type[] = "Safe");
// NEW
native CreateRhombusZone(Float:X, Float:Y, Float:Range = 50.0, color = COLOR_WHITE, name[] = "None", type[] = "None")
native CreateTriangleZone(Float:X, Float:Y, Float:Range = 50.0, cardinalPoint[] = "North", color = COLOR_WHITE, name[] = "None", type[] = "None")
//
native GetZoneType(zoneid); // Changed
native GetZoneName(zoneid);
// Player functions
native IsPlayerInZone(playerid, zoneid);
native IsPlayerInAnyZone(playerid);
native GetPlayerZone(playerid);

native Zone_OnPlayerConnect(playerid);
CreateZone & CreateZoneByRange
Code:
CreateZone(Float:minX, Float:minY, Float:maxX, Float:maxY, color = COLOR_WHITE, name[] = "None", type[] = "None");

Float:minX - Minimum coordinate X.
Float:minY - Minimum coordinate Y.
Float:maxX - Maximum coordinate X.
Float:maxY - Maximum coordinate Y.
color - The colors already defined are red, green, blue, yellow, white (default), gray and blue.
name[24] - The name of the area. If not set it will be "Zone id".
Type[24] - The type of area. If not set it will be "None".

Will return the id of the area.

CreateZoneByRange(Float:X, Float:Y, Float:Range = 5.0, color = COLOR_WHITE, name[] = "None", type[] = "Safe");

Watch function Create Zone.
Float:Rage - Necessary to calculate the minimum and maximum coordinates. Default is 5.0.
CreateRhombusZone NEW!
Code:
CreateRhombusZone(Float:X, Float:Y, Float:Range = 50.0, color = COLOR_WHITE, name[] = "None", type[] = "None");

Float:X - Coordinate X.
Float:Y - Coordinate Y.
Float:Rage - Necessary to calculate the minimum and maximum coordinates. Default is 5.0.
color - The colors already defined are red, green, blue, yellow, white (default), gray and blue.
name[24] - The name of the area. If not set it will be "Zone id".
Type[24] - The type of area. If not set it will be "None".

Will Returns the number of zones created.
CreateTriangleZone NEW!
Code:
CreateTriangleZone(Float:X, Float:Y, Float:Range = 50.0, cardinalPoint[] = "North", color = COLOR_WHITE, name[] = "None", type[] = "None");

Float:X - Coordinate X.
Float:Y - Coordinate Y.
Float:Rage - Necessary to calculate the minimum and maximum coordinates. Default is 50.0.
cardinalPoint[] - It indicates the direction of the triangle. Default is "North".
color - The colors already defined are red, green, blue, yellow, white (default), gray and blue.
name[24] - The name of the area. If not set it will be "Zone id".
Type[24] - The type of area. If not set it will be "None".

Will Returns the number of zones created.
GetZoneType & GetZoneName

Code:
GetZoneType(zoneid); - Returns the type of the area giving it as input the id.
GetZoneName(zoneid); - Returns the name of the area giving it as input the id.
Functions for player
IsPlayerInZone & IsPlayerInAnyZone & GetPlayerZone

Code:
IsPlayerInZone(playerid, zoneid); - Returns 1 if the player is in that area else 0.
IsPlayerInAnyZone(playerid); - Returns 1 if the player is in any zone else 0.
GetPlayerZone(playerid); - Return the id of the area where the player else 0.
Zone_OnPlayerConnect
Code:
Zone_OnPlayerConnect(playerid); - Added OnPlayerConnect of your GM in case of include OnPlayerConnect cause problems.
Callbacks
Code:
forward OnPlayerEnterZone(playerid, zoneid); - It is prompted when the player enters a zone.
forward OnPlayerExitZone(playerid, zoneid); - It is prompted when the player comes out of a zone.
Examples
Code:
public OnPlayerEnterZone(playerid,zoneid)
{
	if(strcmp(GetTypeZone(zoneid), "Blue")==0)
	{
		GameTextForPlayer(playerid, "~b~You went into a blue zone.", 3000, 3);
	}
	else if(strcmp(GetTypeZone(zoneid), "Red")==0)
	{
	    GameTextForPlayer(playerid, "~r~Warning!~n~~w~You went into a red zone.", 3000, 3);
	}
	else GameTextForPlayer(playerid, "~w~You went into a zone.", 3000, 3);
	return 1;
}

public OnPlayerExitZone(playerid,zoneid)
{
	GameTextForPlayer(playerid, "~w~You are come out of a zone.", 3000, 3);
    return 1;
}
Reply
#2

Quote:
Originally Posted by Gammix
Посмотреть сообщение
pawn Код:
CreateTriangleZone
This cannot be possible with gangzones, you can only create areas not gangzones of such shapes.
Try
Use more gangzone to give that form.
Reply
#3

Quote:
Originally Posted by Frenk96
Посмотреть сообщение
Try
Use more gangzone to give that form.
I claimed that after seeing your code, i guess you have just applied your (or anyone else's) math and posted the code without testing. You would ran out of max zone limit creating such shapes.
Reply
#4

This is a good idea but the implementation method is like this was written in 2007.
Reply
#5

I assure you that is tested. I know that with this method you may easily exceed the limit of gangzone, but for now it's the only idea I had.
(I do not know English very well so I do not know if I understood perfectly what I mean)

Quote:
Originally Posted by Pottus
Посмотреть сообщение
This is a good idea but the implementation method is like this was written in 2007.
I did not know. xD
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)