LuaSlinger»Friendly Party Roll For Chest

Friendly Party Roll For Chest

Friendly Party Roll for Chest

If you are playing with friends, this script can roll on chests for the entire party, this is mostly for people playing with friends, as it can be abused otherwise. If you have a set of friends you play with frequently, you can set this up to quickly roll on chests so that someone else doesn't nick the loot first :)
Requirements: none, just bind to a macro if you want.

if (GetNumPartyMembers() == 0) then
    PlaySound("igQuestFailed")
    DEFAULT_CHAT_FRAME:AddMessage("You cannot roll, because you are not in a party");
else
    SendChatMessage("--[   ROLLING FOR CHEST   ] ----------------------", "PARTY");

    -- Create some global variables
    winner = 0;  -- the winner
    winningValue = -1;  -- the winning value
    randomValues = {};
    partyMembers = {};
    randomValues[0] = math.random(1, 100);
    partyMembers[0] = UnitName("player");

    for count = 1, GetNumPartyMembers(), 1 do
        randomValues[count] = math.random(1, 100);
        partyMembers[count] = UnitName("party" .. count);
    end

    -- Work out who the winner is before printing it.
    for count = 0, GetNumPartyMembers(), 1 do
        if (randomValues[count] > winningValue) then
            winner = count;
            winningValue = randomValues[count];
        end
    end

    -- Print values...
    for count = 0, GetNumPartyMembers(), 1 do
        s = partyMembers[count] .. ": " .. randomValues[count];
        if (winner == count) then
            s = "> " .. string.upper(s) .. " < ";
        else
            s = "    " .. s
        end
        SendChatMessage(s, "PARTY");
    end 

    SendChatMessage("------------------------------------------------------------", "PARTY");
end