Health and Mana Regenerator
Lua Script and C++ Script
Coded by Baptizein
What does it do?
This script will allow players to fully regenerate their health and mana (if used) at any time for a fee, using the following item:
Why create a Lua script and a C++ script?Code:INSERT INTO items (`entry`, `class`, `subclass`, `field4`, `name1`, `name2`, `name3`, `name4`, `displayid`, `quality`, `flags`, `buyprice`, `sellprice`, `inventorytype`, `allowableclass`, `allowablerace`, `itemlevel`, `requiredlevel`, `RequiredSkill`, `RequiredSkillRank`, `RequiredSkillSubRank`, `RequiredPlayerRank1`, `RequiredPlayerRank2`, `RequiredFaction`, `RequiredFactionStanding`, `Unique`, `maxcount`, `ContainerSlots`, `stat_type1`, `stat_value1`, `stat_type2`, `stat_value2`, `stat_type3`, `stat_value3`, `stat_type4`, `stat_value4`, `stat_type5`, `stat_value5`, `stat_type6`, `stat_value6`, `stat_type7`, `stat_value7`, `stat_type8`, `stat_value8`, `stat_type9`, `stat_value9`, `stat_type10`, `stat_value10`, `dmg_min1`, `dmg_max1`, `dmg_type1`, `dmg_min2`, `dmg_max2`, `dmg_type2`, `dmg_min3`, `dmg_max3`, `dmg_type3`, `dmg_min4`, `dmg_max4`, `dmg_type4`, `dmg_min5`, `dmg_max5`, `dmg_type5`, `armor`, `holy_res`, `fire_res`, `nature_res`, `frost_res`, `shadow_res`, `arcane_res`, `delay`, `ammo_type`, `range`, `spellid_1`, `spelltrigger_1`, `spellcharges_1`, `spellcooldown_1`, `spellcategory_1`, `spellcategorycooldown_1`, `spellid_2`, `spelltrigger_2`, `spellcharges_2`, `spellcooldown_2`, `spellcategory_2`, `spellcategorycooldown_2`, `spellid_3`, `spelltrigger_3`, `spellcharges_3`, `spellcooldown_3`, `spellcategory_3`, `spellcategorycooldown_3`, `spellid_4`, `spelltrigger_4`, `spellcharges_4`, `spellcooldown_4`, `spellcategory_4`, `spellcategorycooldown_4`, `spellid_5`, `spelltrigger_5`, `spellcharges_5`, `spellcooldown_5`, `spellcategory_5`, `spellcategorycooldown_5`, `bonding`, `description`, `page_id`, `page_language`, `page_material`, `quest_id`, `lock_id`, `lock_material`, `sheathID`, `randomprop`, `unk203_1`, `block`, `itemset`, `MaxDurability`, `ZoneNameID`, `mapid`, `bagfamily`, `TotemCategory`, `socket_color_1`, `unk201_3`, `socket_color_2`, `unk201_5`, `socket_color_3`, `unk201_7`, `socket_bonus`, `GemProperties`, `ReqDisenchantSkill`, `unk2`) VALUES (90000, 15, 0, -1, 'Health and Mana Regenerator', '', '', '', 43359, 1, 0, 0, 0, 0, -1, -1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1500, 0, 0, 46642, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 'Created by Baptizein', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, NULL, -1, 0);
I wanted to give administrators the choice of which one they want to use on their server. The C++ script offers more flexibility and will allow for a better script in the future, while the Lua version doesn't need to be compiled with each new server revision. The two scripts have some differences in coding, though. With the C++ version, I opted not to add a function to check if the player is in combat or not. I'll leave this up to server admins.
Why is it a WIP?
I'm not an expert when it comes to Lua and C++, but I know enough to get me by some obsticles. However, on the C++ version, I couldn't get the script to set the player's mana percentage. This is due to the fact that SetHealthPct is a valid function, but SetManaPct is not. So, until I find a solution to this, it will remain removed from the code. Also, on the Lua version, I had a difficult time trying to get the script to subtract gold from the player and couldn't figure it out, so I removed the code from that part of the script and will add it in when I do get it right.
C++ Version
HealthMana.cpp
Setup.cppCode:// Health and Mana Regenerator created by Baptizein #include "StdAfx.h" #include "Setup.h" class SCRIPT_DECL HealthMana : public GossipScript { public: void GossipStart(Object * pObject, Player* Plr, bool AutoSend); void GossipSelection(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code); void GossipEnd(Object * pObject, Player* Plr); void Destroy() { delete this; } }; void HealthMana::GossipStart(Object * pObject, Player* Plr, bool AutoSend) { GossipMenu *Menu; objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr); Menu->AddItem(0, "Restore My Health [ 5000 Gold ]", 1); // Menu->AddItem(0, "Restore My Mana [ 3000 Gold ]", 2); if(AutoSend) Menu->SendTo(Plr); } void HealthMana::GossipSelection(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code) { switch(IntId) { case 0: GossipStart(pObject, Plr, true); break; case 1: { uint32 price=50000000; uint32 currentgold = Plr->GetUInt32Value(PLAYER_FIELD_COINAGE); if (currentgold>=price){ int32 newgold = currentgold - price; Plr->SetUInt32Value(PLAYER_FIELD_COINAGE,newgold); Plr->SetHealthPct(100); Plr->BroadcastMessage("Health has been restored. Removing 5000 gold. Thank you!"); }else{ Plr->BroadcastMessage("You don't have enough gold."); } } break; // SetManaPct() is not an available function, so this part will be commented until I can find another solution. // case 2: // { // if (Plr->GetPowerType() != POWER_TYPE_MANA){ // Plr->BroadcastMessage("You do not use mana."); break; // } // uint32 price=30000000; // uint32 currentgold = Plr->GetUInt32Value(PLAYER_FIELD_COINAGE); // if (currentgold>=price){ // int32 newgold = currentgold - price; // Plr->SetUInt32Value(PLAYER_FIELD_COINAGE,newgold); // Plr->SetManaPct(100); // Plr->BroadcastMessage("Mana has been restored. Removing 3000 gold. Thank you!"); // }else{ // Plr->BroadcastMessage("You don't have enough gold."); // } // } // break; } } void HealthMana::GossipEnd(Object * pObject, Player* Plr) { GossipScript::GossipEnd(pObject, Plr); } void SetupHealthMana(ScriptMgr * mgr) { GossipScript * gs = (GossipScript*) new HealthMana(); mgr->register_item_gossip_script(90000,gs); }
Setup.hCode:#include "StdAfx.h" #include "Setup.h" #define SKIP_ALLOCATOR_SHARING 1 #include <ScriptSetup.h> extern "C" SCRIPT_DECL uint32 _exp_get_script_type() { return SCRIPT_TYPE_MISC; } extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr) { SetupHealthMana(mgr); } #ifdef WIN32 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #endif
.VCPROJ Download (Required)Code:#ifndef INSTANCE_SCRIPTS_SETUP_H #define INSTANCE_SCRIPTS_SETUP_H void SetupHealthMana(ScriptMgr * mgr); #endif
http://www.wowfare.net/downloads/pro...ana2008.vcproj
Lua++ Version
If someone wants to try and fix these, by all means do so. I'll gladly give +rep and full credits to that person. Anyways, enjoy what I have so far and in the meantime I'll try to get it to work 100%. Thanks for looking!Code:-- Health and Mana Regenerator created by Baptizein local itemid = 90000 function HealthMana_Start(item, event, player) HealthMana_Menu(item, player) end function HealthMana_Menu(item, unit, event, player, id) if (player:IsInCombat() == true) then unit:SendChatMessage(12, 0, "You cannot use this while in combat.") else item:GossipCreateMenu(100, player, 0) item:GossipMenuAddItem(0, "Restore My Health [ 5000 Gold ]", 1, 0) item:GossipMenuAddItem(0, "Restore My Mana [ 3000 Gold ]", 2, 0) item:GossipSendMenu(player) end end function HealthMana_Selection(item, unit, event, player, id, intid, code) if(intid == 1) then player:SetHealthPct(100) if player:GetUInt32Value(PLAYER_FIELD_COINAGE) > 4999 then -- Subtract money from current gold goes here unit:SendChatMessage(12, 0, "Health restored. Subtracted 5000 gold from character. Thank you!") else unit:SendChatMessage(12, 0, "You do not have enough gold.") end end if(intid == 2) then player:GetPowerType() if (player:GetPowerType() == mana) then player:SetManaPct(100) if player:GetUInt32Value(PLAYER_FIELD_COINAGE) < 3000 then unit:SendChatMessage(12, 0, "You do not have enough gold.") -- Subtract money from current gold code goes here unit:SendChatMessage(12, 0, "Mana restored. Subtracted 3000 gold from character. Thank you!") else unit:SendChatMessage(12, 0, "Your character does not use mana.") end end end end RegisterItemGossipEvent(itemid, 1, "HealthMana_Start") RegisterItemGossipEvent(itemid, 2, "HealthMana_Selection")