Сделал спавн крипов, сделал босса с которого падает предмет, всё работает отлично.
Но, когда я первый раз умер в кастомке, где умер, создается такой же персонаж и становится нейтралом.
При каждой его смерти, где он умер будет спавниться ещё один персонаж "нейтрал" , и их становится миллион, если их убивать.
В чём ошибка?
Код :
Но, когда я первый раз умер в кастомке, где умер, создается такой же персонаж и становится нейтралом.
При каждой его смерти, где он умер будет спавниться ещё один персонаж "нейтрал" , и их становится миллион, если их убивать.
В чём ошибка?
Код :
--------------------------------------------------------------------------------
-- Integer constants
--------------------------------------------------------------------------------
_G.nNEUTRAL_TEAM = 4
_G.nCREATURE_RESPAWN_TIME = 2
if CAddonTemplateGameMode == nil then
CAddonTemplateGameMode = class({})
end
xpTable = {0,250,500,750,1000,1250,1500,1750,2000,2250,2500,2750,3000,3250,3500,3750,4000,4250,
4500,4750,5000,5250,5500,5750,6000,6250,6500,6750,7000,7250,7250,7250,7250,7250,7250,7250,7250,
7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250} -- 52
function Precache( context )
--[[
Precache things we know we'll use. Possible file types include (but not limited to):
PrecacheResource( "model", "*.vmdl", context )
PrecacheResource( "soundfile", "*.vsndevts", context )
PrecacheResource( "particle", "*.vpcf", context )
PrecacheResource( "particle_folder", "particles/folder", context )
]]
end
function OnEntityKilled (event)
local killedEntity = EntIndexToHScript(event.entindex_killed)
local sCreatureName = killedEntity:GetUnitName()
local vSpawnLoc = killedEntity.vSpawnLoc
if (vSpawnLoc == nil) then
print ("location not found")
vSpawnLoc = killedEntity:GetOrigin()
end
if (sCreatureName ~= "npc_dota_neutral_kobold_taskmaster") then
GameRules:GetGameModeEntity():SetContextThink (string.format( "CreatureThink_%d", event.entindex_killed ), function () SpawnUnit(sCreatureName, vSpawnLoc) end, nCREATURE_RESPAWN_TIME)
else
local newItem = CreateItem("item_relic", nil, nil)
newItem:SetPurchaseTime(0)
CreateItemOnPositionSync(killedEntity:GetOrigin(), newItem)
newItem:LaunchLoot(false, 300, 0.75, killedEntity:GetOrigin())
end
end
function SpawnUnit (sCreatureName, vSpawnLoc)
local hUnit = CreateUnitByName(sCreatureName, vSpawnLoc, true, nil, nil, nNEUTRAL_TEAM )
hUnit.vSpawnLoc = vSpawnLoc
end
-- Create the game mode when we activate
function Activate()
GameRules.AddonTemplate = CAddonTemplateGameMode()
GameRules.AddonTemplate:InitGameMode()
ListenToGameEvent("entity_killed", OnEntityKilled, nil)
local allUnits = FindUnitsInRadius(nNEUTRAL_TEAM,
Vector(0, 0, 0),
nil,
FIND_UNITS_EVERYWHERE,
DOTA_UNIT_TARGET_TEAM_FRIENDLY,
DOTA_UNIT_TARGET_ALL,
DOTA_UNIT_TARGET_FLAG_NONE,
FIND_ANY_ORDER,
false)
print (allUnits)
for k, hUnit in pairs( allUnits ) do
hUnit.vSpawnLoc = hUnit:GetOrigin()
hUnit.vSpawnVector = hUnit:GetForwardVector()
print (hUnit.vSpawnVector)
end
end
function CAddonTemplateGameMode:InitGameMode()
print( "Template addon is loaded." )
GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
end
-- Evaluate the state of the game
function CAddonTemplateGameMode:OnThink()
GameRules:GetGameModeEntity():SetUseCustomHeroLevels( true )
GameRules:GetGameModeEntity():SetCustomHeroMaxLevel( 52 )
GameRules:GetGameModeEntity():SetCustomXPRequiredToReachNextLevel( xpTable )
print( "Template addon is loaded." )
GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
if GameRules:State_Get() == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
--print( "Template addon script is running." )
elseif GameRules:State_Get() >= DOTA_GAMERULES_STATE_POST_GAME then
return nil
end
return 1
end
-- Integer constants
--------------------------------------------------------------------------------
_G.nNEUTRAL_TEAM = 4
_G.nCREATURE_RESPAWN_TIME = 2
if CAddonTemplateGameMode == nil then
CAddonTemplateGameMode = class({})
end
xpTable = {0,250,500,750,1000,1250,1500,1750,2000,2250,2500,2750,3000,3250,3500,3750,4000,4250,
4500,4750,5000,5250,5500,5750,6000,6250,6500,6750,7000,7250,7250,7250,7250,7250,7250,7250,7250,
7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250,7250} -- 52
function Precache( context )
--[[
Precache things we know we'll use. Possible file types include (but not limited to):
PrecacheResource( "model", "*.vmdl", context )
PrecacheResource( "soundfile", "*.vsndevts", context )
PrecacheResource( "particle", "*.vpcf", context )
PrecacheResource( "particle_folder", "particles/folder", context )
]]
end
function OnEntityKilled (event)
local killedEntity = EntIndexToHScript(event.entindex_killed)
local sCreatureName = killedEntity:GetUnitName()
local vSpawnLoc = killedEntity.vSpawnLoc
if (vSpawnLoc == nil) then
print ("location not found")
vSpawnLoc = killedEntity:GetOrigin()
end
if (sCreatureName ~= "npc_dota_neutral_kobold_taskmaster") then
GameRules:GetGameModeEntity():SetContextThink (string.format( "CreatureThink_%d", event.entindex_killed ), function () SpawnUnit(sCreatureName, vSpawnLoc) end, nCREATURE_RESPAWN_TIME)
else
local newItem = CreateItem("item_relic", nil, nil)
newItem:SetPurchaseTime(0)
CreateItemOnPositionSync(killedEntity:GetOrigin(), newItem)
newItem:LaunchLoot(false, 300, 0.75, killedEntity:GetOrigin())
end
end
function SpawnUnit (sCreatureName, vSpawnLoc)
local hUnit = CreateUnitByName(sCreatureName, vSpawnLoc, true, nil, nil, nNEUTRAL_TEAM )
hUnit.vSpawnLoc = vSpawnLoc
end
-- Create the game mode when we activate
function Activate()
GameRules.AddonTemplate = CAddonTemplateGameMode()
GameRules.AddonTemplate:InitGameMode()
ListenToGameEvent("entity_killed", OnEntityKilled, nil)
local allUnits = FindUnitsInRadius(nNEUTRAL_TEAM,
Vector(0, 0, 0),
nil,
FIND_UNITS_EVERYWHERE,
DOTA_UNIT_TARGET_TEAM_FRIENDLY,
DOTA_UNIT_TARGET_ALL,
DOTA_UNIT_TARGET_FLAG_NONE,
FIND_ANY_ORDER,
false)
print (allUnits)
for k, hUnit in pairs( allUnits ) do
hUnit.vSpawnLoc = hUnit:GetOrigin()
hUnit.vSpawnVector = hUnit:GetForwardVector()
print (hUnit.vSpawnVector)
end
end
function CAddonTemplateGameMode:InitGameMode()
print( "Template addon is loaded." )
GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
end
-- Evaluate the state of the game
function CAddonTemplateGameMode:OnThink()
GameRules:GetGameModeEntity():SetUseCustomHeroLevels( true )
GameRules:GetGameModeEntity():SetCustomHeroMaxLevel( 52 )
GameRules:GetGameModeEntity():SetCustomXPRequiredToReachNextLevel( xpTable )
print( "Template addon is loaded." )
GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
if GameRules:State_Get() == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
--print( "Template addon script is running." )
elseif GameRules:State_Get() >= DOTA_GAMERULES_STATE_POST_GAME then
return nil
end
return 1
end
Последнее редактирование модератором: