GangZone Wars HELP!
#1

I did the script with a guide: https://sampforum.blast.hk/showthread.php?tid=276352
Please help me with the script.

Код:
#include <a_samp>

#define TEAM_GROVE 1
#define TEAM_BALLAS 2
#define TEAM_VAGOS 3

#define TAKEOVER_TIME 120 // how many seconds needed to take over the zone
#define MIN_MEMBERS_TO_START_WAR 3 // how many team members needed in a zone to start a war
#define MIN_DEATHS_TO_START_WAR 3 // how many team members must be killed in a zone to start a war

enum eZone
{
	Float:zMinX,
	Float:zMinY,
	Float:zMaxX,
	Float:zMaxY,
	zTeam
}
new ZoneInfo[][eZone] = {
	{2337.9004,-1808.8383,2590.2043,-1610.3673,TEAM_GROVE},
	{2084.7,-1808.8383,2337.9004,-1610.3673,TEAM_BALLAS},
	{2590.2043,-1808.8383,2842.3,-1610.3673,TEAM_VAGOS}
};
new ZoneID[sizeof(ZoneInfo)];

new ZoneAttacker[sizeof(ZoneInfo)] = {-1, ...};
new ZoneAttackTime[sizeof(ZoneInfo)];
new ZoneDeaths[sizeof(ZoneInfo)];

new Teams[] = {
	TEAM_GROVE,
	TEAM_BALLAS,
	TEAM_VAGOS
};

main()
{

}

public OnGameModeInit()
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
	{
	ZoneID[i] = GangZoneCreate(ZoneInfo[i][zMinX], ZoneInfo[i][zMinY], ZoneInfo[i][zMaxX], ZoneInfo[i][zMaxY]);
	}
	SetTimer("ZoneTimer", 1000, true);
	return 1;
}

public OnPlayerSpawn(playerid)
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
	{
		GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
	}
	for(new i=0; i < sizeof(ZoneInfo); i++)
	{
		GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
		if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam[killerid]) // not a suicide or team kill
	{
	new zoneid = GetPlayerZone(playerid);
	if(zoneid != -1 && ZoneInfo[zoneid][zTeam] == GetPlayerTeam(playerid)) // zone member has been killed in the zone
	{
		ZoneDeaths[zoneid]++;
		if(ZoneDeaths[zoneid] == MIN_DEATHS_TO_START_WAR)
		{
			ZoneDeaths[zoneid] = 0;
			ZoneAttacker[zoneid] = GetPlayerTeam(killerid);
			ZoneAttackTime[zoneid] = 0;
			GangZoneFlashForAll(ZoneID[zoneid], GetTeamZoneColor(ZoneAttacker[zoneid]));
		}
	}
}

public ZoneTimer()
{
	for(new i=0; i < sizeof(ZoneInfo); i++) // loop all zones
	{
		if(ZoneAttacker[i] != -1) // zone is being attacked
		{
			if(GetPlayersInZone(i, ZoneAttacker[i]) >= MIN_MEMBERS_TO_START_WAR) // team has enough members in the zone
			{
				ZoneAttackTime[i]++;
				if(ZoneAttackTime[i] == TAKEOVER_TIME) // zone has been under attack for enough time and attackers take over the zone
				{
					GangZoneStopFlashForAll(ZoneID[i]);
					ZoneInfo[i][zTeam] = ZoneAttacker[i];
					GangZoneShowForAll(ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam])); // update the zone color for new team
					ZoneAttacker[i] = -1;
				}
			}
			else // attackers failed to take over the zone
			{
				GangZoneStopFlashForAll(ZoneID[i]);
				ZoneAttacker[i] = -1;
			}
		}
		else // check if somebody is attacking
		{
			for(new t=0; t < sizeof(Teams); t++) // loop all teams
			{
				if(Teams[t] != ZoneInfo[i][zTeam] && GetPlayersInZone(i, Teams[t]) >= MIN_MEMBERS_TO_START_WAR) // if there are enough enemies in the zone
				{
					ZoneAttacker[i] = Teams[t];
					ZoneAttackTime[i] = 0;
					GangZoneFlashForAll(ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
				}
			}
		}
	}
}

stock GetTeamZoneColor(teamid)
{
	switch(teamid)
	{
		case TEAM_GROVE: return 0x00FF0088;
		case TEAM_BALLAS: return 0xFF00FF88;
		case TEAM_VAGOS: return 0xFFFF0088;
	}
	return -1;
}

stock IsPlayerInZone(playerid, zoneid)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	return (x > ZoneInfo[zoneid][zMinX] && x < ZoneInfo[zoneid][zMaxX] && y > ZoneInfo[zoneid][zMinY] && y < ZoneInfo[zoneid][zMaxY]);
}

stock GetPlayersInZone(zoneid, teamid)
{
	new count;
	for(new i=0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid && IsPlayerInZone(i, zoneid))
	    {
			count++;
	    }
	}
	return count;
}

stock GetPlayerZone(playerid)
{
	for(new i=0; i < sizeof(ZoneInfo); i++)
	{
		if(IsPlayerInZone(playerid, i))
		{
			return i;
		}
	}
	return -1;
}
Errors.
Код:
TeamDM.pwn(55) : error 017: undefined symbol "GetTeamZoneColor"
TeamDM.pwn(59) : error 017: undefined symbol "GetTeamZoneColor"
TeamDM.pwn(60) : error 017: undefined symbol "GetTeamZoneColor"
TeamDM.pwn(67) : error 017: undefined symbol "gTeam"
TeamDM.pwn(67) : warning 215: expression has no effect
TeamDM.pwn(67) : error 001: expected token: ";", but found "]"
TeamDM.pwn(67) : error 029: invalid expression, assumed zero
TeamDM.pwn(67) : fatal error 107: too many error messages on one line
Reply
#2

Error 55, 59, 60. Incorrectly indented code... your missing a bracket in other words. More precisely a closing bracket } put one on line 81 or just copy this. I highly recommend keeping good tabs on your indentation as if this was a 80k line mode you'd have no chance of finding that without Zeexs brace checking thing or skill.

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam[killerid]) // not a suicide or team kill
    {
        new zoneid = GetPlayerZone(playerid);
        if(zoneid != -1 && ZoneInfo[zoneid][zTeam] == GetPlayerTeam(playerid)) // zone member has been killed in the zone
        {
            ZoneDeaths[zoneid]++;
            if(ZoneDeaths[zoneid] == MIN_DEATHS_TO_START_WAR)
            {
                ZoneDeaths[zoneid] = 0;
                ZoneAttacker[zoneid] = GetPlayerTeam(killerid);
                ZoneAttackTime[zoneid] = 0;
                GangZoneFlashForAll(ZoneID[zoneid], GetTeamZoneColor(ZoneAttacker[zoneid]));
            }
        }
    }
}
Error 67: This genuinely isn't defined adding the definition:
pawn Код:
new gTeam[MAX_PLAYERS];
fixes this.

Fixing these creates 2 more errors:
pawn Код:
G:\samp037_svr_R2-1-1_win32\pawno\Untitled.pwn(85) : warning 235: public function lacks forward declaration (symbol "ZoneTimer")
G:\samp037_svr_R2-1-1_win32\pawno\Untitled.pwn(164) : error 010: invalid function or declaration
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Well ones a warning and it's better resolved than not:
Warning 85: Just add the forward declaration:
pawn Код:
forward ZoneTimer();
Now the error: you had an = sign after a bracket... or maybe I made this I'm not sure. If you want to make your changes it will help you learn hence listing them above. If you don't want to see they which I highly recommend you see and fix them yourself, heres the code below: (the main reason for posting this is encase you lose your progress and look back here for it).

pawn Код:
#include <a_samp>

#define TEAM_GROVE 1
#define TEAM_BALLAS 2
#define TEAM_VAGOS 3

#define TAKEOVER_TIME 120 // how many seconds needed to take over the zone
#define MIN_MEMBERS_TO_START_WAR 3 // how many team members needed in a zone to start a war
#define MIN_DEATHS_TO_START_WAR 3 // how many team members must be killed in a zone to start a war

enum eZone
{
    Float:zMinX,
    Float:zMinY,
    Float:zMaxX,
    Float:zMaxY,
    zTeam
}
new ZoneInfo[][eZone] = {
    {2337.9004,-1808.8383,2590.2043,-1610.3673,TEAM_GROVE},
    {2084.7,-1808.8383,2337.9004,-1610.3673,TEAM_BALLAS},
    {2590.2043,-1808.8383,2842.3,-1610.3673,TEAM_VAGOS}
};
new ZoneID[sizeof(ZoneInfo)];

new ZoneAttacker[sizeof(ZoneInfo)] = {-1, ...};
new ZoneAttackTime[sizeof(ZoneInfo)];
new ZoneDeaths[sizeof(ZoneInfo)];
new gTeam[MAX_PLAYERS];

