|   -SilverBane- | 
				
					| Category: | Code |  
					| Level: | Intermediate    |  
					| Created: | Thursday May 28, 2015 - 16:08 |  
					| Updated: | Sunday May 31, 2015 - 10:20 |  
					| Views: | 6821 |  
					| Summary: | A tutorial for those who want to make heavily customized maps, but modders might find  tricks too! |  | Rating
			 
				
					| Staff says 
							-
						 | Members say 
							-
						 |  
					| Average - |  0 votes | 
	
6==================================================================================================
Spellbooks are easy to do, because they work similiar to unit special abilities.
You will need to check the following files: playertemplate.INI, science.INI, specialpower.INI, commandbutton.INI, system.INI (found in data\ini\object\system)
I will show you here how to make a small spellbook of just 3 powers, making a larger one uses the same system, you just need to add more modules inside the spellbok obj, sciences and commandbuttons.
It's the best to create a new spellbook object, instead of editing existing one. So let's see:
         | Code | 
         | 
 Object DeathmatchSpellBook
 
 
 
 
 CommandSet          = DeathmatchSpellBookCommandSet
 RadarPriority       = NOT_ON_RADAR
 KindOf              = SPELL_BOOK IMMOBILE IGNORES_SELECT_ALL INERT
 
 
 AddModule
 Behavior = PlayerHealSpecialPower ModuleTag_Heal
 SpecialPowerTemplate  = SpellBookHeal
 HealAffects              = INFANTRY CAVALRY SHIP DOZER MONSTER ;MACHINE
 HealAmount              = 0.5 ; ;1.0    ; 0.5 = 50% of maximum health
 HealRadius              = SPELL_HEAL_RADIUS_UNIT_SCAN
 HealFX                  = FX_SpellHealUnitHealBuff        ;FX_DefaultUnitHealBuff
 ; To replenish hordes a bit
 HealOCL               = OCL_HealSpellHordeReplenishPing
 AvailableAtStart      = No
 RequirementsFilterMPSkirmish = SPELL_BOOK_REQUIREMENTS_FILTER
 RequirementsFilterStrategic = SPELL_BOOK_REQUIREMENTS_FILTER_STRATEGIC
 End
 End
 
 
 AddModule
 Behavior = SpecialPowerModule        SpellBookWarChant_ModuleTag
 SpecialPowerTemplate        = SpellBookWarChant
 AttributeModifier            = SpellBookWarChant
 AttributeModifierRange        = 100
 AttributeModifierAffects    = GENERIC_BUFF_RECIPIENT_OBJECT_FILTER
 TriggerFX                    = FX_SpellWarChant
 UpdateModuleStartsAttack    = No
 AvailableAtStart            = No
 RequirementsFilterMPSkirmish = SPELL_BOOK_REQUIREMENTS_FILTER
 RequirementsFilterStrategic = SPELL_BOOK_REQUIREMENTS_FILTER_STRATEGIC
 End
 End
 
 AddModule
 Behavior = OCLSpecialPower    ModuleTag_OCLCaveBats
 SpecialPowerTemplate    = SpellBookCaveBats
 OCL                        = OCL_SpellBookCaveBats
 CreateLocation            = CREATE_AT_LOCATION
 AvailableAtStart        = No
 RequirementsFilterMPSkirmish = SPELL_BOOK_REQUIREMENTS_FILTER
 RequirementsFilterStrategic = SPELL_BOOK_REQUIREMENTS_FILTER_STRATEGIC
 End
 End
 
 End
 
 
 
 | 
         
Now, I will use as example the heal power:
         | Code | 
         | 
 Science SCIENCE_HealN                   ; N is for new, it's needed to make new sciences if you want requirments to work properly (so you cant just buy 25pp balrog if you don't have darkness first as an example)
 PrerequisiteSciences = SCIENCE_EVIL   ; see below, we edit playertemplate.ini
 SciencePurchasePointCost = 5          ; only for campaign, not relevant
 SciencePurchasePointCostMP = 5        ; how much it costs
 IsGrantable = Yes                     ; it can be granted through map script
 End
 
 SpecialPower SpellBookHeal       ; you already know how a special power works - it is bound to commandbutton and module in spellbok obj!
 InitiateAtLocationSound     = SpellHeal
 Enum                        = SPECIAL_SPELL_BOOK_HEAL
 Flags                = WATER_OK RESPECT_RECHARGE_TIME_DISCOUNT
 ReloadTime                 = SPELL_RECHARGE_TIME_TIER_1
 RequiredSciences             = SCIENCE_HealN      ; the science above
 RadiusCursorRadius          = SPELL_HEAL_RADIUS_CURSOR
 End
 
 
 CommandButton Command_PurchaseSpellHeal               ;this one is in the spellstore
 Command                = PURCHASE_SCIENCE
 ButtonBorderType    = UPGRADE
 ButtonImage            = SBGood_Heal
 Science                = SCIENCE_HealN    ;
 TextLabel            = CONTROLBAR:Heal
 DescriptLabel        = CONTROLBAR:TooltipHeal
 End
 
 
 
 
 | 
         
And the commandsets:
         | Code | 
         | CommandSet DeathmatchSpellBookCommandSet ; this one is used by spellbook object
 1 =  Command_SpellBookHeal       ; this one leave it as it is unless you want another description
 2 = Command_SpellBookWarChant
 3 = Command_SpellBookCaveBats
 
 
 End
 
 CommandSet DeathmatchSpellStoreCommandSet
 1 = Command_PurchaseSpellCaveBats
 2 = Command_PurchaseSpellHeal
 3 = Command_PurchaseSpellWarChant
 
 End
 
 
 
 | 
         
The playertemplate related stuff:
         | Code | 
         | ;these are the settings for factions
 
 
 PlayerTemplate FactionMen
 IntrinsicSciencesMP = SCIENCE_EVIL      ; this matches the PrerequisiteSciences in the science
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet ; the commandset of the spellstore
 SpellBookMp = DeathmatchSpellBook    ; the spellbook object used for this faction
 End
 
 
 
 | 
         
The same template goes for other factions. Of course, you can create a different spellbook for each faction (like original ones) but it takes a lot of time! :P
Let's get these pieces together and see the spellbook in-game!
         | Code | 
         | 
 Science SCIENCE_HealN
 PrerequisiteSciences = SCIENCE_EVIL
 SciencePurchasePointCost = 5
 SciencePurchasePointCostMP = 5
 IsGrantable = Yes
 End
 
 SpecialPower SpellBookHeal
 InitiateAtLocationSound     = SpellHeal
 Enum                        = SPECIAL_SPELL_BOOK_HEAL
 Flags                = WATER_OK RESPECT_RECHARGE_TIME_DISCOUNT
 ReloadTime                 = SPELL_RECHARGE_TIME_TIER_1
 RequiredSciences             = SCIENCE_HealN
 RadiusCursorRadius          = SPELL_HEAL_RADIUS_CURSOR
 End
 
 
 CommandButton Command_PurchaseSpellHeal
 Command                = PURCHASE_SCIENCE
 ButtonBorderType    = UPGRADE
 ButtonImage            = SBGood_Heal
 Science                = SCIENCE_HealN
 TextLabel            = CONTROLBAR:Heal
 DescriptLabel        = CONTROLBAR:TooltipHeal
 End
 
 
 
 
 CommandSet DeathmatchSpellBookCommandSet ; this one is used by spellbook object
 1 =  Command_SpellBookHeal
 2 = Command_SpellBookWarChant
 3 = Command_SpellBookCaveBats
 
 
 End
 
 CommandSet DeathmatchSpellStoreCommandSet
 1 = Command_PurchaseSpellCaveBats
 2 = Command_PurchaseSpellHeal
 3 = Command_PurchaseSpellWarChant
 
 End
 
 
 
 
 
 Object DeathmatchSpellBook
 
 
 
 
 CommandSet          = DeathmatchSpellBookCommandSet
 RadarPriority       = NOT_ON_RADAR
 KindOf              = SPELL_BOOK IMMOBILE IGNORES_SELECT_ALL INERT
 
 
 AddModule
 Behavior = PlayerHealSpecialPower ModuleTag_Heal
 SpecialPowerTemplate  = SpellBookHeal
 HealAffects              = INFANTRY CAVALRY SHIP DOZER MONSTER ;MACHINE
 HealAmount              = 0.5 ; ;1.0    ; 0.5 = 50% of maximum health
 HealRadius              = SPELL_HEAL_RADIUS_UNIT_SCAN
 HealFX                  = FX_SpellHealUnitHealBuff        ;FX_DefaultUnitHealBuff
 ; To replenish hordes a bit
 HealOCL               = OCL_HealSpellHordeReplenishPing
 AvailableAtStart      = No
 RequirementsFilterMPSkirmish = SPELL_BOOK_REQUIREMENTS_FILTER
 RequirementsFilterStrategic = SPELL_BOOK_REQUIREMENTS_FILTER_STRATEGIC
 End
 End
 
 
 AddModule
 Behavior = SpecialPowerModule        SpellBookWarChant_ModuleTag
 SpecialPowerTemplate        = SpellBookWarChant
 AttributeModifier            = SpellBookWarChant
 AttributeModifierRange        = 100
 AttributeModifierAffects    = GENERIC_BUFF_RECIPIENT_OBJECT_FILTER
 TriggerFX                    = FX_SpellWarChant
 UpdateModuleStartsAttack    = No
 AvailableAtStart            = No
 RequirementsFilterMPSkirmish = SPELL_BOOK_REQUIREMENTS_FILTER
 RequirementsFilterStrategic = SPELL_BOOK_REQUIREMENTS_FILTER_STRATEGIC
 End
 End
 
 AddModule
 Behavior = OCLSpecialPower    ModuleTag_OCLCaveBats
 SpecialPowerTemplate    = SpellBookCaveBats
 OCL                        = OCL_SpellBookCaveBats
 CreateLocation            = CREATE_AT_LOCATION
 AvailableAtStart        = No
 RequirementsFilterMPSkirmish = SPELL_BOOK_REQUIREMENTS_FILTER
 RequirementsFilterStrategic = SPELL_BOOK_REQUIREMENTS_FILTER_STRATEGIC
 End
 End
 
 End
 
 
 
 
 PlayerTemplate FactionMen
 IntrinsicSciencesMP = SCIENCE_EVIL
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet
 SpellBookMp = DeathmatchSpellBook
 End
 
 PlayerTemplate FactionElves
 IntrinsicSciencesMP = SCIENCE_EVIL
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet
 SpellBookMp = DeathmatchSpellBook
 End
 
 PlayerTemplate FactionDwarves
 IntrinsicSciencesMP = SCIENCE_EVIL
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet
 SpellBookMp = DeathmatchSpellBook
 End
 
 PlayerTemplate FactionIsengard
 IntrinsicSciencesMP = SCIENCE_EVIL
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet
 SpellBookMp = DeathmatchSpellBook
 End
 
 
 
 PlayerTemplate FactionWild
 IntrinsicSciencesMP = SCIENCE_EVIL
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet
 SpellBookMp = DeathmatchSpellBook
 End
 
 
 PlayerTemplate FactionMordor
 IntrinsicSciencesMP = SCIENCE_EVIL
 PurchaseScienceCommandSetMP = DeathmatchSpellStoreCommandSet
 SpellBookMp = DeathmatchSpellBook
 End
 
 
 
 
 | 
         
Add this in your map.ini and tell me if it works! :D
So basically, the spellbook works almost like a normal object, you can have different type of special power modules into it. Of course, you can create new ones aswell (not only existing powers), but I won't do it here or this tutorial will be infinite.