LitchLight
Trial Member
- 1
- 2023
- 0
WOOPS-001.RELEASE.LUA
This script allows the server to spawn a custom game object with a generic loot template, and then dynamically replaces that loot with specific dropped items when a player interacts with the object via the OnLoot function. At this point the existing loot is cleared from the lua table and the specific dropped items from the player who died are awarded up to the limit of the recipient's bag space. When the server restarts the crates and data are lost.
This script allows the server to spawn a custom game object with a generic loot template, and then dynamically replaces that loot with specific dropped items when a player interacts with the object via the OnLoot function. At this point the existing loot is cleared from the lua table and the specific dropped items from the player who died are awarded up to the limit of the recipient's bag space. When the server restarts the crates and data are lost.
Code:
--[[
Woops! You died!
(c) 2023 LitchLight-III. All Rights Reserved. Please include this header and do not modify.
Server Side LUA routine for ELUNA/TrinityCore.
https://youtu.be/7SgIDcSvkIY
Video is over long - I got messed up by mobs!
Wanted a game mode where players drop all their equipment and loot when they die.
This script allows the server to spawn a custom game object with a generic loot template, and then dynamically replaces that loot with specific dropped items when a player interacts with the object via the OnLoot function. At this point the existing loot is cleared from the lua table and the specific dropped items from the player who died are awarded up to the limit of the recipient's bag space. When the server restarts the crates and data are lost.
to implement -
1. copy this script to your server lua script dir
3. import the custom gameobject_template SQL:
// *********************************************************************
// LLIII Lootable pLayers custom game object - adjust as required.
// *********************************************************************
insert into `gameobject_template` (`entry`, `type`, `displayId`, `name`, `IconName`, `castBarCaption`, `unk1`, `faction`, `flags`, `size`, `Data0`, `Data1`, `Data2`, `Data3`, `Data4`, `Data5`, `Data6`, `Data7`, `Data8`, `Data9`, `Data10`, `Data11`, `Data12`, `Data13`, `Data14`, `Data15`, `Data16`, `Data17`, `Data18`, `Data19`, `Data20`, `Data21`, `Data22`, `Data23`, `AIName`, `ScriptName`, `VerifiedBuild`) values('600000','3','259','Dropped Items in a Battered Chest','','','','0','','1','57','0','0','1','0','0','0','0','0','0','1','0','1','0','0','1','0','0','0','0','0','0','0','0','','','12340');
3. restart server
4. try not to die!
]]--
local v0 = {};
local v1 = 0 - 0;
local v2 = 601187 - (1069 + 118);
function OnPlayerDeath(v3, v4, v5)
local v6 = 0 - 0;
local v7;
local v8;
local v9;
local v10;
local v11;
while true do
if ((1 - 0) == v6) then
v8 = v5:GetLocation();
v9 = v5:GetGUIDLow();
v6 = 1 + 1;
end
if (v6 == (0 - 0)) then
v7 = v5:InBattleground();
if (v7 == true) then
return false;
end
v6 = 1 + 0;
end
if ((794 - (368 + 423)) == v6) then
if v11 then
local v22 = 0 - 0;
local v23;
while true do
if (v22 == (22 - (10 + 8))) then
v5:PlayDirectSound(44618 - 33019);
print("Spawned lootable gameobject at:", v5:GetX(), v5:GetY(), v5:GetZ());
break;
end
if (v22 == (444 - (416 + 26))) then
for v26 = 60 - 41, 10 + 12 do
for v32 = 0 - 0, 35 do
local v33 = v5:GetItemByPos(v26, v32);
if v33 then
local v48 = 438 - (145 + 293);
local v49;
local v50;
local v51;
while true do
if (v48 == (430 - (44 + 386))) then
v49 = v33:GetName();
v50 = v33:GetCount();
v48 = 1;
end
if (v48 == 1) then
v51 = v33:GetItemLink();
print("Adding item to loot: ", v49, v50, v51);
v48 = 2;
end
if (v48 == 2) then
table.insert(v0[v23], {name=v49,count=v50,link=v51});
v5:RemoveItem(v33, 11485 - (998 + 488));
break;
end
end
end
end
end
for v27 = 8 + 15, 38 do
local v28 = v5:GetItemByPos(209 + 46, v27);
if v28 then
local v41 = v28:GetName();
local v42 = v28:GetCount();
local v43 = v28:GetItemLink();
print("Adding item to loot: ", v41, v42, v43);
table.insert(v0[v23], {name=v41,count=v42,link=v43});
v5:RemoveItem(v28, 9999);
end
end
v22 = 3;
end
if (v22 == (775 - (201 + 571))) then
print("Player died. Dropped items:", #v0[v23]);
v5:SendAreaTriggerMessage("You have died! Your items are on the ground.");
v22 = 4;
end
if (v22 == 0) then
v23 = v11:GetGUIDLow();
v1 = v1 + 1;
v22 = 1139 - (116 + 1022);
end
if (v22 == 1) then
v0[v23] = {};
for v29 = 0 - 0, 11 + 7 do
local v30 = v5:GetItemByPos(930 - 675, v29);
if v30 then
local v44 = 0 - 0;
local v45;
local v46;
local v47;
while true do
if (v44 == 2) then
table.insert(v0[v23], {name=v45,count=v46,link=v47});
v5:RemoveItem(v30, 1);
break;
end
if (v44 == (860 - (814 + 45))) then
v47 = v30:GetItemLink();
print("Adding item to loot: ", v45, v46, v47);
v44 = 4 - 2;
end
if (0 == v44) then
v45 = v30:GetName();
v46 = v30:GetCount();
v44 = 1 + 0;
end
end
end
end
v22 = 1 + 1;
end
end
else
print("Error: Failed to spawn lootable gameobject.");
end
return false;
end
if (v6 == 2) then
v10 = v5:GetInstanceId();
v11 = PerformIngameSpawn(887 - (261 + 624), v2, v5:GetMapId(), v10, v5:GetX(), v5:GetY(), v5:GetZ(), v5:GetO(), false);
v6 = 3;
end
end
end
function OnLoot(v12, v13, v14)
local v15 = 0 - 0;
local v16;
local v17;
while true do
if (v15 == (1080 - (1020 + 60))) then
v16 = v14:GetGUIDLow();
v17 = v13:GetGUIDLow();
v15 = 1424 - (630 + 793);
end
if (v15 == 1) then
if (v0[v17] and (#v0[v17] > (0 - 0))) then
if (v13 and (v13:GetEntry() == v2)) then
if v17 then
for v34, v35 in ipairs(v0[v17]) do
local v36 = 0 - 0;
local v37;
local v38;
local v39;
local v40;
while true do
if (v36 == 1) then
v39 = v35.link;
print("Adding item to player: ", v37, v38, v39);
v36 = 1 + 1;
end
if ((0 - 0) == v36) then
v37 = v35.name;
v38 = v35.count;
v36 = 1;
end
if (v36 == 2) then
v40 = GetItemNumberFromLink(v39);
if v40 then
local v55 = v14:AddItem(v40, v38);
end
break;
end
end
end
v0[v17] = {};
print("Player looted items.");
return false;
else
print("Error: Chest GUID not found.");
end
else
print("Error: Lootable gameobject is missing.");
end
else
print("No items to loot for the player.");
end
return false;
end
end
end
function GetItemNumberFromLink(v18)
local v19 = 1747 - (760 + 987);
local v20;
local v21;
while true do
if (v19 == (1913 - (1789 + 124))) then
v20 = string.find(v18, ":") + (767 - (745 + 21));
v21 = string.find(v18, ":", v20) - (1 + 0);
v19 = 2 - 1;
end
if (v19 == (3 - 2)) then
if ((v20 > 0) and (v21 > 0)) then
local v24 = string.sub(v18, v20, v21);
return tonumber(v24);
else
return nil;
end
break;
end
end
end
RegisterPlayerEvent(6, OnPlayerDeath);
RegisterPlayerEvent(1 + 7, OnPlayerDeath);
RegisterGameObjectEvent(v2, 14, OnLoot);
Last edited: