• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

C++ newbie starting to learn .

Status
Not open for further replies.

Pox

Enthusiast
So i am learning c++. I am i doing it correct?
and yes there is probably 100 other duel reset scripts.

Code:
#include "ScriptPCH.h"

class DuelReset : public PlayerScript
{
    public
          DuelReset() : PlayerScript("DuelReset"){}
          void OnDuelEnd(Player* Winner, Player* Loser, DuelCompleteType)
          {
            Winner->RemoveAllSpellCooldown();
            Loser->RemoveAllSpellCooldown();
            Winner->SetHealth(Winner->GetMaxPower());
            if (Winner->getPowerType() == POWER_MANA)
                  winner->SetPower(POWER_MANA, pWinner->GetMaxPower(POWER_MANA));
            Loser->SetHealth(Loser->GetMaxPower()):
              if (Loser->getPowerType() == POWER_MANA)
                  loser->SetPower(POWER_MANA, loser->GetMaxPower(POWER_MANA));
          };

void AddSC_DuelReset()
{
        new DuelReset();
}
 

Tommy

Founder
So i am learning c++. I am i doing it correct?
and yes there is probably 100 other duel reset scripts.

Code:
#include "ScriptPCH.h"

class DuelReset : public PlayerScript
{
    public
          DuelReset() : PlayerScript("DuelReset"){}
          void OnDuelEnd(Player* Winner, Player* Loser, DuelCompleteType)
          {
            Winner->RemoveAllSpellCooldown();
            Loser->RemoveAllSpellCooldown();
            Winner->SetHealth(Winner->GetMaxPower());
            if (Winner->getPowerType() == POWER_MANA)
                  winner->SetPower(POWER_MANA, pWinner->GetMaxPower(POWER_MANA));
            Loser->SetHealth(Loser->GetMaxPower()):
              if (Loser->getPowerType() == POWER_MANA)
                  loser->SetPower(POWER_MANA, loser->GetMaxPower(POWER_MANA));
          };

void AddSC_DuelReset()
{
        new DuelReset();
}

Ultimately it is all about trial & error. Did you test this to see if it does work? I see a some issues. You aren't using the correct variable names for "SetPower" and "GetMaxPower", you're missing a colon next to "public", you're missing a close bracket for your hook function.

Code:
Player* Winner, Player* Loser

You're using 'winner->SetPower' and 'loser->SetPower', not 'Winner->SetPower' and 'Loser->SetPower' -- same with "GetMaxPower". You can't have different variable names calling methods, it doesn't work like that. You need to use the correct names. Though, I do recommend setting the variable all lower case:

P.S: You don't need to include ScriptPCH.h.

Code:
class DuelReset : public PlayerScript
{
public:
    DuelReset() : PlayerScript("DuelReset") { }

    void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType /* duelType */)
    {
        winner->RemoveAllSpellCooldown();
        loser->RemoveAllSpellCooldown();
        winner->SetHealth(winner->GetMaxPower());
        if (winner->getPowerType() == POWER_MANA)
            winner->SetPower(POWER_MANA, winner->GetMaxPower(POWER_MANA));
        loser->SetHealth(loser->GetMaxPower()):
        if (loser->getPowerType() == POWER_MANA)
            loser->SetPower(POWER_MANA, loser->GetMaxPower(POWER_MANA));
    }
};

void AddSC_DuelReset()
{
    new DuelReset();
}

Clean script goes along way too. Also, your setup function "void AddSC_DuelReset()" can be named anything and doesn't always need to have "AddSC_" in it. ;)
 

Jpp

Administrator
Code:
class DuelReset : public PlayerScript
{
public:
    DuelReset() : PlayerScript("DuelReset") { }

    void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType /* duelType */)
    {
        winner->RemoveAllSpellCooldown();
        loser->RemoveAllSpellCooldown();
        winner->SetHealth(winner->[COLOR="#00FF00"]GetMaxHealth()[/COLOR]);
        if (winner->getPowerType() == POWER_MANA)
            winner->SetPower(POWER_MANA, winner->GetMaxPower(POWER_MANA));
        loser->SetHealth(loser->[COLOR="#00FF00"]GetMaxHealth()[/COLOR]):
        if (loser->getPowerType() == POWER_MANA)
        loser->SetPower(POWER_MANA, loser->GetMaxPower(POWER_MANA));
    }
};

void AddSC_DuelReset()
{
    new DuelReset();
}

.
 
Status
Not open for further replies.
Top