Hey there.
I need some help with making this bossloot system. But first I need to tell you something about how the loot goes in my orpg.
The normal loot system is done and the reward loot system aswel.
Normal loot system:
A unit dies and drops loot. Then a unit called 'lootbag' spawns for the killing unit, and the item that dropped will be given to his inventory. Then when the player clicks the item in his 'lootbag''s inventory he will obtain the item in his own inventory.
Reward loot system:
Same as above, but whenever there are 2 or more items in 1 lootbag, the player can only chose one of them to go to his real inventory. After clicking an item, the others will disappear.
Now here's the code of the boss loot system I'm trying to make. Please take a look at it. I described quite a few things inside the trigger. There's just one thing I'm kinda stuck with, and I would like to ask someone to help me out with it.
EDIT:
Hmm the thing that will currently help me most is if I can do various actions for a group withoud having to use FirstOfGroup so I don't have to remove units out of a group. Is that the 'ForGroup' command? I have no idea how that actually works.
I need some help with making this bossloot system. But first I need to tell you something about how the loot goes in my orpg.
The normal loot system is done and the reward loot system aswel.
Normal loot system:
A unit dies and drops loot. Then a unit called 'lootbag' spawns for the killing unit, and the item that dropped will be given to his inventory. Then when the player clicks the item in his 'lootbag''s inventory he will obtain the item in his own inventory.
Reward loot system:
Same as above, but whenever there are 2 or more items in 1 lootbag, the player can only chose one of them to go to his real inventory. After clicking an item, the others will disappear.
Now here's the code of the boss loot system I'm trying to make. Please take a look at it. I described quite a few things inside the trigger. There's just one thing I'm kinda stuck with, and I would like to ask someone to help me out with it.
JASS:
//=======================================================================================================================
// Bossloot
// How does it work:
// With CreateBossLoot(boss, players, item1, item2, item3, item4, item5, item6) I'm able to let a boss drop loot
// this loot will be given to a treasure chest. Each player that owned a hero that was in the area of killing the boss
// will get a treasure chest (with invisibility) for himself. This treasure chest has the dropped items.
// (A treasure chest is a unit with a 6 slot inventory)
// When clicking an item inside the treasure chest's inventory the player will roll for the item.
// Each player is able to roll 3 times and the first roll gets +40 and the second roll +20.
// When the Treasure Chests disappear (after the 20 second timer) the loot where players rolled will be distributed
// to the highest rollers.
// If nobody rolled on an item a random player will also obtain that item.
//
// So what basically happens is:
// a) A unit clicks the item in his Treasure Chest.
// b) A roll will appear and the player's roll on that item will be saved until the Treasure Chest disappears.
// c) The player with the highest roll on an item will obtain the item after the Treasure Chest disappears.
//
//
// Notes:
// 1) It shouldn't be possible that if 2 players roll the same amount none/both of them gets the item.
// 2)
//=======================================================================================================================
library bossloot
globals
constant integer array RollBonus[]
constant integer array FirstRoll[]
constant integer array SecondRoll[]
constant integer array ThirdRoll[]
constant integer array FirstItem[]
constant integer array SecondItem[]
constant integer array ThirdItem[]
constant timer TreasureChestDuration[]
endglobals
private function LootDistribution takes nothing returns nothing
///This is the point I'm currently stuck a littlebit.
///I want the loot to be distributed here.
///So I want this function to check which players won loot by checking their rolls
///After that I want this function to create an item of that itemid for those players then
endfunction
///unit boss = killed boss
///group players = Hero's that killed the boss together
///integer item1-6 means the item id's. A boss can drop up to a maximum of 6 items.
function CreateBossLoot takes unit boss, group players, integer item1, integer item2, integer item3, integer item4, integer item5, integer item6 returns nothing
local real x = GetUnitX(boss)
local real y = GetUnitY(boss)
local real face = GetUnitFacing(boss)
local player p = GetOwningPlayer(u)
local unit chest
local item reward
local unit u
local integer timerid = GetPlayerId(GetOwningPlayer(FirstOfGroup(players)))
loop
set u FirstOfGroup(players)
exitwhen u = null
set chest = CreateUnit(GetOwningPlayer(u),'n00H', x, y, face)
call UnitApplyTimedLife(chest, 'BTLF', 20.)
if item1 > 0 then
set reward = CreateItem(item1, x, y)
call UnitAddItem(chest, reward)
endif
if item2 > 0 then
set reward = CreateItem(item2, x, y)
call UnitAddItem(chest, reward)
endif
if item3 > 0 then
set reward = CreateItem(item3, x, y)
call UnitAddItem(chest, reward)
endif
if item4 > 0 then
set reward = CreateItem(item4, x, y)
call UnitAddItem(chest, reward)
endif
if item5 > 0 then
set reward = CreateItem(item5, x, y)
call UnitAddItem(chest, reward)
endif
if item6 > 0 then
set reward = CreateItem(item6, x, y)
call UnitAddItem(chest, reward)
endif
call GroupRemoveUnit(players, u)
endloop
call TimerStart(TreasureChestDuration[timerid],20.,false,function LootDistribution)
///Its impossible for a player to defeat 2 bosses within 20 seconds of eachother. But it is possible that 2 bosses
///die within 20 seconds of eachother from multiple players at different zones in the map.
///Thats why I used the array for TreasureChestDuration. Now it starts the timer for a player that killed the boss.
endfunction
private function itemPickUpCheck takes nothing returns boolean
return GetUnitTypeId(GetManipulatingUnit()) == 'n00H' ///This is the id of the Treasure Chest///
endfunction
private function itemPickUp takes nothing returns nothing
local integer i = GetPlayerId(GetOwningPlayer(GetManipulatingUnit()))
local unit u
local string name = GetPlayerName(Player(i))
local integer chance
local string bonusstring
local string laststring
///Rolling
set chance = GetRandomInt(0,100)
if RollBonus[i] == 40 then
set FirstRoll[i] = chance + RollBonus[i]
set FirstItem[i] = GetItemTypeId(GetManipulatedItem())
set bonusstring = " |cff00ff00(+40)|r for "
set laststring = " on his |cff00ff00first|r roll!"
elseif RollBonus[i] == 20 then
set SecondRoll[i] = chance + RollBonus[i]
set SecondItem[i] = GetItemTypeId(GetManipulatedItem())
set bonusstring = " |cffffde08(+20)|r for "
set laststring = " on his |cffffde08second|r roll!"
elseif RollBonus[i] == 0 then
set ThirdRoll[i] = chance + RollBonus[i]
set ThirdItem[i] = GetItemTypeId(GetManipulatedItem())
set bonusstring = " (+0) for "
set laststring = " on his third roll!"
endif
set msg = (name+(" has rolled "+(I2S(chance+RollBonus[i])+((bonusstring)+(GetItemName(GetManipulatedItem()))+(laststring)))))
loop
exitwhen i > GetPlayers()
call DisplayTimedTextToPlayer(Player(i),0,0,10,msg)
set i = i + 1
endloop
endfunction
private function itemPickUpCheck takes nothing returns boolean
return GetUnitTypeId(GetManipulatingUnit()) == 'n00H' ///This is the id of the Treasure Chest///
endfunction
private function init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_USE_ITEM)
call TriggerAddAction(trig,function itemPickUp)
call TriggerAddCondition(trig,Condition(function itemPickUpCheck))
endfunction
endlibrary
EDIT:
Hmm the thing that will currently help me most is if I can do various actions for a group withoud having to use FirstOfGroup so I don't have to remove units out of a group. Is that the 'ForGroup' command? I have no idea how that actually works.
Last edited: