[Patch] Cancel Maintained & Use Equipped Item Commands
Posted: Mon May 31, 2010 10:12 pm
I've added two commands that I'd like you guys to take a look at to make sure it looks okay.
The first is COMMAND_USE_EQUIPPED_ITEM (275). It is implemented almost exactly like COMMAND_USE_ITEM except the slot_id is passed in instead of the item_index. I also check if the item is useable before calling the item script. I verified this works by hooking up one of the mount whistles to a lua script I created (see horsemount.lua below) and tied the item to that script in the database. The script just calls the beta mount spell. It worked like a charm from the inventory and also when equipped in the charm slot.
I also realize there is more stuff to add to make usable items work like live but this is a start.
horsemount.lua
The second command I added was COMMAND_CANCEL_MAINTAINED (276). After I used the beta mount, I couldn't figure out how to get rid of it (besides logging), so I implemented this command. The code is pretty simple. The client sends the maintained spell index. I use that to get the spell from the master_spell_list. After verifying that it is a friendly spell, I call the DeleteCasterSpell function (already implemented) which handles the removal of the buffs. I tested this solo and in a group. I also tested when I had more that one maintained spell active.
Also, obviously the handlers have to be updated in the database as well. As always, let me know if I overlooked something. I'm not sure how much time I can devote to this project so don't call me official yet but I am having a blast so far.
Commands.h
Commands.cpp
The first is COMMAND_USE_EQUIPPED_ITEM (275). It is implemented almost exactly like COMMAND_USE_ITEM except the slot_id is passed in instead of the item_index. I also check if the item is useable before calling the item script. I verified this works by hooking up one of the mount whistles to a lua script I created (see horsemount.lua below) and tied the item to that script in the database. The script just calls the beta mount spell. It worked like a charm from the inventory and also when equipped in the charm slot.
horsemount.lua
Code: Select all
function used(Item, ItemUser)
CastSpell(ItemUser, 3101, 1, ItemUser)
end
Also, obviously the handlers have to be updated in the database as well. As always, let me know if I overlooked something. I'm not sure how much time I can devote to this project so don't call me official yet but I am having a blast so far.
Commands.h
Code: Select all
--- Commands.h (revision 437)
+++ Commands.h (working copy)
@@ -477,4 +477,6 @@
#define COMMAND_LOCATION_REMOVE 272
#define COMMAND_LOCATION_DELETE 273
#define COMMAND_LOCATION_LIST 274
+#define COMMAND_USE_EQUIPPED_ITEM 275
+#define COMMAND_CANCEL_MAINTAINED 276
#endif
Code: Select all
--- Commands.cpp (Revision 437)
+++ Commands.cpp (working copy)
@@ -960,6 +960,16 @@
client->SimpleMessage(CHANNEL_COLOR_YELLOW,"Usage: /info {inventory|equipment|spell} {id}");
break;
}
+
+ case COMMAND_USE_EQUIPPED_ITEM:
+ if (sep && sep->arg[0] && sep->IsNumber(0)) {
+ int32 slot_id = atoul(sep->arg[0]);
+ Item* item = player->GetEquipmentList()->GetItem(slot_id);
+ if (item && item->generic_info.usable && item->GetItemScript())
+ lua_interface->RunItemScript(item->GetItemScript(), "used", item, player);
+ }
+ break;
+
case COMMAND_USE_ITEM: {
if (sep && sep->arg[0] && sep->IsNumber(0)) {
int32 item_index = atoul(sep->arg[0]);
@@ -3978,6 +3988,21 @@
client->Message(CHANNEL_COLOR_YELLOW,"You are %s invisible to who queries.", client->GetPlayer()->get_character_flag(CF_GM_HIDDEN)?"now":"no longer");
break;
}
+ case COMMAND_CANCEL_MAINTAINED:{
+ if (sep && sep->arg[0] && sep->IsNumber(0)) {
+ int32 spell_index = atoul(sep->arg[0]);
+ MaintainedEffects mEffects = client->GetPlayer()->GetInfoStruct()->maintained_effects[spell_index];
+
+ Spell* spell = master_spell_list.GetSpell(mEffects.spell_id, mEffects.tier);
+ if(spell && spell->GetSpellData()->friendly_spell){
+ if(!client->GetPlayer()->GetZone()->GetSpellProcess()->DeleteCasterSpell(client->GetPlayer(), spell))
+ client->Message(CHANNEL_COLOR_RED, "The maintained spell could not be cancelled.");
+ }
+ else
+ client->Message(CHANNEL_COLOR_RED, "You can only cancel friendly spells!");
+ }
+ break;
+ }
default:{
LogFile->write(EQEMuLog::Status, "Unhandled command: %s", command->command.data.c_str());
}