Триггер проверяет что покупаемый предмет - из категории шлемов, проверяет что у юнита хватает ресурсов на его покупку. Если да, то герой получает тот шлем который он выбрал. Шлемы(виды предметов) и стоимости записанны в массив. Вот триггер:
Code
function Trig_Helmets_Func001C takes nothing returns boolean if ( not ( GetSpellAbilityId() != 'A024' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A025' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A026' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A027' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A029' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02A' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A028' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02B' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02C' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02E' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02F' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02G' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02H' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02J' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02K' ) ) then return false endif return true endfunction
function Trig_Helmets_Conditions takes nothing returns boolean if ( not Trig_Helmets_Func001C() ) then return false endif return true endfunction
function HeroPick takes location PointCasting returns unit local location PointPicked local unit PickHero set PointPicked = GetUnitLoc(GetEnumUnit()) if (( DistanceBetweenPoints(PointCasting, PointPicked) <= 200.00 ) and ( IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true ) and ( GetUnitTypeId(GetEnumUnit()) != 'n001' ) and ( GetUnitTypeId(GetEnumUnit()) != 'n008' )) then set PickHero = GetEnumUnit() else call DoNothing( ) endif call RemoveLocation(PointPicked) return PickHero endfunction
function Trig_Helmets_Actions takes nothing returns nothing local location PointCasting local integer ForIndex = 1 local integer AbilityIndex = 0 local unit PickedHero set bj_forLoopAIndex = 1 set bj_forLoopAIndexEnd = 10 loop exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd if ( GetSpellAbilityId() == udg_HelmetAbilities[ForIndex] ) then set AbilityIndex = ForIndex set ForIndex = ( ForIndex + 1 ) else set ForIndex = ( ForIndex + 1 ) endif set bj_forLoopAIndex = bj_forLoopAIndex + 1 endloop if ( AbilityIndex == 0 ) then return else call DoNothing( ) endif
set PointCasting = GetUnitLoc(GetSpellAbilityUnit()) call ForGroupBJ( GetUnitsInRectOfPlayer(GetPlayableMapRect(), GetOwningPlayer(GetSpellAbilityUnit())), function HeroPick) set PickedHero = HeroPick(PointCasting) call DestroyGroup(GetLastCreatedGroup()) if ( AbilityIndex > 1 ) then if (( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_HelmetGold[AbilityIndex] ) and ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_LUMBER) >= udg_HelmetUpgradePoints[AbilityIndex] ) and ( UnitHasItemOfTypeBJ(PickedHero, udg_HelmetItems[( AbilityIndex - 1 )]) == true ))then call RemoveItem( GetItemOfTypeFromUnitBJ(PickedHero, udg_HelmetItems[( AbilityIndex - 1 )]) ) call AddSpecialEffectTargetUnitBJ( "origin", PickedHero, "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" ) call DestroyEffectBJ( GetLastCreatedEffectBJ() ) call AdjustPlayerStateBJ( ( udg_HelmetGold[AbilityIndex] * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_GOLD ) call AdjustPlayerStateBJ( ( udg_HelmetUpgradePoints[AbilityIndex] * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_LUMBER ) call UnitAddItemByIdSwapped( udg_HelmetItems[AbilityIndex], PickedHero ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) else call PlaySoundOnUnitBJ( gg_snd_Warning, 100, PickedHero ) call TransmissionFromUnitWithNameBJ( GetPlayersAllies(GetOwningPlayer(PickedHero)), GetSpellAbilityUnit(), GetUnitName(GetSpellAbilityUnit()), null, ( GetUnitName(PickedHero) + ", bring me everything I require, and I will craft you whatever you want!" ), bj_TIMETYPE_ADD, 3.00, true ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) endif else if ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_HelmetGold[AbilityIndex] ) then call AddSpecialEffectTargetUnitBJ( "origin", PickedHero, "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" ) call DestroyEffectBJ( GetLastCreatedEffectBJ() ) call AdjustPlayerStateBJ( ( udg_HelmetGold[AbilityIndex] * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_GOLD ) call UnitAddItemByIdSwapped( udg_HelmetItems[AbilityIndex], PickedHero ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) else call PlaySoundOnUnitBJ( gg_snd_Warning, 100, PickedHero ) call TransmissionFromUnitWithNameBJ( GetPlayersAllies(GetOwningPlayer(PickedHero)), GetSpellAbilityUnit(), GetUnitName(GetSpellAbilityUnit()), null, ( GetUnitName(PickedHero) + ", bring me everything I require, and I will craft you whatever you want!" ), bj_TIMETYPE_ADD, 3.00, true ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) endif endif endfunction
//=========================================================================== function InitTrig_Helmets takes nothing returns nothing set gg_trg_Helmets = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Helmets, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_Helmets, Condition( function Trig_Helmets_Conditions ) ) call TriggerAddAction( gg_trg_Helmets, function Trig_Helmets_Actions ) endfunction
Но когда я в игре нажимаю на покупку предмета, игра вылетает и выдаёт Fatal Error. Помогите плз разобраться в чём дело и почему.
ммм, вообще я вижу локалки и прочее. Оптимизируй код, будь добр
Как? А что там ещё должно быть?)
Добавлено (17-07-2011, 12:38) --------------------------------------------- Вот код
Code
function Trig_Helmets_Conditions takes nothing returns boolean if ( not ( GetSpellAbilityId() != 'A024' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A025' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A026' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A027' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A029' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02A' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A028' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02B' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02C' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02E' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02F' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02G' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02H' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02J' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02K' ) ) then return false endif return true endfunction
function HeroPick takes location PointCasting returns unit local location PointPicked local unit PickHero set PointPicked = GetUnitLoc(GetEnumUnit()) if (( DistanceBetweenPoints(PointCasting, PointPicked) <= 200.00 ) and ( IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true ) and ( GetUnitTypeId(GetEnumUnit()) != 'n001' ) and ( GetUnitTypeId(GetEnumUnit()) != 'n008' )) then set PickHero = GetEnumUnit() else endif call RemoveLocation(PointPicked) return PickHero endfunction
function Trig_Helmets_Actions takes nothing returns nothing local location PointCasting local integer AbilityIndex = 0 local unit PickedHero set bj_forLoopAIndex = 1 set bj_forLoopAIndexEnd = 10 loop exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd if ( GetSpellAbilityId() == udg_HelmetAbilities[bj_forLoopAIndex]) then set AbilityIndex = bj_forLoopAIndex else endif set bj_forLoopAIndex = bj_forLoopAIndex + 1 endloop if ( AbilityIndex == 0 ) then return else endif
set PointCasting = GetUnitLoc(GetSpellAbilityUnit()) call ForGroupBJ( GetUnitsInRectOfPlayer(GetPlayableMapRect(), GetOwningPlayer(GetSpellAbilityUnit())), function HeroPick) set PickedHero = HeroPick(PointCasting) call DestroyGroup(GetLastCreatedGroup()) if ( AbilityIndex > 1 ) then if (( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_HelmetGold[AbilityIndex] ) and ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_LUMBER) >= udg_HelmetUpgradePoints[AbilityIndex] ) and ( UnitHasItemOfTypeBJ(PickedHero, udg_HelmetItems[( AbilityIndex - 1 )]) == true ))then call RemoveItem( GetItemOfTypeFromUnitBJ(PickedHero, udg_HelmetItems[( AbilityIndex - 1 )]) ) call AddSpecialEffectTargetUnitBJ( "origin", PickedHero, "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" ) call DestroyEffectBJ( GetLastCreatedEffectBJ() ) call AdjustPlayerStateBJ( ( udg_HelmetGold[AbilityIndex] * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_GOLD ) call AdjustPlayerStateBJ( ( udg_HelmetUpgradePoints[AbilityIndex] * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_LUMBER ) call UnitAddItemByIdSwapped( udg_HelmetItems[AbilityIndex], PickedHero ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) else call PlaySoundOnUnitBJ( gg_snd_Warning, 100, PickedHero ) call TransmissionFromUnitWithNameBJ( GetPlayersAllies(GetOwningPlayer(PickedHero)), GetSpellAbilityUnit(), GetUnitName(GetSpellAbilityUnit()), null, ( GetUnitName(PickedHero) + ", bring me everything I require, and I will craft you whatever you want!" ), bj_TIMETYPE_ADD, 3.00, true ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) endif else if ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= udg_HelmetGold[AbilityIndex] ) then call AddSpecialEffectTargetUnitBJ( "origin", PickedHero, "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" ) call DestroyEffectBJ( GetLastCreatedEffectBJ() ) call AdjustPlayerStateBJ( ( udg_HelmetGold[AbilityIndex] * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_GOLD ) call UnitAddItemByIdSwapped( udg_HelmetItems[AbilityIndex], PickedHero ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) else call PlaySoundOnUnitBJ( gg_snd_Warning, 100, PickedHero ) call TransmissionFromUnitWithNameBJ( GetPlayersAllies(GetOwningPlayer(PickedHero)), GetSpellAbilityUnit(), GetUnitName(GetSpellAbilityUnit()), null, ( GetUnitName(PickedHero) + ", bring me everything I require, and I will craft you whatever you want!" ), bj_TIMETYPE_ADD, 3.00, true ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) endif endif endfunction
//=========================================================================== function InitTrig_Helmets takes nothing returns nothing set gg_trg_Helmets = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Helmets, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_Helmets, Condition( function Trig_Helmets_Conditions ) ) call TriggerAddAction( gg_trg_Helmets, function Trig_Helmets_Actions ) endfunction
Почему вылетает игра с ошибкой?
Добавлено (17-07-2011, 12:42) --------------------------------------------- Как я понял проблема вот в этом: if ( GetSpellAbilityId() == udg_HelmetAbilities[bj_forLoopAIndex]) then
Но почему? udg_HelmetAbilities[bj_forLoopAIndex]) - это массив созданный заранее, который содержит несколько абилок. Джасс не принимает массивы чтоли?
Сообщение отредактировал FatalBlade - Воскресенье, 17 Июля 2011, 12:39:04
function Trig_Helmets_Conditions takes nothing returns boolean if ( not ( GetSpellAbilityId() != 'A024' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A025' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A026' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A027' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A029' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02A' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A028' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02B' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02C' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02E' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02F' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02G' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02H' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02J' ) ) then return false endif if ( not ( GetSpellAbilityId() != 'A02K' ) ) then return false endif return true endfunction
function HeroPick takes location PointCasting returns unit local location PointPicked local unit PickHero set PointPicked = GetUnitLoc(GetEnumUnit()) if (( DistanceBetweenPoints(PointCasting, PointPicked) <= 200.00 ) and ( IsUnitType(GetEnumUnit(), UNIT_TYPE_HERO) == true ) and ( GetUnitTypeId(GetEnumUnit()) != 'n001' ) and ( GetUnitTypeId(GetEnumUnit()) != 'n008' )) then set PickHero = GetEnumUnit() endif call RemoveLocation(PointPicked) return PickHero endfunction
function Trig_Helmets_Actions takes nothing returns nothing local location PointCasting local integer AbilityIndex = 0 local unit PickedHero local integer abil local integer equip local integer old local integer gold local integer upgrade local integer i = 1 loop exitwhen i > 10 set abil = udg_HelmetAbilities[i] if ( GetSpellAbilityId() == abil) then set AbilityIndex = i endif set i = i + 1 endloop if ( AbilityIndex == 0 ) then return endif
set equip = udg_HelmetItems[AbilityIndex] set old = udg_HelmetItems[AbilityIndex - 1] set gold = udg_HelmetGold[AbilityIndex] set upgrade = udg_HelmetUpgradePoints[AbilityIndex] set PointCasting = GetUnitLoc(GetSpellAbilityUnit()) call ForGroupBJ( GetUnitsInRectOfPlayer(GetPlayableMapRect(), GetOwningPlayer(GetSpellAbilityUnit())), function HeroPick) set PickedHero = HeroPick(PointCasting) call DestroyGroup(GetLastCreatedGroup()) if ( AbilityIndex > 1 ) then if (( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= gold ) and ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_LUMBER) >= upgrade ) and ( UnitHasItemOfTypeBJ(PickedHero, old) == true ))then call RemoveItem( GetItemOfTypeFromUnitBJ(PickedHero, old) ) call AddSpecialEffectTargetUnitBJ( "origin", PickedHero, "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" ) call DestroyEffectBJ( GetLastCreatedEffectBJ() ) call AdjustPlayerStateBJ( ( gold * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_GOLD ) call AdjustPlayerStateBJ( ( upgrade * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_LUMBER ) call UnitAddItemByIdSwapped( equip, PickedHero ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) else call PlaySoundOnUnitBJ( gg_snd_Warning, 100, PickedHero ) call TransmissionFromUnitWithNameBJ( GetPlayersAllies(GetOwningPlayer(PickedHero)), GetSpellAbilityUnit(), GetUnitName(GetSpellAbilityUnit()), null, ( GetUnitName(PickedHero) + ", bring me everything I require, and I will craft you whatever you want!" ), bj_TIMETYPE_ADD, 3.00, true ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) endif else if ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) >= gold ) then call AddSpecialEffectTargetUnitBJ( "origin", PickedHero, "Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl" ) call DestroyEffectBJ( GetLastCreatedEffectBJ() ) call AdjustPlayerStateBJ( ( gold * -1 ), GetOwningPlayer(PickedHero), PLAYER_STATE_RESOURCE_GOLD ) call UnitAddItemByIdSwapped( equip, PickedHero ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) else call PlaySoundOnUnitBJ( gg_snd_Warning, 100, PickedHero ) call TransmissionFromUnitWithNameBJ( GetPlayersAllies(GetOwningPlayer(PickedHero)), GetSpellAbilityUnit(), GetUnitName(GetSpellAbilityUnit()), null, ( GetUnitName(PickedHero) + ", bring me everything I require, and I will craft you whatever you want!" ), bj_TIMETYPE_ADD, 3.00, true ) call RemoveLocation(PointCasting) set PickedHero = null call RemoveUnit(PickedHero) endif endif endfunction
//=========================================================================== function InitTrig_Helmets takes nothing returns nothing set gg_trg_Helmets = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Helmets, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_Helmets, Condition( function Trig_Helmets_Conditions ) ) call TriggerAddAction( gg_trg_Helmets, function Trig_Helmets_Actions ) endfunction
FatalBlade, мда над оптимизацией тебе еще надо работать + бесполезное использование глобалок и локалок. И вообще что делает этот триггер? Хотябы в краце расскажи.
call ForGroupBJ( GetUnitsInRectOfPlayer(GetPlayableMapRect(), GetOwningPlayer(GetSpellAbilityUnit())), function HeroPick) set PickedHero = HeroPick(PointCasting)
function HeroPick takes location PointCasting returns unit local location PointPicked local unit PickHero set PointPicked = GetUnitLoc(GetEnumUnit()) if *** then set PickHero = GetEnumUnit() endif call RemoveLocation(PointPicked) return PickHero endfunction
Nic nie wiem bo mam chuj. редактирую посты! ВСЕ!
Сообщение отредактировал lawson - Воскресенье, 17 Июля 2011, 15:47:29