Timer not counting
#1

Hello, guys! So, I have an RP gamemode, in russian it's called Engine-RP. I've got the translated version to latvian. The thing is, that the gamemode has Gang system, with zones. And the Mafia system is very similar to it. It is alsmost the same code with different name, except that Mafia system doesn't have zone capture system. It has business, but you can't capture them. What I tried to do, is to allow Mafia's to capture those businesses. I almost suceeded, Mafia's businesses zones do flash upon attack, but the problem is, that the MZSafeTime (MafiaZoneSafeTime) isn't counting, so it never ends. But the Gang system works perfectly well.

Here's my code for the Gang system:
Код:
#define MAX_GZONE 150
new OnZONE[MAX_GZONE][20];
new ZoneOnBattle[MAX_GZONE];
new ZoneTimer[MAX_GZONE];
new allowedfactions[] = { 8, 9, 10, 11, 12, 21};
new GZSafeTime[MAX_GZONE];
enum GzoneInfo
{
    id,
    Float:gCoords[4],
    gFrak,
    gNapad
}
new GZInfo[MAX_GZONE][GzoneInfo];
new FrakCD[20];

stock LoadGZ()
{
    new time = GetTickCount();
    mysql_query("SELECT * FROM `"TABLE_GANGZONE"`");
	mysql_store_result();
	if(mysql_num_rows() > 0)
	{
		for(new idx = 1; idx <= mysql_num_rows(); idx++)
		{
		   	mysql_fetch_row(query);
        	sscanf(query, "p<|>iffffi",
        	GZInfo[idx][id],
			GZInfo[idx][gCoords][0],
			GZInfo[idx][gCoords][1],
			GZInfo[idx][gCoords][2],
			GZInfo[idx][gCoords][3],
			GZInfo[idx][gFrak]);
        	TOTALGZ++;
	        GZInfo[idx][id] = GangZoneCreate(GZInfo[idx][gCoords][0],GZInfo[idx][gCoords][1],GZInfo[idx][gCoords][2],GZInfo[idx][gCoords][3]);
        	ZoneOnBattle[idx] = 0;
        	GZSafeTime[idx] = 0;
        }
    }
    mysql_free_result();
    printf(" [gangzones]: tika ieladeti - %d ļīņљąчеķī %d (ms)", TOTALGZ,GetTickCount() - time);
	return 1;
}

stock GzCheck()
{
	new string[128];
    for(new i =0;i<sizeof(GZInfo);i++)
    {
        if(ZoneOnBattle[i] == 1 && GZSafeTime[i] == 0)
        {
            ZoneTimer[i] -=5;
            new faction;
            new zl;
            zl = i;
            if(ZoneTimer[i] <=0)
            {
                SendFMes(i,COLOR_RED,"[F] Laiks ir beidzies!");
                ZoneOnBattle[i] =0;
                GangZoneStopFlashForAll(GZInfo[i][id]);
                SaveGZ(zl);
            }
            for(new x =0;x<MAX_PLAYERS;x++)
            {
                if(PlayerToKvadrat(x,GZInfo[i][gCoords][0], GZInfo[i][gCoords][1],GZInfo[i][gCoords][2],GZInfo[i][gCoords][3])&&IsInAllowed(x))
                {
                    if(PlayerInfo[x][pLeader] !=0) {faction = PlayerInfo[x][pLeader];}
                    else { faction = PlayerInfo[x][pMember];}
                    OnZONE[i][faction] ++;
                }
            }
            new asd;
            for(new x =0;x<20;x++)
            {
                if(OnZONE[i][x] > 0 && IsInAllowedF(x)) asd ++;
            }
            if(asd == 1)
            {
                for(new x =0;x<20;x++)
                {
                    if(OnZONE[i][x] > 0)
                    {
                        new zx;
                        zx = x;
                        if(GZInfo[i][gFrak] == x) {format(string,90,"[F] %s banda aizstaveja savu territoriju!",GetGangName(zx)); }
                        else
                        {format(string,90,"[F] %s banda vinneja un ieguva jaunu territoriju!",GetGangName(zx)); }
                        for(new ads = 8; ads <= 12;ads++) SendFMes(ads, COLOR_LIGHTRED,string);
                        ZoneOnBattle[zl] =0;
                        GZInfo[zl][gNapad] = 0;
                        GZInfo[zl][gFrak] = zx;
                        GangZoneStopFlashForAll(GZInfo[zl][id]);
                        GangZoneHideForAll(GZInfo[zl][id]);
                        GangZoneShowForAll(GZInfo[zl][id],GetGangZoneColor(zl));
                        SaveGZ(zl);
                        break;
                    }
                }
            }
        }
    }
    for(new i =0;i<120;i++)
    {
        for(new z = 0;z<20;z++)
        {
            OnZONE[i][z] =0;
        }
    }
    return 1;
}

forward SecUpdate();
public SecUpdate()
{
    GzCheck();
    for(new i = 1; i <= TOTALGZ; i++)
    {
        if(GZSafeTime[i] > 0)
        {
            GZSafeTime[i]--;
            if(GZSafeTime[i] == 60 || GZSafeTime[i] == 120)
            {
                format(string,127,"[F] Jums atlikusas %d sekundes lai sagatavotos",GZSafeTime[i]);
                SendFMes(GZInfo[i][gNapad],COLOR_LIGHTRED,string);
                SendFMes(GZInfo[i][gFrak],COLOR_LIGHTRED,string);
            }
            if(GZSafeTime[i] == 0)
            {
                format(string,127,"[F] Sagatavosanas laiks ir beidzies! Kad zona nebus tavas bandas speletaji, ta tiks pretiniekiem!");
                SendFMes(GZInfo[i][gNapad],COLOR_LIGHTRED,string);
                SendFMes(GZInfo[i][gFrak],COLOR_LIGHTRED,string);
            }
        }
    }
    for(new i =0;i<sizeof(FrakCD);i++)
    {
        if(FrakCD[i] >0)
        {
            FrakCD[i] --;
            if(FrakCD[i] == 0) SendFMes(i,COLOR_LIGHTRED,"[F] Tava banda atkal var karot par zonu!");
        }
    }
}

CMD:capture(playerid, params[])
{
	if(PlayerLogged[playerid] == 0) return 1;
	if(IsAGang(playerid))
	{
		if(PlayerInfo[playerid][pRank] < 7) return SendClientMessage(playerid,COLOR_LIGHTRED,"funkcijas pieejama no 7 ranga!");
	   	new faction = PlayerInfo[playerid][pMember];
	   	//if(FrakCD[faction] > 0) return SendClientMessage(playerid, COLOR_GREY, "Iekarot zonu var vienreiz 40 minutes!");
	   	if(!IsInAllowed(playerid)) return SendClientMessage(playerid, COLOR_GREY, "Banda jau piedalas zonas partversanai!");
	   	for(new i = 1;i<=TOTALGZ;i++)
     	{
      		if(PlayerToKvadrat(playerid,GZInfo[i][gCoords][0], GZInfo[i][gCoords][1],GZInfo[i][gCoords][2],GZInfo[i][gCoords][3]) && ZoneOnBattle[i] == 0)
      		{
      		    if(GZInfo[i][gFrak] == faction) return SendClientMessage(playerid, COLOR_GREY, "Jūs nevarat iekarot savas bandas zonu!");
        		//if(!IsPlayerInBandOnline(GZInfo[i][gFrak])) return SendMes(playerid,COLOR_GREY, "Nav spēlētāju no bandas \"%s\"!", GetGangName(GZInfo[i][gFrak]));
				new string[256];
		  		format(string, 127,"[F] Jūsu zonai uzbrūk banda %s, jums ir 5 minūtes lai sagatavotos", FracInfo[PlayerInfo[playerid][pMember]][fName]);
          		SendFMes(GZInfo[i][gFrak],COLOR_LIGHTRED,string);
          		format(string, 127, "[F] Ja pēc laika iztecēљanas jus nebūsiet zona, tā paries %s",FracInfo[PlayerInfo[playerid][pMember]][fName]);
          		SendFMes(GZInfo[i][gFrak],COLOR_LIGHTRED,string);
          		format(string,128,"[F] %s sāka zonas iekaroљanu %s. Jums ir 5 minūtes lai sagatavotos",sendername(playerid),GetGangName(GZInfo[i][gFrak]));
          		SendFMes(faction,COLOR_LIGHTRED,string);
		  		GangZoneFlashForAll(GZInfo[i][id],GetGZColorF(faction));
          		GZSafeTime[i] = 300;
          		FrakCD[faction]  = 4200;
          		GZInfo[i][gNapad] = faction;
       			ZoneTimer[i] = 720;
          		ZoneOnBattle[i] = 1;
          		break;
            }
        }
	}
	else SendClientMessage(playerid, COLOR_GREY, YouCanNot);
	return 1;
}

