Land System
#9

You can't create a GangZone using only X, Y, Z.I did a little script to give you an idea of how to do it.
I'm sorry if there are a few mistakes, kinda wrote it in a hurry.
PHP код:
#define MAX_LANDS 100 //Maximum number of lands
#define INVALID_LAND_ID -1

new playerLand[MAX_PLAYERS]; //Stores the land id of the player


enum lInfo
{
    
Float:lID//Used to store the result of GangZoneCreate
    
Float:lMinX//Needed for gangZone
    
Float:lMinY//Needed for gangZone
    
Float:lMaxX//Needed for gangZone
    
Float:lMaxY//Needed for gangZone
    
lOwner[MAX_PLAYER_NAME], //Owner's name
    
lOwned//Set it to 0 it none owns it, or 1 if someone does
    
lCreated //Set it to 1 if the land exists, or 0 if it doesn't
};
new 
landInfo[MAX_LANDS][sizeof(lInfo)];

public 
OnPlayerConnect(playerid)
{
    
playerLand[playerid] = INVALID_LAND_ID;
    return 
1;
}

stock getFreeLandID()
{
    for(
int i 0MAX_LANDSi++)
        if(!
landInfo[i][lCreated])
            return 
i;
    return 
INVALID_LAND_ID;
}

/*
You will need minX, minY, maxX, maxY coords to create a gangzone.A gangzone doesn't care about Z.
*/
stock createLand(playeridFloat:minXFloat:minYFloat:maxXFloat:maxY//Function used by admins to create the land
{
    new 
landID getFeeLandID(); //Store a free land ID
    
if(landID != INVALID_LAND_ID)
    {
        
landInfo[landID][lMinX] = minX;
        
landInfo[landID][lMinY] = minY;
        
landInfo[landID][lMaxX] = maxX;
        
landInfo[landID][lMaxY] = maxY;
        
strcpy(landInfo[landID][lOwner], "No-one");
        
landInfo[landID][lOwned] = 0;
        
landInfo[landID][lCreated] = 1;
        
landInfo[landID][lID] = GangZoneCreate(minXminYmaxXmaxY); //Same as: GangZoneCreate(landInfo[landID][lMinX], landInfo[landID][lMinY], landInfo[landID][lMaxX] = maxX, landInfo[landID][lMaxY] = maxY);
        
GangZoneShowForAll(landInfo[landID][lID], 0xFFFFFF93); //0xFFFFFF93 can be replaced with any color.
        //Send message that a land has been created
    
}
    else
        
SendClientMessage(playerid0xFFFFFFFF"All the land zones are used.");
}

//returns the landID a specific player is inside of or INALID_LAND_ID if the player isn't inside any land
stock getPlayerLandID(playerid)
{
    for(
int i 0MAX_LANDSi++)
        if(
landInfo[i][lCreated])
            if(
IsPlayerInArea(playeridlandInfo[i][lMinX], landInfo[i][lMinY], landInfo[i][lMaxX], landInfo[i][lMaxY]))
                return 
i;
    return 
INVALID_LAND_ID;
}

stock isPlayerInOwnLand(playerid)
{
    if(
playerLand[playerid] != INVALID_LAND_ID//Checks if the player owns any land
    
{
        new 
landID playerLand[playerid]; //Store the land ID
        
if(landInfo[landID][lCreated]) //Checks to see if the land exists
            
if(IsPlayerInArea(playeridlandInfo[landID][lMinX], landInfo[landID][lMinY], landInfo[landID][lMaxX], landInfo[landID][lMaxY])) //Check to see if player is in his own land
                
return 1;
    }
    return 
0;
}

stock onLandBought(playeridlandID)
{
    new 
playerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridplayerNamesizeof(playerName));
    
//
    
playerLand[playerid] = landID;
    
//Update the land info
    
landInfo[landID][lOwned] = 1;
    
strcpy(landInfo[landID][lOwner], playerName);
}

CMD:buyland(playeridparams[])
{
    new 
landID getPlayerLandID(playerid);
    if(
landID != INVALID_LAND_ID)
    {
        
//Your code
        
onLandBought(playeridlandID);
    }
    else
        
SendClientMessage(playerid0xFFFFFFFF"Message to let him know he's not in any zone.");
    return 
1;
}

//Cmd for admins
CMD:createland(playeridparams[])
{
    if(
IsPlayerAdmin(playerid))
    {
        new 
Float:minXFloat:minYFloat:maxXFloat:maxY;
        if(
sscanf(params"ffff"minXminYmaxXmaxY))
            return 
SCM(playerid0xFFFFFFFF"/createland [minX] [minY] [maxX] [maxY]");
        
createLand(playeridminXminYmaxXmaxY;
        return 
1;
    }
    return 
0;
}


//Useful functions
stock strcpy(dest[], const source[], maxlength=sizeof dest)
{
    
strcat((dest[0] = EOSdest), sourcemaxlength);
}

/*
We'll use this function to see if playerid is inside a land
*/
public IsPlayerInArea(playeridFloat:minx2Float:miny2Float:maxx2Float:maxy2)
{
    new 
Float:xaFloat:yaFloat:za;
    
GetPlayerPos(playeridxayaza);
    if (
xa minx2 && xa maxx2 && ya miny2 && ya maxy2) return 1;
    return 
0;

Reply


Messages In This Thread
Land System - by JasonRiggs - 20.07.2016, 21:24
Re: Land System - by Codeah - 20.07.2016, 22:16
Re: Land System - by JasonRiggs - 19.05.2017, 00:53
Re: Land System - by rockhopper - 19.05.2017, 13:07
Re: Land System - by JasonRiggs - 19.05.2017, 14:31
Re: Land System - by GTLS - 19.05.2017, 16:35
Re: Land System - by JasonRiggs - 19.05.2017, 16:46
Re: Land System - by JasonRiggs - 19.05.2017, 16:48
Re: Land System - by Aly - 19.05.2017, 17:29
Re: Land System - by JasonRiggs - 19.05.2017, 18:08

Forum Jump:


Users browsing this thread: 1 Guest(s)