Page 1 of 1

Intrebare cod

Posted: 05 Jan 2018, 05:58
by Filiq_
Am si eu o intrebare. Cat de optim e? eu zic ca altceva n-ar avea ce sa ii faca

Code: Select all

    /*IsDay = 1 Zombie Day
    IsDay = 2 Reverse Zombie Day
    IsDay = 3 Knife Day
    IsDay = 4 Fotball
    IsDay = 5 Gun Day
    IsDay = 6 Sparta Day
    IsDay = 7 GodMode Day
    IsDay = 8 Paintball Day
    IsDay = 9 Nightcrawler
    IsDay = 10 Nightcrawler Reverse
    IsDay = 11 HNS
    IsDay = 12 HNS reverse
    IsDay = 13 Shark Day
    IsDay = 14 Space Day*/

    switch(IsDay)
    {
        case 1..2: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(1))
        case 3: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(3))
        case 4: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(4))
        case 5: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(5))
        case 6: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(6))
        case 7: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(7))
        case 8: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(8))
        case 9..10: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(9))
        case 11..12: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(11))
        case 13: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(13))
        case 14: player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(14))
    }
 

Code: Select all

public GetDay(day)
{
    switch(day)
    {
        case 1:
        {
            switch(IsDay)
            {
                case 1: //zombie
                case 2: // reverse
            }
        }
        case 3:
        case 4
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        {
            switch(IsDay)
            {
                case 9: // Nightcrawler
                case 10: // Nightcrawler reverse
            }
        }
        case 11:
        {
            switch(IsDay)
            {
                case 11: // hns
                case 12: // hns reverse
            }
        }
        case 13:
        case 14:

    }

}
 
GetDay arata numele dayului, cum as putea sa fac sa il arate? eu m-am gandit la un string si dupa il returnez.

Re: Intrebare cod

Posted: 05 Jan 2018, 12:06
by Lux0R^
puteai face al doilea switch sa fie mai complet (get day)

iar primul sa il faci mai simplu, redus la o linie : player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))

e acelasi nivel de eficienta, doar ca e codul mai scurt.

Re: Intrebare cod

Posted: 05 Jan 2018, 12:37
by Filiq_
Lux0R^ wrote:puteai face al doilea switch sa fie mai complet (get day)

iar primul sa il faci mai simplu, redus la o linie : player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))

e acelasi nivel de eficienta, doar ca e codul mai scurt.
al 2-lea cod l-am facut pana la urma, ii formatez un string dupa il returnez si merge.

La primul cod daca fac cum ai zis tu nu o sa mearga pentru ca nu va arata mesajul. M-am gandit la altceva, la asta:

Code: Select all

if(IsDay >= 1)
    player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))

Re: Intrebare cod

Posted: 05 Jan 2018, 14:12
by Lux0R^
Diversity wrote:
Lux0R^ wrote:puteai face al doilea switch sa fie mai complet (get day)

iar primul sa il faci mai simplu, redus la o linie : player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))

e acelasi nivel de eficienta, doar ca e codul mai scurt.
al 2-lea cod l-am facut pana la urma, ii formatez un string dupa il returnez si merge.

La primul cod daca fac cum ai zis tu nu o sa mearga pentru ca nu va arata mesajul. M-am gandit la altceva, la asta:

Code: Select all

if(IsDay >= 1)
    player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))
cum adica nu va arata mesajul ? :-? si da e ok ca l-ai restrictionat, poate trebe sa pui si un max nu doar minim

Re: Intrebare cod

Posted: 05 Jan 2018, 15:19
by Filiq_
Lux0R^ wrote:
Diversity wrote:
Lux0R^ wrote:puteai face al doilea switch sa fie mai complet (get day)

iar primul sa il faci mai simplu, redus la o linie : player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))

e acelasi nivel de eficienta, doar ca e codul mai scurt.
al 2-lea cod l-am facut pana la urma, ii formatez un string dupa il returnez si merge.

La primul cod daca fac cum ai zis tu nu o sa mearga pentru ca nu va arata mesajul. M-am gandit la altceva, la asta:

Code: Select all

if(IsDay >= 1)
    player_hudmessage(0, 2, HUD_DELAY + 1.0, {0, 255, 0}, "%L", LANG_SERVER, "JBE_IS_DAY", GetDay(IsDay))
cum adica nu va arata mesajul ? :-? si da e ok ca l-ai restrictionat, poate trebe sa pui si un max nu doar minim
Daca nu faceam verificarea nu arata mesajul

Re: Intrebare cod

Posted: 18 Jan 2018, 11:16
by LondoN eXtream
Daca vrei sa returnezi string | Afiseaza codul
stock GetDayName(DayNumber)
{
	new g_szDayName[32];

	switch(DayNumber)
	{
		case 1: formatex(g_szDayName, charsmax(g_szDayName), "Nume Ziua 1");
		case 2: formatex(g_szDayName, charsmax(g_szDayName), "Nume Ziua 2");
	}

	return g_szDayName;
}