13.10.2013, 11:33
(
Последний раз редактировалось Pravin; 13.10.2013 в 12:38.
Причина: Added my codes
)
Well, i used to write the co-ords of a capture zone in an enum and load co-ords from it for capture zone.
But there is a bug, once when i go attack a capture zone, all of the zones in the enum gets attacked. :/
Help pls.
My code :
But there is a bug, once when i go attack a capture zone, all of the zones in the enum gets attacked. :/
Help pls.
My code :
pawn Код:
#define AREA51 0
#define DA 1
enum eCPZone
{
Float:CX,
Float:CY,
Float:CZ,
CTeam,
CName,
Float:CMinX,
Float:CMinY,
Float:CMaxX,
Float:CMaxY,
CMapIconNumber
}
new CZoneInfo[][eCPZone] = {
{214.6418,1822.6184,6.4141,NONE,AREA51,-99.609375,1666.015625,466.796875,2140.625, 0}, //first 3 are Capture zone and second 4 gangzone
{405.2332,2453.1125,16.5000,NONE,DA,78.125,2408.203125,501.953125,2634.765625, 1}
};
new CZoneID[sizeof(CZoneInfo)];
/// This one at OnGameModeInIt ///
for(new i=0; i < sizeof(CZoneInfo); i++)
{
CZoneID[CZoneInfo[i][CName]] = CreateDynamicCP(CZoneInfo[i][CX], CZoneInfo[i][CY], CZoneInfo[i][CZ],6.0, -1, -1, -1, 100.0);
tCP[CZoneInfo[i][CName]] = NONE;
Zone[CZoneInfo[i][CName]] = GangZoneCreate(CZoneInfo[i][CMinX], CZoneInfo[i][CMinY], CZoneInfo[i][CMaxX], CZoneInfo[i][CMaxY]);
UnderAttack[CZoneInfo[i][CName]] = 0;
}
////This one at OnPlayerConnect
for(new i=0; i < sizeof(CZoneInfo); i++)
{
SetPlayerMapIcon(playerid, CZoneInfo[i][CMapIconNumber], CZoneInfo[i][CX],CZoneInfo[i][CY],CZoneInfo[i][CZ], 19, MAPICON_GLOBAL);
IsPlayerCapturing[playerid][CZoneInfo[i][CName]] = 0;
CountVar[playerid][CZoneInfo[i][CName]] = 25;
GangZoneShowForAll(Zone[CZoneInfo[i][CName]], 0x00000043);
if(tCP[CZoneInfo[i][CName]] == NONE) GangZoneShowForAll(Zone[CZoneInfo[i][CName]], 0xFFFFFF46);
else if(tCP[CZoneInfo[i][CName]] == TEAM_U) GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_U_COLOR);
else if(tCP[CZoneInfo[i][CName]] == TEAM_R) GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_R_COLOR);
else if(tCP[CZoneInfo[i][CName]] == TEAM_A) GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_A_COLOR);
else if(tCP[CZoneInfo[i][CName]] == TEAM_A1) GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_A1_COLOR);
else if(tCP[CZoneInfo[i][CName]] == TEAM_E) GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_E_COLOR);
}
forward OnPlayerEnterDynamicCP(playerid, checkpointid);
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
for(new i=0; i < sizeof(CZoneInfo); i++)
{
if(checkpointid == CZoneID[CZoneInfo[i][CName]])
{
if(UnderAttack[CZoneInfo[i][CName]] == 0)
{
if(tCP[CZoneInfo[i][CName]] != gTeam[playerid])
{
CountVar[playerid][CZoneInfo[i][CName]] = 25;
ActiveCAPZONE(playerid);
} else return SendClientMessage(playerid, COLOR_RED,"*This zone is already captured by your team!");
} else return CaptureZoneMessage(playerid,2);
}
}
return 1;
}
forward OnPlayerLeaveDynamicCP(playerid, checkpointid);
public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
for(new i=0; i < sizeof(CZoneInfo); i++)
{
if(checkpointid == CZoneID[CZoneInfo[i][CName]] && Captured[playerid][CZoneInfo[i][CName]] == 0 && IsPlayerCapturing[playerid][CZoneInfo[i][CName]] == 1 && !IsPlayerInDynamicCP(playerid, CZoneID[CZoneInfo[i][CName]]))
{
LeavingCAPZONE(playerid);
}
}
}
stock CaptureZoneMessage(playerid, messageid)
{
switch(messageid)
{
case 1:
{
SendClientMessage(playerid, COLOR_RED,"You cannot capture while in a vehicle!");
}
case 2:
{
SendClientMessage(playerid, COLOR_RED,"This zone is already being taken over!");
}
}
return 1;
}
stock ActiveCAPZONE(playerid)
{
for(new i=0; i < sizeof(CZoneInfo); i++)
{
if(UnderAttack[CZoneInfo[i][CName]] == 0)
{
if(!IsPlayerInAnyVehicle(playerid))
{
UnderAttack[CZoneInfo[i][CName]] = 1;
timer[playerid][CZoneInfo[i][CName]] = SetTimerEx("CAPZONETimer", 25000, false,"i",playerid);
Captured[playerid][CZoneInfo[i][CName]] = 0;
SendClientMessage(playerid, 0xFFFFFFFF,"| Stay in this checkpoint for 25 seconds to capture it! |");
if(gTeam[playerid] == TEAM_U)
{
GangZoneFlashForAll(Zone[CZoneInfo[i][CName]], TEAM_U_COLOR);
}
else if(gTeam[playerid] == TEAM_R)
{
GangZoneFlashForAll(Zone[CZoneInfo[i][CName]], TEAM_R_COLOR);
}
else if(gTeam[playerid] == TEAM_A)
{
GangZoneFlashForAll(Zone[CZoneInfo[i][CName]], TEAM_A_COLOR);
}
else if(gTeam[playerid] == TEAM_A1)
{
GangZoneFlashForAll(Zone[CZoneInfo[i][CName]], TEAM_A1_COLOR);
}
else if(gTeam[playerid] == TEAM_E)
{
GangZoneFlashForAll(Zone[CZoneInfo[i][CName]], TEAM_E_COLOR);
}
//------Message-----
if(tCP[CZoneInfo[i][CName]] == TEAM_U)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 1!");
SendClientMessageToAll(-1,"*Capture Zone is under attack!");
}
else if(tCP[CZoneInfo[i][CName]] == TEAM_R)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 2!");
SendClientMessageToAll(-1,"*Capture Zone is under attack!");
}
else if(tCP[CZoneInfo[i][CName]] == TEAM_A)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 2!");
SendClientMessageToAll(-1,"*Capture Zone is under attack!");
}
else if(tCP[CZoneInfo[i][CName]] == TEAM_A1)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 2!");
SendClientMessageToAll(-1,"*Capture Zone is under attack!");
}
else if(tCP[CZoneInfo[i][CName]] == TEAM_E)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is controlled by team 2!");
SendClientMessageToAll(-1,"*Capture Zone is under attack!");
}
else if(tCP[CZoneInfo[i][CName]] == NONE)
{
SendClientMessage(playerid, COLOR_WHITE,"This flag is not controlled by any team!");
}
//---------loop-------//
for(new n = 0; n < MAX_PLAYERS; n ++)
{
IsPlayerCapturing[n][i] = 1;
}
}
else return CaptureZoneMessage(playerid, 1);
}
else return CaptureZoneMessage(playerid, 2);
}
return 1;
}
stock CAPZONECaptured(playerid)
{
for(new i=0; i < sizeof(CZoneInfo); i++)
{
Captured[playerid][CZoneInfo[i][CName]] = 1;
UnderAttack[CZoneInfo[i][CName]] = 0;
KillTimer(timer[playerid][CZoneInfo[i][CName]]);
CountVar[playerid][CZoneInfo[i][CName]] = 25;
GivePlayerScore(playerid, 5);
GivePlayerMoney(playerid, 5000);
SendClientMessage(playerid, COLOR_GREEN,"Congratulations! You have captured the area! You received +5 scores and +$5000 cash!");
//==========================================================================
for(new n = 0; n < MAX_PLAYERS; n++)
{
IsPlayerCapturing[n][i] = 0;
if(gTeam[n] == gTeam[playerid])
{
SendClientMessage(n, 0xFFFFFFFF,"*Your team has captured the area! You received +1 score for it!");
GivePlayerScore(n, 1);
}
}
//==========================================================================
tCP[CZoneInfo[i][CName]] = gTeam[playerid];
GangZoneStopFlashForAll(CZoneInfo[i][CName]);
//==========================================================================
if(gTeam[playerid] == TEAM_U)
{
GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_U_COLOR);
}
else if(gTeam[playerid] == TEAM_R)
{
GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_R_COLOR);
}
else if(gTeam[playerid] == TEAM_A)
{
GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_A_COLOR);
}
else if(gTeam[playerid] == TEAM_A1)
{
GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_A1_COLOR);
}
else if(gTeam[playerid] == TEAM_E)
{
GangZoneShowForAll(Zone[CZoneInfo[i][CName]], TEAM_E_COLOR);
}
//==========================================================================
//==========================================================================
new str[128];
format(str, sizeof(str),"%s has captured the capture zone!", GetName(playerid));
SendClientMessageToAll(COLOR_ORANGE, str);
}
return 1;
}
stock LeavingCAPZONE(playerid)
{
for(new i=0; i < sizeof(CZoneInfo); i++)
{
Captured[playerid][CZoneInfo[i][CName]] = 0;
UnderAttack[CZoneInfo[i][CName]] = 0;
KillTimer(timer[playerid][CZoneInfo[i][CName]]);
CountVar[playerid][CZoneInfo[i][CName]] = 25;
GangZoneStopFlashForAll(Zone[CZoneInfo[i][CName]]);
for(new n = 0; n < MAX_PLAYERS; n++)
{
IsPlayerCapturing[n][i] = 0;
}
SendClientMessage(playerid, COLOR_RED,"*You have failed to capture this zone!");
}
return 1;
}
stock GivePlayerScore(playerid, score) // creating our stock
{
SetPlayerScore(playerid, GetPlayerScore(playerid) + score); // we're defining it as it will SetPlayerScore, since it's not known like GivePlayerMoney, there is just SetPlayerScore for the scores.
return 1;
}
forward CAPZONETimer(playerid);
public CAPZONETimer(playerid)
{
CAPZONECaptured(playerid);
return 1;
}