Advertisement
Guest User

Random Item Drops LUA

a guest
Aug 30th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. --InitGameMode() requires
  2. --Hook
  3. --ListenToGameEvent( "entity_killed", Dynamic_Wrap( CAddonTemplateGameMode, 'OnEntityKilled' ), self )
  4.  
  5. --RANDOM ITEM DROPS
  6.  
  7. -- Read and assign configurable keyvalues if applicable
  8. function CAddonTemplateGameMode:_ReadGameConfiguration()
  9. local kv = LoadKeyValues( "scripts/maps/" .. GetMapName() .. ".txt" )
  10. kv = kv or {} -- Handle the case where there is not keyvalues file
  11.  
  12. self:_ReadLootItemDropsConfiguration( kv["ItemDrops"] )
  13.  
  14. end
  15.  
  16. -- If random drops are defined read in that data
  17. function CAddonTemplateGameMode:_ReadLootItemDropsConfiguration( kvLootDrops )
  18.  
  19. self._vLootItemDropsList = {}
  20. --[[if type( kvLootDrops ) ~= "table" then
  21. return
  22. end
  23. for _,lootItem in pairs( kvLootDrops ) do
  24. table.insert( self._vLootItemDropsList, {
  25. szItemName = lootItem.Item or "",
  26. nChance = tonumber( lootItem.Chance or 0 )
  27. })
  28. end]]
  29.  
  30. table.insert ( self._vLootItemDropsList, {szItemName = "item_cloak_of_flames", nChance = })
  31.  
  32. print("Drop Table:")
  33. DeepPrintTable( self._vLootItemDropsList, nil, true )
  34. print("----")
  35. end
  36.  
  37. function CAddonTemplateGameMode:OnEntityKilled( event )
  38. local killedUnit = EntIndexToHScript( event.entindex_killed )
  39. print("1 mob dead")
  40. self:CheckForLootItemDrop( killedUnit )
  41. end
  42.  
  43. function CAddonTemplateGameMode:CheckForLootItemDrop( killedUnit )
  44. print("Drop")
  45. for _,itemDropInfo in pairs( self._vLootItemDropsList ) do
  46. print("Calculating Drops")
  47. if RollPercentage( itemDropInfo.nChance ) then
  48. print("Giving Drop")
  49. local newItem = CreateItem( "item_cloak_of_flames", nil, nil )
  50. newItem:SetPurchaseTime( 0 )
  51. if newItem:IsPermanent() and newItem:GetShareability() == ITEM_FULLY_SHAREABLE then
  52. item:SetStacksWithOtherOwners( true )
  53. end
  54. local drop = CreateItemOnPositionSync( killedUnit:GetAbsOrigin(), newItem )
  55. end
  56. end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement