Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Pomoc w redukcji if-else


Rekomendowane odpowiedzi

Opublikowano

Witam. podobno moje kody sa "malo wydajne" ptak powiedzial mi wykladowca zawsze skraca moj ekody o poloew xD

i tu jest moje pytanie czy ktos by mi pomogl lekko zredukowac to cacuszko:

if(GetHPProc(handle,baseAddr,HP ,HP_max , XorAd)<=hp_M_heal && GetHPProc(handle,baseAddr,HP ,HP_max , XorAd)>=hp_Uhp_heal){//hp < X % i hp > hp X % na uhp

                if(exhaustedmp>=Time_Mp){
                    ControlSend("TibiaClient",'!', VK_F1);//uhp
                    cout<<"Using one of Your ultimate health potions..."<<endl;
                    Time_Mp=exhaustedmp+timep;
                }//ifwif
           // }//if uhp czy potrawka
        }else if(GetHPProc(handle,baseAddr,HP ,HP_max , XorAd)<=hp_Uhp_heal){//hp < X %

                        if(exhaustedmp>=Time_Spell){
                            ControlSend("TibiaClient",'*', VK_F1);//exura gran ico
                            cout<<"Using one of Your mana potions..."<<endl;

                            Time_Spell=exhaustedmp+times;
                        }
                        if(exhaustedspell>=Time_Mp){
                            ControlSend("TibiaClient",'!', VK_F1);//uhp
                            cout<<"Using one of Your ultimate health potions..."<<endl;
                            Time_Mp=exhaustedspell+timep;
                        }
           // }//if uhp czy potrawka
        }else{
                if(GetHPProc(handle,baseAddr,HP ,HP_max , XorAd)<=hp_heal &&  GetMPProc(handle,baseAddr,MP ,MP_max , XorAd) <= mp_easy){//jesli hp<x% i mp < x% to mp+spell...

                       if(exhaustedmp>=Time_Mp){
                            ControlSend("TibiaClient",'!', VK_F11);//mp
                            cout<<"Using one of Your mana potions..."<<endl;

                            Time_Mp=exhaustedmp+timep;
                        }
                        if(exhaustedspell>=Time_Spell){
                            ControlSend("TibiaClient",'!', VK_F12);//exura ico
                           cout<<"exura ico"<<endl;
                            Time_Spell=exhaustedspell+times;
                        }
                }else if(GetHPProc(handle,baseAddr,HP ,HP_max , XorAd)<=hp_heal &&  GetMPProc(handle,baseAddr,MP ,MP_max , XorAd) >= mp_easy){//hp<90% i mana > spell to spell...

                         if(exhaustedspell>=Time_Spell){
                                    ControlSend("TibiaClient",'!', VK_F12);//exura ico
                                   cout<<"exura ico"<<endl;
                                    Time_Spell=exhaustedspell+times;
                                }
                }else if(GetHPProc(handle,baseAddr,HP ,HP_max , XorAd) >= hp_heal && GetMPProc(handle,baseAddr,MP ,MP_max , XorAd) <= mp_easy){

                            if(exhaustedmp>=Time_Mp){
                                ControlSend("TibiaClient",'!', VK_F11);//mp
                                cout<<"Using one of Your mana potions..."<<endl;

                                Time_Mp=exhaustedmp+timep;
                            }
                

                   if(GetPlayerFlags(handle,baseAddr,PlayerFlag) == (battle+paraliz) || GetPlayerFlags(handle,baseAddr,PlayerFlag)== (battle+paraliz+poisoned) || GetPlayerFlags(handle,baseAddr,PlayerFlag)== (battle+paraliz+topienie) || GetPlayerFlags(handle,baseAddr,PlayerFlag)== (battle+paraliz+topienie+poisoned)){
                             if(exhaustedspell>=Time_Spell){
                                ControlSend("TibiaClient",'!', VK_F12);//exura ico(na paraliz)
                                cout<<"paraliz->exura ico"<<endl;
                                Time_Spell=exhaustedspell+times;
                            }
                    }else if(GetHPProc(handle,baseAddr,HP ,HP_max , XorAd)>=hp_heal && (GetPlayerFlags(handle,baseAddr,PlayerFlag) == (pz+poisoned) || GetPlayerFlags(handle,baseAddr,PlayerFlag) == (pz+poisoned+topienie) ||GetPlayerFlags(handle,baseAddr,PlayerFlag) == (battle+poisoned) || GetPlayerFlags(handle,baseAddr,PlayerFlag)== (battle+poisoned+topienie) || GetPlayerFlags(handle,baseAddr,PlayerFlag) == (battle+topienie+buff+poisoned))){
                        if(exhaustedspell>=Time_poi){
                            ControlSend("TibiaClient",'*', VK_F3);//exana pox
                            cout<<"poisoned->exana pox"<<endl;
                               Time_poi=exhaustedspell+6000;
                            }
                    }


                }//elfe

jakby mial ktos jakies sugestie walic smialo:)

Do
$wiek+=1
Until ŻycieGetMsg() = -3

zbieram +

Opublikowano

Po pierwsze naucz się lepiej formatować kod i nazywać zmienne.

W tym kodzie nie ma jako tako dużo do optymalizacji, poza powtarzającymi się wywołaniami.

Jedynie poprawiłem czytelność kodu (nazwy zmiennych zostały)

struct Reaction
{
    char type;
    uint8_t key;
    std::string message;
    int updateTimeP;
    int updateTimeS;
    int updateTimePoi;
} reaction;
reaction.type = '\0'; //oznacza brak reakcji

int hp = GetHPProc(handle, baseAddr, HP, HP_max, XorAd);
int mp = GetMPProc(handle, baseAddr, MP, MP_max, XorAd);

if(hp <= hp_M_heal && hp >= hp_Uhp_heal) //hp < X % i hp > hp X % na uhp
{
    if(exhaustedmp >= Time_Mp) reaction = Reaction           {'!', VK_F1, "Using one of Your ultimate health potions...", timep, 0, 0};
}
else if(hp <= hp_Uhp_heal) //hp < X %
{
    if(exhaustedmp    >= Time_Spell) reaction = Reaction     {'*', VK_F1, "Using one of Your mana potions...", 0, times, 0};
    if(exhaustedspell >= Time_Mp) reaction = Reaction        {'!', VK_F1, "Using one of Your ultimate health potions...", timep, 0, 0};
}
else if(hp <= hp_heal && mp <= mp_easy) //jesli hp<x% i mp < x% to mp+spell...
{
    if(exhaustedmp    >= Time_Mp)    reaction = Reaction     {'!', VK_F11, "Using one of Your mana potions...", timep, 0, 0};
    if(exhaustedspell >= Time_Spell) reaction = Reaction     {'!', VK_F12, "exura ico", 0, times, 0};
}
else if(hp <= hp_heal && mp >= mp_easy) //hp<90% i mana > spell to spell...
{
    if(exhaustedspell >= Time_Spell) reaction = Reaction     {'!', VK_F12, "exura ico", 0, times, 0};
}
else if(hp >= hp_heal && mp <= mp_easy)
{
    if(exhaustedmp >= Time_Mp) reaction = Reaction           {'!', VK_F11, "Using one of Your mana potions...", timep, 0, 0};

    int playerFlags = GetPlayerFlags(handle, baseAddr, PlayerFlag);
    //TYCH PONIZEJ NIE DA RADY SKROCIC BARDZIEJ BEZ WIEKSZEJ ILOSCI INFORMACJI
    if(playerFlags == (battle + paraliz) || playerFlags == (battle + paraliz + poisoned) || playerFlags == (battle + paraliz + topienie) || playerFlags == (battle + paraliz + topienie + poisoned))
    {
        if(exhaustedspell >= Time_Spell) reaction = Reaction {'!', VK_F12, "paraliz->exura ico", 0, times, 0};
    }
    else if(hp >= hp_heal && (playerFlags == (pz + poisoned) || playerFlags == (pz + poisoned + topienie) || playerFlags == (battle + poisoned) || playerFlags == (battle + poisoned + topienie) || playerFlags == (battle + topienie + buff + poisoned)))
    {
        if(exhaustedspell >= Time_poi)   reaction = Reaction {'*', VK_F3, "poisoned->exana pox", 0, 0, 6000};
    }

}
if(reaction.type != '\0')
{    
    ControlSend("TibiaClient", reaction.type, reaction.key);
    cout << reaction.message << '\n';
    if(reaction.updateTimeP > 0) Time_Mp = exhaustedmp + reaction.updateTimeP;
    if(reaction.updateTimeS > 0) Time_Spell = exhaustedspell + reaction.updateTimeS;
    if(reaction.updateTimePoi > 0) Time_poi = exhaustedspell + reaction.updateTimePoi;
}

Opublikowano

Dzieki, w sumie ladniej to wyglada po dodaniu struktury.

no czyli chyba nie narobilem za duzo if-ow xD

Do
$wiek+=1
Until ŻycieGetMsg() = -3

zbieram +

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...