Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.98 KB | None | 0 0
  1. GAME_BUSH_TICK_TIME = 100
  2.  
  3. function ITT:SpawnBushes()
  4. Containers:SetDisableItemLimit(true)
  5. Containers:UsePanoramaInventory(false)
  6.  
  7. local bushSpawnerTable = GameRules.BushInfo["BushSpawnInfo"]["SpawnerNames"]
  8. GameRules.Bushes = {}
  9. Spawns.bushCount = {}
  10. Spawns.bushCount["World"]= {{}}
  11. Spawns.bushCount["Island"]= {{},{},{},{}}
  12. for bushItem,_ in pairs(bushSpawnerTable) do
  13. Spawns.bushCount["World"][1][bushItem] = 0
  14. for i,_ in pairs(REGIONS) do
  15. Spawns.bushCount["Island"][i][bushItem] = 0
  16. end
  17. end
  18.  
  19. if GameRules.GameModeSettings.custom.fixed_bush_spawning then
  20. spawners = GetFixedBushLocations(bushSpawnerTable)
  21. for bushName, bushSpawners in pairs(spawners) do
  22. for _,spawner in pairs(bushSpawners) do
  23. local pos = spawner:GetAbsOrigin()
  24. CreateBush(bushName, pos)
  25. CreateBushContainer(bushName, pos)
  26. end
  27. end
  28. else
  29. GameRules.PredefinedBushLocations = GetPredefinedBushLocations(bushSpawnerTable)
  30. local locationType = GameRules.GameModeSettings["BUSH_SPAWNING_LOCATION"]
  31. local regionType = GameRules.BushSpawnRegion
  32. for bushItem,_ in pairs(bushSpawnerTable) do
  33. SpawnBushes(bushItem, regionType, locationType)
  34. end
  35. end
  36.  
  37. local bushCount = #GameRules.Bushes
  38. print("Spawned "..bushCount.." bushes total")
  39.  
  40. Timers:CreateTimer(function()
  41. ITT:OnBushThink()
  42. if GameRules.DevMode then
  43. return 10
  44. end
  45. return GAME_BUSH_TICK_TIME
  46. end)
  47. end
  48.  
  49.  
  50. function SpawnBushes(bushItem, regionType, locationType)
  51. if regionType == "World" then
  52. SpawnBushesCommon(bushItem, locationType, regionType, WORLD)
  53. elseif regionType == "Island" then
  54. SpawnBushesCommon(bushItem, locationType,regionType, REGIONS)
  55. end
  56. end
  57.  
  58. function SpawnBushesCommon(bushItem, locationType, regionType, regions)
  59. local bushMaxTable = GameRules.BushInfo["BushSpawnInfo"]['Max'][regionType]
  60. for i,region in pairs(regions) do
  61. for count=1,bushMaxTable[bushItem] do
  62. local spawnLocation = GetBushSpawnLocation(bushItem, region, locationType)
  63. if spawnLocation then
  64. CreateBush(bushItem, spawnLocation)
  65. CreateBushContainer(bushItem, spawnLocation)
  66. end
  67. Spawns.bushCount[regionType][i][bushItem] = Spawns.bushCount[regionType][i][bushItem] + 1
  68. end
  69. end
  70. end
  71.  
  72. function GetFixedBushLocations(spawnerTable)
  73. local allSpawners = Entities:FindAllByClassname("npc_dota_spawner")
  74. local bushSpawners = {}
  75. for bushItem,_ in pairs(spawnerTable) do
  76. bushSpawners[bushItem] = {}
  77. end
  78. for _,spawner in pairs(allSpawners) do
  79. local name = spawner:GetName()
  80. if string.find(name, "_fixedbush_") then
  81. local cutoff = string.find(name,"s")
  82. local bushName = "npc_".. string.gsub(string.sub(name, cutoff), "spawner_npc_", "")
  83. bushName = bushName:gsub("_fixedbush_", "_bush_")
  84. table.insert(bushSpawners[bushName], spawner)
  85. end
  86. end
  87. return bushSpawners
  88. end
  89.  
  90. function GetPredefinedBushLocations(bushSpawnerTable)
  91. local allSpawners = Entities:FindAllByClassname("npc_dota_spawner")
  92. local bushSpawners = {}
  93. for bushItem,_ in pairs(bushSpawnerTable) do
  94. bushSpawners[bushItem] = {}
  95. end
  96. for _,spawner in pairs(allSpawners) do
  97. local spawnerName = spawner:GetName()
  98. if string.find(spawnerName, "_bush_") then
  99. local cutoff = string.find(spawnerName,"s")
  100. local bushName = "npc_".. string.gsub(string.sub(spawnerName, cutoff), "spawner_npc_", "")
  101. -- local itemName = "item_"..bushName
  102. -- print("bushname " .. bushName)
  103. table.insert(bushSpawners[bushName],spawner)
  104. end
  105. end
  106. return bushSpawners
  107. end
  108.  
  109. function GetBushSpawnLocation(bushItem, region, locationType)
  110. local location
  111. if locationType == "random" then
  112. location = GetRandomBushLocation(region, bushItem)
  113. elseif locationType == "predefined" then
  114. location = GetPredefinedBushLocation(region, bushItem)
  115. elseif locationType == "mix" then
  116. if RollPercentage(50) then
  117. location = GetRandomBushLocation(region, bushItem)
  118. else
  119. location = GetPredefinedBushLocation(region, bushItem)
  120. end
  121. end
  122. return location
  123. end
  124.  
  125. -- Creates a neutral on a predefined spawner position
  126. function GetPredefinedBushLocation(region, bushItem)
  127. local locations = GetPredefinedBushLocationsOnRegion(region, bushItem)
  128. if not locations then
  129. print("ERROR: no spawner locations stored for "..bushItem)
  130. end
  131. return GetEmptyLocation(locations)
  132. end
  133.  
  134. function GetPredefinedBushLocationsOnRegion(region, bushItem)
  135. local locations = {}
  136. for _,predefinedLocation in pairs(GameRules.PredefinedBushLocations[bushItem]) do
  137. local location = predefinedLocation:GetAbsOrigin()
  138. if IsVectorInBounds(location, region[1], region[2], region[4], region[3]) and not IsNearABush(location, bushItem) then
  139. table.insert(locations, location)
  140. end
  141. end
  142. return locations
  143. end
  144.  
  145. function IsNearABush(location, bushItem)
  146. local nearbyBushes = Entities:FindAllByClassnameWithin("npc_dota_creature", location, 1500)
  147. for _,bushName in pairs(nearbyBushes) do
  148. if bushName:GetUnitName() == bushItem then
  149. return true
  150. end
  151. end
  152. return false
  153. end
  154.  
  155. -- Creates a nutral on a random location
  156. function GetRandomBushLocation(region, bushItem)
  157. local location = GetRandomVectorGivenBounds(region[1], region[2], region[3], region[4])
  158. while IsNearABush(location, bushItem) do
  159. location = GetRandomVectorGivenBounds(region[1], region[2], region[3], region[4])
  160. end
  161. return location
  162. end
  163.  
  164. function ITT:OnBushThink()
  165. print("OnBushThink Creating Items on Bushes")
  166.  
  167. local bushes = GameRules.Bushes
  168.  
  169. for k,bush in pairs(bushes) do
  170. if bush.RngWeight == nil then --rng weight maks it so there's a chance a bush won't spawn but you won't get rng fucked
  171. bush.RngWeight = 1 --if rng weight doesnt exist declare it to a value that's unlikely to spawn for the first few ticks
  172. end
  173.  
  174. local rand = RandomInt(-4,4) --randomize between -4 and +4, since the min is 0 with the best rng on the minimum number you will still not get a spawn
  175. local numItems = #(bush.container:GetAllItems())
  176. --print("Bush name: "..bush:GetUnitName())
  177. if rand + bush.RngWeight >= 5 and numItems < 6 then
  178. bush.RngWeight = bush.RngWeight - 1 --if spawn succeeds reduce the odds of the next spawn
  179.  
  180. local bush_name = bush.name
  181. local bushTable = GameRules.BushInfo["Bushes"][bush_name]
  182. local possibleChoices = TableCount(bushTable)
  183. local randomN = tostring(RandomInt(1, possibleChoices))
  184. local bush_random_item = bushTable[randomN]
  185.  
  186. --GiveItemStack(bush, bush_random_item)
  187. local item = CreateItem(bush_random_item, nil, nil)
  188. bush.container:AddItemBush(item) --AddItem with stack handling
  189. print("Added " .. bush_random_item .. " to ".. bush_name .. " " .. bush:GetEntityIndex())
  190.  
  191. -- Particle glow
  192. AddBushGlow(bush)
  193. else
  194. bush.RngWeight = bush.RngWeight + 1 --if spawn fails increase odds for next run
  195. --print("Spawn Failed " .. bush:GetUnitName() .. " " .. bush:GetEntityIndex())
  196. end
  197. end
  198. --print("bush spawning time: " .. math.floor(GameRules:GetGameTime()))
  199. return GAME_BUSH_TICK_TIME
  200. end
  201.  
  202. function CreateBush(name, position)
  203. local bush
  204. -- Scout bush has to be a unit for invisibility
  205. if name:match("scout") then
  206. bush = CreateUnitByName(name, position, true, nil, nil, DOTA_TEAM_NEUTRALS)
  207. else
  208. bush = CreateItemOnPositionSync(position, CreateItem(name:gsub("npc","item"), nil, nil))
  209. end
  210. bush.name = name --keep the name as npc to not need to change the kv table
  211.  
  212. table.insert(GameRules.Bushes, bush)
  213.  
  214. CreateBushContainer(name, bush)
  215. --Containers:SetDefaultInventory(bush, container)
  216. end
  217.  
  218. function AddBushGlow(entity)
  219. if not entity.whiteGlowParticle then
  220. --Particle refused to show through fog for an hour so give vision instead
  221. for _,v in pairs(VALID_TEAMS) do AddFOWViewer(v, entity:GetAbsOrigin(), 100, 0.1, false) end
  222.  
  223. local particleName = "particles/custom/dropped_item_white.vpcf"
  224. entity.whiteGlowParticle = ParticleManager:CreateParticle(particleName, PATTACH_CUSTOMORIGIN, entity)
  225. ParticleManager:SetParticleControlEnt(entity.whiteGlowParticle, 0, entity, PATTACH_POINT_FOLLOW, "attach_center", entity:GetAbsOrigin(), true)
  226. end
  227. end
  228.  
  229.  
  230. function RemoveBushGlow(entity)
  231. if entity.whiteGlowParticle then
  232. ParticleManager:DestroyParticle(entity.whiteGlowParticle, true)
  233. entity.whiteGlowParticle = nil
  234. end
  235. end
  236.  
  237. function CreateBushContainer(name, bush)
  238. local cont = Containers:CreateContainer({
  239. layout = {3,3},
  240. --skins = {"Hourglass"},
  241. headerText = name,
  242. buttons = {"Grab All"},
  243. position="entity", --"mouse",--"900px 200px 0px",
  244. draggable = false,
  245. closeOnOrder= true,
  246. items = {},
  247. entity = bush,
  248. range = DEFAULT_TRANSFER_RANGE,
  249. OnDragWorld = true,
  250.  
  251. OnLeftClick = function(playerID, container, unit, item, slot)
  252.  
  253. if ContainerTransferItem(container, bush, unit, item) then
  254. unit:StartGesture(ACT_DOTA_ATTACK)
  255. unit:EmitSound("bush.rustle")
  256. else
  257. SendErrorMessage(playerID, "#error_inventory_full")
  258. end
  259.  
  260. if container:GetNumItems() == 0 then RemoveBushGlow(bush) end
  261. end,
  262.  
  263. OnRightClick = function(playerID, container, unit, item, slot)
  264. if ContainerTransferItem(container, bush, unit, item) then
  265. unit:StartGesture(ACT_DOTA_ATTACK)
  266. unit:EmitSound("bush.rustle")
  267. else
  268. SendErrorMessage(playerID, "#error_inventory_full")
  269. end
  270.  
  271. if container:GetNumItems() == 0 then RemoveBushGlow(bush) end
  272. end,
  273.  
  274. OnButtonPressed = function(playerID, container, unit, button, buttonName)
  275. if button == 1 then
  276. local items = container:GetAllItems()
  277. unit:StartGesture(ACT_DOTA_ATTACK)
  278. unit:EmitSound("bush.rustle")
  279. local got_atleast_one = false
  280. local atleast_one_left = false
  281. local stack_full = false
  282. local stack
  283. local max_stack
  284. local inventory_space = GetNumItemsInInventory(unit)
  285.  
  286. for _,item in ipairs(items) do
  287. local cantake = CanTakeItem(unit, item)
  288. if cantake then -- Truthy
  289. if (cantake == true and inventory_space < 6) or (cantake ~= true and not stack_full) then
  290. if cantake == true then -- Inventory has space
  291. inventory_space = inventory_space + 1
  292. else -- Item in question can stack
  293. if not stack then
  294. stack = cantake:GetCurrentCharges()
  295. max_stack = GameRules.ItemKV[cantake:GetAbilityName()]["MaxStacks"]
  296. end
  297.  
  298. local grab_stack = item:GetCurrentCharges()
  299. if stack + grab_stack >= max_stack then
  300. stack_full = true
  301. else
  302. stack = stack + grab_stack
  303. end
  304. end
  305.  
  306. got_atleast_one = true
  307.  
  308. ContainerTransferItem(container, bush, unit, item)
  309. if unit:HasModifier("modifier_telegather") then
  310. local didTeleport = TeleportItem(unit,item)
  311. elseif unit:HasModifier("modifier_herbtelegather") then
  312. local didTeleport = TeleportItemHerb(unit,item)
  313. end
  314. end
  315. else
  316. atleast_one_left = true
  317. end
  318. end
  319.  
  320. if not got_atleast_one then
  321. if not atleast_one_left then
  322. SendErrorMessage(playerID, "#error_bush_empty")
  323. else
  324. SendErrorMessage(playerID, "#error_inventory_full")
  325. end
  326. end
  327.  
  328. container:Close(playerID)
  329.  
  330. if atleast_one_left then
  331. RemoveBushGlow(bush)
  332. end
  333. end
  334. end,
  335.  
  336. OnEntityOrder = function(playerID, container, unit, target)
  337. --[[if (bush:GetUnitName() == "npc_bush_scout" and unit:GetClassname() ~= "npc_dota_hero_lion") then
  338. SendErrorMessage(playerID, "#error_scout_only_bush")
  339. return --exits if bush is used by anything other than a scout
  340. end
  341.  
  342. if (bush:GetUnitName() == "npc_bush_thief" and unit:GetClassname() ~= "npc_dota_hero_riki") then
  343. SendErrorMessage(playerID, "#error_thief_only_bush")
  344. return --exits if bush is used by anything other than a thief
  345. end]]
  346.  
  347. print("ORDER ACTION loot box: ", playerID)
  348. container:Open(playerID)
  349. unit:Stop()
  350. unit:Hold()
  351. end,
  352. })
  353.  
  354. bush.container = cont
  355. bush.phys = phys
  356. end
  357.  
  358. function TeleportItem(hero,originalItem)
  359. local targetFire = hero.targetFire
  360. local newItem = CreateItem(originalItem:GetName(), nil, nil)
  361. local teleportSuccess = false
  362.  
  363. local telegatherBuff = hero:FindModifierByName("modifier_telegather")
  364. local telegatherAbility = telegatherBuff:GetAbility()
  365. local percentChance = telegatherAbility:GetSpecialValueFor("percent_chance")
  366. --print("Teleporting item : " .. telegatherAbility:GetAbilityName() .. ", " .. percentChance .."% chance")
  367.  
  368. local itemList = {"item_tinder", "item_flint", "item_stone", "item_stick", "item_bone", "item_meat_raw", "item_meat_cooked", "item_crystal_mana", "item_ball_clay", "item_hide_elk", "item_hide_wolf", "item_hide_bear", "item_magic_raw"}
  369. for key,value in pairs(itemList) do
  370. if value == originalItem:GetName() then
  371. local diceRoll = RandomFloat(0,100)
  372. --print("telegather roll " .. diceRoll)
  373. if diceRoll <= percentChance then
  374. --print( "Teleporting Item", originalItem:GetName())
  375. hero:RemoveItem(originalItem)
  376. local itemPosition = targetFire:GetAbsOrigin() + RandomVector(RandomInt(100,150))
  377. CreateItemOnPositionSync(itemPosition,newItem)
  378. newItem:SetOrigin(itemPosition)
  379. hero:EmitSound("Hero_Zuus.Attack")
  380. teleportSuccess = true
  381. return teleportSuccess
  382. end
  383. end
  384. end
  385. return teleportSuccess
  386. end
  387.  
  388.  
  389.  
  390. function TeleportItemHerb(hero,originalItem)
  391. local targetFire = hero.targetFire
  392. local newItem = CreateItem(originalItem:GetName(), nil, nil)
  393. local teleportSuccess = false
  394.  
  395. local herbtelegatherBuff = hero:FindModifierByName("modifier_herbtelegather")
  396. local telegatherAbility = herbtelegatherBuff:GetAbility()
  397. local percentChance = telegatherAbility:GetSpecialValueFor("percent_chance")
  398. --print("Teleporting item : " .. telegatherAbility:GetAbilityName() .. ", " .. percentChance .."% chance")
  399.  
  400. local itemList = {"item_herb_blue", "item_herb_butsu", "item_herb_orange", "item_herb_purple", "item_herb_yellow", "item_thistles", "item_river_root", "item_river_stem", "item_acorn", "item_acorn_magic", "item_mushroom", "item_spirit_water", "item_spirit_wind"}
  401.  
  402. for key,value in pairs(itemList) do
  403. if value == originalItem:GetName() then
  404. local diceRoll = RandomFloat(0,100)
  405. --print("telegather roll " .. diceRoll)
  406. if diceRoll <= percentChance then
  407. --print( "Teleporting Item", originalItem:GetName())
  408. hero:RemoveItem(originalItem)
  409. local itemPosition = targetFire:GetAbsOrigin() + RandomVector(RandomInt(100,150))
  410. CreateItemOnPositionSync(itemPosition,newItem)
  411. newItem:SetOrigin(itemPosition)
  412. hero:EmitSound("Hero_Zuus.Attack")
  413. teleportSuccess = true
  414. return teleportSuccess
  415. end
  416. end
  417. end
  418. return teleportSuccess
  419. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement