|
发表于 2011-5-17 10:55:15
|
显示全部楼层
哈哈哈,原来不够详细啊,那么弄得详细些?
[codes=jass]//***************************************************************************
//*
//* Melee Template Granted Hero Items
//*
//***************************************************************************
//===========================================================================
function MeleeTrainedUnitIsHeroBJFilter takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
endfunction
//===========================================================================
// The first N heroes trained or hired for each player start off with a
// standard set of items. This is currently:
// - 1x Scroll of Town Portal
//
function MeleeGrantItemsToHero takes unit whichUnit returns nothing
local integer owner = GetPlayerId(GetOwningPlayer(whichUnit))
// If we haven't twinked N heroes for this player yet, twink away.
if (bj_meleeTwinkedHeroes[owner] < bj_MELEE_MAX_TWINKED_HEROES) then
call UnitAddItemById(whichUnit, 'stwp')
set bj_meleeTwinkedHeroes[owner] = bj_meleeTwinkedHeroes[owner] + 1
endif
endfunction
//===========================================================================
function MeleeGrantItemsToTrainedHero takes nothing returns nothing
call MeleeGrantItemsToHero(GetTrainedUnit())
endfunction
//===========================================================================
function MeleeGrantItemsToHiredHero takes nothing returns nothing
call MeleeGrantItemsToHero(GetSoldUnit())
endfunction
//===========================================================================
function MeleeGrantHeroItems takes nothing returns nothing
local integer index
local trigger trig
// Initialize the twinked hero counts.
set index = 0
loop
set bj_meleeTwinkedHeroes[index] = 0
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
// Register for an event whenever a hero is trained, so that we can give
// him/her their starting items.
set index = 0
loop
set trig = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(trig, Player(index), EVENT_PLAYER_UNIT_TRAIN_FINISH, filterMeleeTrainedUnitIsHeroBJ)
call TriggerAddAction(trig, function MeleeGrantItemsToTrainedHero)
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
// Register for an event whenever a neutral hero is hired, so that we
// can give him/her their starting items.
set trig = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(trig, Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_SELL, filterMeleeTrainedUnitIsHeroBJ)
call TriggerAddAction(trig, function MeleeGrantItemsToHiredHero)
// Flag that we are giving starting items to heroes, so that the melee
// starting units code can create them as necessary.
set bj_meleeGrantHeroItems = true
endfunction[/codes]
以上是主干部分,简单的说就是注册两种类型的触发事件,一个是玩家训练英雄,另一个是中立玩家出售英雄
下面是涉及到的一下相关变量
[codes=jass]
constant integer bj_MELEE_MAX_TWINKED_HEROES_V0 = 3
constant integer bj_MELEE_MAX_TWINKED_HEROES_V1 = 1
integer bj_MELEE_MAX_TWINKED_HEROES = 0
set v = VersionGet()
if (v == VERSION_REIGN_OF_CHAOS) then
set bj_MELEE_MAX_TWINKED_HEROES = bj_MELEE_MAX_TWINKED_HEROES_V0
else
set bj_MELEE_MAX_TWINKED_HEROES = bj_MELEE_MAX_TWINKED_HEROES_V1
endif
integer array bj_meleeTwinkedHeroes
[/codes]
这个呢,简单的说就是要塞东西的英雄数量,对于混乱之治是3,对于冰封王座是1,以及记录每个玩家已经训练或者买了的英雄数量的数组
[codes=jass]constant integer bj_MAX_PLAYERS = 12
constant integer bj_MAX_PLAYER_SLOTS = 16[/codes]
最大玩家数量,区别是前者不包含中立的那4个
[codes=jass]boolexpr filterMeleeTrainedUnitIsHeroBJ = null
set filterMeleeTrainedUnitIsHeroBJ = Filter(function MeleeTrainedUnitIsHeroBJFilter)[/codes]
判断条件的变量,判断训练/买出来的是不是英雄
以上是和这个触发动作相关的bj代码了,那个触发动作本身调用的是MeleeGrantHeroItems函数,最终实际起到给物品的是MeleeGrantItemsToHero这个函数,‘stwp’这个就是回城卷轴的物品id,要自定义的话,删掉这条触发动作,然后重写上面主干部分的那些函数并调用就可以了,是不是够详细了呢 |
|