stock SaveGZ(idx)
{
	format(query, sizeof(query), "UPDATE "TABLE_GANGZONE" SET ginfo1 = '%f', ginfo2 = '%f', ginfo3 = '%f', ginfo4 = '%f', fraction = %i WHERE id = %i",
	GZInfo[idx][gCoords][0], GZInfo[idx][gCoords][1],GZInfo[idx][gCoords][2],GZInfo[idx][gCoords][3],GZInfo[idx][gFrak], idx);
	mysql_query(query);
	return 1;
}
And here's the code for Mafia system:
Код:
#define MAX_MBIZZ 5
new MafiaOnZONE[MAX_MBIZZ][20];
new MafiaZoneOnBattle[MAX_MBIZZ];
new MafiaZoneTimer[MAX_MBIZZ];
new allowedmafias[] = {16, 17, 18};
new MZSafeTime[MAX_MBIZZ];
enum maf_bizz
{
	id,
	ID,
	Float:mCoord[4],
	mFraction,
	mFractTime,
	mMatsPrice,
	mDrugsPrice,
	mMineral,
	mFuels[128],
	mFuel[5],
	mEntPrice,
	mBarPrice,
	mMetals[128],
	mNapad
}
new MafiaInfo[MAX_MBIZZ][maf_bizz];
new FrakCDM[20];

stock LoadMafia()
{
    new time = GetTickCount();
    mysql_query("SELECT * FROM `"TABLE_MAFIA"`");
	mysql_store_result();
	if(mysql_num_rows() > 0)
	{
		for(new idx = 1; idx <= mysql_num_rows(); idx++)
		{
		   	mysql_fetch_row(query);
        	sscanf(query, "p<|>iiffffiiis[128]iiis[128]",
			MafiaInfo[idx][id],
			MafiaInfo[idx][mMatsPrice],
			MafiaInfo[idx][mCoord][0],
			MafiaInfo[idx][mCoord][1],
			MafiaInfo[idx][mCoord][2],
			MafiaInfo[idx][mCoord][3],
			MafiaInfo[idx][mFraction],
			MafiaInfo[idx][mFractTime],
			MafiaInfo[idx][mMineral],
			MafiaInfo[idx][mFuels],
			MafiaInfo[idx][mEntPrice],
			MafiaInfo[idx][mBarPrice],
			MafiaInfo[idx][mDrugsPrice],
			MafiaInfo[idx][mMetals]);
			TOTALMAFIA++;
       	 	sscanf(MafiaInfo[idx][mFuels], "p<,>a<i>[5]", MafiaInfo[idx][mFuel]);
	        MafiaInfo[idx][ID] = GangZoneCreate(MafiaInfo[idx][mCoord][0],MafiaInfo[idx][mCoord][1],MafiaInfo[idx][mCoord][2],MafiaInfo[idx][mCoord][3]);
	        MafiaZoneOnBattle[idx] = 0;
        	MZSafeTime[idx] = 0;
        }
		sscanf(MafiaInfo[1][mMetals], "p<,>iiiii", MafiaMetal[1], MafiaMetal[2], MafiaMetal[3], MafiaMetal[4], MafiaMetal[5]);
    }
    mysql_free_result();
    printf(" [mafijas]: tika ielaadeti - %d ļīņљąчеķī %d (ms)", TOTALMAFIA,GetTickCount() - time);
}

stock SaveMZ(idx)
{
	format(query, sizeof(query), "UPDATE "TABLE_MAFIA" SET minx = '%f', miny = '%f', maxx = '%f', maxy = '%f', fraction = %i WHERE id = %i",
	MafiaInfo[idx][mCoord][0], MafiaInfo[idx][mCoord][1],MafiaInfo[idx][mCoord][2],MafiaInfo[idx][mCoord][3],MafiaInfo[idx][mFraction], idx);
	mysql_query(query);
	return 1;
}

stock MzCheck()
{
	new string[128];
    for(new i =0;i<sizeof(MafiaInfo);i++)
    {
        if(MafiaZoneOnBattle[i] == 1 && MZSafeTime[i] == 0)
        {
            MafiaZoneTimer[i] -=5;
            new faction;
            new zl;
            zl = i;
            if(MafiaZoneTimer[i] <=0)
            {
                SendFMes(i,COLOR_RED,"[F] Laiks ir beidzies!");
                MafiaZoneOnBattle[i] =0;
                GangZoneStopFlashForAll(MafiaInfo[i][ID]);
                SaveMZ(zl);
            }
            for(new x =0;x<MAX_PLAYERS;x++)
            {
                if(PlayerToKvadrat(x,MafiaInfo[i][mCoord][0], MafiaInfo[i][mCoord][1],MafiaInfo[i][mCoord][2],MafiaInfo[i][mCoord][3])&&IsInAllowedMafia(x))
                {
                    if(PlayerInfo[x][pLeader] !=0) {faction = PlayerInfo[x][pLeader];}
                    else { faction = PlayerInfo[x][pMember];}
                    MafiaOnZONE[i][faction] ++;
                }
            }
            new asd;
            for(new x =0;x<20;x++)
            {
                if(MafiaOnZONE[i][x] > 0 && IsInAllowedFMafia(x)) asd ++;
            }
            if(asd == 1)
            {
                for(new x =0;x<20;x++)
                {
                    if(MafiaOnZONE[i][x] > 0)
                    {
                        new zx;
                        zx = x;
                        if(MafiaInfo[i][mFraction] == x) {format(string,90,"[F] %s mafija aizstaveja savu biznesu!",GetMafiaName(zx)); }
                        else
                        {format(string,90,"[F] %s banda vinneja un ieguva jaunu territoriju!",GetGangName(zx)); }
                        for(new ads = 8; ads <= 12;ads++) SendFMes(ads, COLOR_LIGHTRED,string);
                        MafiaZoneOnBattle[zl] =0;
                        MafiaInfo[zl][mNapad] = 0;
                        MafiaInfo[zl][mFraction] = zx;
                        GangZoneStopFlashForAll(MafiaInfo[zl][ID]);
                        GangZoneHideForAll(MafiaInfo[zl][ID]);
                        GangZoneShowForAll(MafiaInfo[zl][ID],GetMafiaZoneColor(zl));
                        SaveMZ(zl);
                        break;
                    }
                }
            }
        }
    }
    for(new i =0;i<120;i++)
    {
        for(new z = 0;z<20;z++)
        {
            MafiaOnZONE[i][z] =0;
        }
    }
    return 1;
}

forward SecUpdate();
public SecUpdate()
{
    MzCheck();
    for(new i = 1; i <= TOTALMAFIA; i++)
    {
        if(MZSafeTime[i] > 0)
        {
            MZSafeTime[i]--;
            if(MZSafeTime[i] == 60 || MZSafeTime[i] == 120)
            {
                format(string,127,"[F] Jums atlikusas %d sekundes lai sagatavotos",MZSafeTime[i]);
                SendFMes(MafiaInfo[i][mNapad],COLOR_LIGHTRED,string);
                SendFMes(MafiaInfo[i][mFraction],COLOR_LIGHTRED,string);
            }
            if(MZSafeTime[i] == 0)
            {
                format(string,127,"[F] Sagatavosanas laiks ir beidzies! Kad zona nebus tavas mafijas speletaji, ta tiks pretiniekiem!");
                SendFMes(MafiaInfo[i][mNapad],COLOR_LIGHTRED,string);
                SendFMes(MafiaInfo[i][mFraction],COLOR_LIGHTRED,string);
            }
        }
    }
}

CMD:mafbizz(playerid, params[])
{
	if(PlayerLogged[playerid] == 0) return 1;
	if(IsAMafia(playerid))
	{
		if(PlayerInfo[playerid][pRank] < 7) return SendClientMessage(playerid,COLOR_LIGHTRED,"funkcijas pieejama no 7 ranga!");
	   	new faction = PlayerInfo[playerid][pMember];
	   	if(FrakCDM[faction] > 0) return SendClientMessage(playerid, COLOR_GREY, "Jusu mafija jau karoja!");
	   	if(!IsInAllowedMafia(playerid)) return SendClientMessage(playerid, COLOR_GREY, "Mafija jau piedalas zonas partversanai!");
	   	for(new i = 1;i<=TOTALMAFIA;i++)
     	{
      		if(PlayerToKvadrat(playerid,MafiaInfo[i][mCoord][0], MafiaInfo[i][mCoord][1],MafiaInfo[i][mCoord][2],MafiaInfo[i][mCoord][3]) && MafiaZoneOnBattle[i] == 0)
      		{
      		    if(MafiaInfo[i][mFraction] == faction) return SendClientMessage(playerid, COLOR_GREY, "Jūs nevarat iekarot savas mafijas zonu!");
				new string[256];
		  		format(string, 127,"[F] Jūsu zonai uzbrūk banda %s, jums ir 3 minūtes lai sagatavotos", FracInfo[PlayerInfo[playerid][pMember]][fName]);
          		SendFMes(MafiaInfo[i][mFraction],COLOR_LIGHTRED,string);
          		format(string, 127, "[F] Ja pēc laika iztecēљanas jus nebūsiet zona, tā paries %s",FracInfo[PlayerInfo[playerid][pMember]][fName]);
          		SendFMes(MafiaInfo[i][mFraction],COLOR_LIGHTRED,string);
          		format(string,128,"[F] %s sāka zonas iekaroљanu %s. Jums ir 3 minūtes lai sagatavotos",sendername(playerid),GetMafiaName(MafiaInfo[i][mFraction]));
          		SendFMes(faction,COLOR_LIGHTRED,string);
		  		GangZoneFlashForAll(MafiaInfo[i][ID],GetMZColorF(faction));
          		MZSafeTime[i] = 300;
          		FrakCDM[faction]  = 4200;
          		MafiaInfo[i][mNapad] = faction;
       			MafiaZoneTimer[i] = 720;
          		MafiaZoneOnBattle[i] = 1;
          		break;
            }
        }
	}
	else SendClientMessage(playerid, COLOR_GREY, YouCanNot);
	return 1;
To me, this looks go. I can't find any mistakes I made. When capturing a Mafia's business, the MZSafeTime timer will never end. Hope someone can help me. Sorry about the messed up formating :P
Reply


Messages In This Thread
Timer not counting - by RageCraftLV - 02.07.2016, 11:31
Re: Timer not counting - by SetPlayerNameTag - 02.07.2016, 11:49
Re: Timer not counting - by RageCraftLV - 02.07.2016, 14:26
Re: Timer not counting - by RageCraftLV - 03.07.2016, 13:08

Forum Jump:


Users browsing this thread: 1 Guest(s)