Browse Source

LUA Function AddItem(Spawn, ItemID, Quantity) for players

Alternate to SummonItem as it does not allow quantity.  AddItem for the time being is only for adding a single item or stack of items, quantity is an optional field.
Image 3 years ago
parent
commit
331a1a2b4c

+ 22 - 0
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -917,6 +917,28 @@ int EQ2Emu_lua_SpellHeal(lua_State* state) {
 	return 0;
 }
 
+int EQ2Emu_lua_AddItem(lua_State* state) {
+	if (!lua_interface)
+		return 0;
+	Spawn* spawn = lua_interface->GetSpawn(state);
+	int32 item_id = lua_interface->GetInt32Value(state, 2);
+	int16 quantity = lua_interface->GetInt32Value(state, 3);
+
+	// default of 1 quantity to add
+	if (quantity == 0)
+		quantity = 1;
+
+	if (spawn && spawn->IsPlayer()) {
+		Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
+		if (client && item_id > 0) {
+			lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
+			return 1;
+		}
+	}
+
+	lua_interface->SetBooleanValue(state, false);
+	return 1;
+}
 
 int EQ2Emu_lua_SummonItem(lua_State* state) {
 	if (!lua_interface)

+ 2 - 0
EQ2/source/WorldServer/LuaFunctions.h

@@ -130,6 +130,8 @@ int EQ2Emu_lua_ModifyHP(lua_State* state);
 int EQ2Emu_lua_ModifyTotalPower(lua_State* state);
 int EQ2Emu_lua_ModifyTotalHP(lua_State* state);
 int EQ2Emu_lua_SpellHeal(lua_State* state);
+
+int EQ2Emu_lua_AddItem(lua_State* state);
 int EQ2Emu_lua_SummonItem(lua_State* state);
 int EQ2Emu_lua_RemoveItem(lua_State* state);
 int EQ2Emu_lua_HasItem(lua_State* state);

+ 1 - 0
EQ2/source/WorldServer/LuaInterface.cpp

@@ -693,6 +693,7 @@ void LuaInterface::RegisterFunctions(lua_State* state) {
 	lua_register(state, "SpellDamage", EQ2Emu_lua_SpellDamage);
 	lua_register(state, "CastSpell", EQ2Emu_lua_CastSpell);	
 	lua_register(state, "SpellHeal", EQ2Emu_lua_SpellHeal);
+	lua_register(state, "AddItem", EQ2Emu_lua_AddItem);
 	lua_register(state, "SummonItem", EQ2Emu_lua_SummonItem);
 	lua_register(state, "RemoveItem", EQ2Emu_lua_RemoveItem);
 	lua_register(state, "HasItem", EQ2Emu_lua_HasItem);