new Teams[] = {
    TEAM_GROVE,
    TEAM_BALLAS,
    TEAM_VAGOS
};

main()
{

}

public OnGameModeInit()
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
    ZoneID[i] = GangZoneCreate(ZoneInfo[i][zMinX], ZoneInfo[i][zMinY], ZoneInfo[i][zMaxX], ZoneInfo[i][zMaxY]);
    }
    SetTimer("ZoneTimer", 1000, true);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
    }
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        GangZoneShowForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam]));
        if(ZoneAttacker[i] != -1) GangZoneFlashForPlayer(playerid, ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && gTeam[playerid] != gTeam[killerid]) // not a suicide or team kill
    {
        new zoneid = GetPlayerZone(playerid);
        if(zoneid != -1 && ZoneInfo[zoneid][zTeam] == GetPlayerTeam(playerid)) // zone member has been killed in the zone
        {
            ZoneDeaths[zoneid]++;
            if(ZoneDeaths[zoneid] == MIN_DEATHS_TO_START_WAR)
            {
                ZoneDeaths[zoneid] = 0;
                ZoneAttacker[zoneid] = GetPlayerTeam(killerid);
                ZoneAttackTime[zoneid] = 0;
                GangZoneFlashForAll(ZoneID[zoneid], GetTeamZoneColor(ZoneAttacker[zoneid]));
            }
        }
    }
}

forward ZoneTimer();
public ZoneTimer()
{
    for(new i=0; i < sizeof(ZoneInfo); i++) // loop all zones
    {
        if(ZoneAttacker[i] != -1) // zone is being attacked
        {
            if(GetPlayersInZone(i, ZoneAttacker[i]) >= MIN_MEMBERS_TO_START_WAR) // team has enough members in the zone
            {
                ZoneAttackTime[i]++;
                if(ZoneAttackTime[i] == TAKEOVER_TIME) // zone has been under attack for enough time and attackers take over the zone
                {
                    GangZoneStopFlashForAll(ZoneID[i]);
                    ZoneInfo[i][zTeam] = ZoneAttacker[i];
                    GangZoneShowForAll(ZoneID[i], GetTeamZoneColor(ZoneInfo[i][zTeam])); // update the zone color for new team
                    ZoneAttacker[i] = -1;
                }
            }
            else // attackers failed to take over the zone
            {
                GangZoneStopFlashForAll(ZoneID[i]);
                ZoneAttacker[i] = -1;
            }
        }
        else // check if somebody is attacking
        {
            for(new t=0; t < sizeof(Teams); t++) // loop all teams
            {
                if(Teams[t] != ZoneInfo[i][zTeam] && GetPlayersInZone(i, Teams[t]) >= MIN_MEMBERS_TO_START_WAR) // if there are enough enemies in the zone
                {
                    ZoneAttacker[i] = Teams[t];
                    ZoneAttackTime[i] = 0;
                    GangZoneFlashForAll(ZoneID[i], GetTeamZoneColor(ZoneAttacker[i]));
                }
            }
        }
    }
}

stock GetTeamZoneColor(teamid)
{
    switch(teamid)
    {
        case TEAM_GROVE: return 0x00FF0088;
        case TEAM_BALLAS: return 0xFF00FF88;
        case TEAM_VAGOS: return 0xFFFF0088;
    }
    return -1;
}

stock IsPlayerInZone(playerid, zoneid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    return (x > ZoneInfo[zoneid][zMinX] && x < ZoneInfo[zoneid][zMaxX] && y > ZoneInfo[zoneid][zMinY] && y < ZoneInfo[zoneid][zMaxY]);
}

stock GetPlayersInZone(zoneid, teamid)
{
    new count;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && GetPlayerTeam(i) == teamid && IsPlayerInZone(i, zoneid))
        {
            count++;
        }
    }
    return count;
}

stock GetPlayerZone(playerid)
{
    for(new i=0; i < sizeof(ZoneInfo); i++)
    {
        if(IsPlayerInZone(playerid, i))
        {
            return i;
        }
    }
    return -1;
}
Aside from that this code is pretty well made, its not bad and your going in the right direction towards being a good programmer even I could make these errors still today. So not an issue really aslong as you learn to identify them.

P.S: In order to copy this with the indentation already done... Press quote and copy the code from there. This will SAVE the TAB indentations whereas copying direct from page wont!.
Reply
#3

Thank You!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)