What's new

Custom Script - NPC adding levels

akuz666

Verified Member
17
2021
5
Hello everyone,
recently I entered the world of emulation and trinitycore. I compiled a version and added some custom scripts (race swap, autobalance, etc).
Now I'd like to create something custom (custrom_script) but I haven't found any guides around that specifically talk about how the trinitycore code is structured. Only this one that speaks of the custom_script in general: https://trinitycore.atlassian.net/wiki/spaces/tc/pages/2130195/CustomScript
Perhaps the best idea for learning is to get started, but I would need your help to create something - hopefully - simple:

I would like to create a custom script, and then associate it to an NPC, which increase the level of a character (for example 80) by asking in exchange a specific object, a custom_item.

The idea is to try to figure out how to replicate the "character changes", something similar to the commands dedicated to the GM, through an exchange (levelup, modify money, add rep, etc.)

Can someone help me?

PS: If you know any guides that can help me, thank you in advance for sharing the links.

Thank you!
 

MrTacoTastic

Verified Member
10
2022
9
Location
United States
C++
C++:
struct LevelUpGossip : public ScriptedAI {
    explicit LevelUpGossip(Creature* creature) : ScriptedAI(creature) {}

    // Set your item entry id here.
    uint32 itemId = 60006;
    // Set the amount of the item required.
    uint32 amount = 1;

    bool OnGossipHello(Player* player) {
        if (player->GetMap()->IsBattlegroundOrArena() || player->IsInCombat() || player->IsInFlight()) {
            player->GetSession()->SendNotification("This can not be used in Combat, BG, Arena, or in Flight!");
            return false;
        }
        else {
            ClearGossipMenuFor(player);
            AddGossipItemFor(player, GossipOptionIcon::GOSSIP_ICON_DOT, "Level Up To 80!", GOSSIP_SENDER_MAIN, 1);
            SendGossipMenuFor(player, 1, me);
            return true;
        }
    }

    bool OnGossipSelect(Player* player, uint32 menuId, uint32 gossipListId) {
        uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
        uint32 const sender = player->PlayerTalkClass->GetGossipOptionSender(gossipListId);

        if (sender != GOSSIP_SENDER_MAIN)
            CloseGossipMenuFor(player);

        switch (action) {
        case 1:
            if (player->HasItemCount(itemId, amount, false) && player->GetLevel() != 80) {
                player->DestroyItemCount(itemId, amount, true);
                player->SetLevel(80);
                player->GetSession()->SendNotification("You leveled up to 80!");
            }
            else
                player->GetSession()->SendNotification("You do not have the required item or you are already level 80!");
            break;
        }
        return true;
    }
};

void AddSC_LevelUpGossip() {
    RegisterCreatureAI(LevelUpGossip);
}
SQL
SQL:
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `DamageModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (190001, 0, 0, 0, 0, 0, 1556, 0, 0, 0, 'Level Up', 'EmuCoach', NULL, 0, 80, 80, 2, 35, 1, 1, 1.14286, 3, 0, 0, 2000, 0, 1, 1, 1, 0, 0, 0, 0, 7, 138936390, 0, 0, 0, 0, 0, 0, 0, '', 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 'LevelUpGossip', 0);

There you go hope it helps.

Modify Money
player->ModifyMoney(amount, true);
Set Rep
player->SetReputation(repfactionentry, amount);
 
Top