• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Custom Spell System

+ Description: This system allow you to make "Buy item to learn skill" very easy and more configurable.
+

JASS:
function AddCSS takes integer ii, integer si returns nothing
        call SaveInteger(udg_CSS_Hash, 1, ii, si)
        call SaveInteger(udg_CSS_Hash, 1, si, ii)
endfunction

function SetCSSTypeB takes integer ii, boolean b returns nothing
        call SaveBoolean(udg_CSS_Hash, 0, ii, b)
endfunction

function SetCSSClassB takes integer ii, boolean b returns nothing
        call SaveBoolean(udg_CSS_Hash, 8, ii, b)
endfunction

function SetCSSType takes integer ii, integer i returns nothing
        call SaveInteger(udg_CSS_Hash, 2, ii, i)
endfunction

function SetCSSCost takes integer ii, integer i returns nothing
        call SaveInteger(udg_CSS_Hash, 3, ii, i)
endfunction

function SetCSSMaxLevel takes integer ii, integer i returns nothing
        call SaveInteger(udg_CSS_Hash, 4, ii, i)
endfunction

function SetCSSClass takes integer ii, integer i returns nothing
        call SaveInteger(udg_CSS_Hash, 5, ii, i)
endfunction

function SetCSSReqLevel takes integer ii, integer i returns nothing
        call SaveInteger(udg_CSS_Hash, 6, ii, i)
endfunction

function SetCSSPoint takes unit u, integer p returns nothing
        call SaveInteger(udg_CSS_Hash, 7, GetHandleId(u), p)
endfunction

function AddCSSPoint takes unit u, integer p returns nothing
        call SaveInteger(udg_CSS_Hash, 7, GetHandleId(u), LoadInteger(udg_CSS_Hash, 7, GetHandleId(u)) + p)
endfunction

function GetCSSSpell takes integer ii returns integer si
        return LoadInteger(udg_CSS_Hash, 1, ii)
endfunction

function GetCSSItem takes integer si returns integer ii
        return LoadInteger(udg_CSS_Hash, 1, si)
endfunction

function GetCSSType takes integer ii returns integer i
        return LoadInteger(udg_CSS_Hash, 2, ii)
endfunction

function GetCSSCost takes integer ii returns integer i
        return LoadInteger(udg_CSS_Hash, 3, ii)
endfunction

function GetCSSMaxLevel takes integer ii returns integer i
        return LoadInteger(udg_CSS_Hash, 4, ii)
endfunction

function GetCSSClass takes integer ii returns integer i
        return LoadInteger(udg_CSS_Hash, 5, ii)
endfunction

function GetCSSReqLevel takes integer ii returns integer i
        return LoadInteger(udg_CSS_Hash, 6, ii)
endfunction

function GetCSSPoint takes unit u returns integer i
        return LoadInteger(udg_CSS_Hash, 7, GetHandleId(u))
endfunction

function GetCSSClassB takes integer ii returns boolean b
        return LoadBoolean(udg_CSS_Hash, 8, ii)
endfunction

function GetCSSTypeB takes integer ii returns boolean b
        return LoadBoolean(udg_CSS_Hash, 0, ii)
endfunction

function GetCSSUnitS takes unit u, integer i returns integer si
            return LoadInteger(udg_CSS_Hash, GetHandleId(u), i)
endfunction
  • CSS Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set udg_CSS_Hash = InitHashtable()
      • -------- ----------- --------
      • Custom script: call SetCSSClass('Hpal', 1)
      • Custom script: call SetCSSClass('Hamg', 2)
      • -------- ----------- --------
      • Custom script: call AddCSS('I000', 'AHav')
      • Custom script: call SetCSSType('I000', 2)
      • Custom script: call SetCSSCost('I000', 2)
      • Custom script: call SetCSSMaxLevel('I000', 1)
      • Custom script: call SetCSSClass('I000', 1)
      • Custom script: call SetCSSClassB('I000', true)
      • Custom script: call SetCSSTypeB('I000', true)
      • -------- ----------- --------
      • Custom script: call AddCSS('I001', 'ANab')
      • Custom script: call SetCSSType('I001', 1)
      • Custom script: call SetCSSCost('I001', 1)
      • Custom script: call SetCSSMaxLevel('I001', 3)
      • Custom script: call SetCSSClass('I001', 2)
      • Custom script: call SetCSSClassB('I001', true)
      • Custom script: call SetCSSTypeB('I001', true)
      • -------- ----------- --------
      • Custom script: call AddCSS('I002', 'AHbz')
      • Custom script: call SetCSSTypeB('I001', true)
      • Custom script: call SetCSSType('I002', 1)
      • Custom script: call SetCSSCost('I002', 1)
      • Custom script: call SetCSSMaxLevel('I002', 3)
      • Custom script: call SetCSSClassB('I001', false)
      • -------- ----------- --------
      • Custom script: call AddCSS('I003', 'AOhx')
      • Custom script: call SetCSSCost('I003', 1)
      • Custom script: call SetCSSMaxLevel('I003', 3)
      • Custom script: call SetCSSClass('I003', 1)
      • Custom script: call SetCSSClassB('I000', true)
      • Custom script: call SetCSSTypeB('I003', false)
      • -------- ----------- --------
      • Custom script: call AddCSS('I004', 'AOmi')
      • Custom script: call SetCSSType('I004', 1)
      • Custom script: call SetCSSCost('I004', 1)
      • Custom script: call SetCSSMaxLevel('I004', 3)
      • Custom script: call SetCSSClass('I004', 2)
      • Custom script: call SetCSSClassB('I004', true)
      • Custom script: call SetCSSTypeB('I004', true)
  • CSS Check
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • Set TempItem = (Item being manipulated)
      • Set TempItemType = (Item-type of TempItem)
      • Set TempUnit = (Triggering unit)
      • Set TempUnitType = (Unit-type of TempUnit)
      • Custom script: set udg_TempAbility = GetCSSSpell(udg_TempItemType)
      • Set TempInt = (Level of TempAbility for TempUnit)
      • -------- - --------
      • Custom script: if (udg_TempAbility > 0) and (not GetCSSClassB(udg_TempItemType) or GetCSSClass(udg_TempItemType) == GetCSSClass(udg_TempUnitType)) then
      • -------- - --------
      • Custom script: if not GetCSSTypeB(udg_TempItemType) or (GetCSSUnitS(udg_TempUnit, GetCSSType(udg_TempItemType)) == 0) or (GetCSSUnitS(udg_TempUnit, GetCSSType(udg_TempItemType)) == udg_TempAbility) then
      • -------- - --------
      • Custom script: if (GetCSSCost(udg_TempItemType) <= GetCSSPoint(udg_TempUnit)) then
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInt Equal to 0
        • Then - Actions
          • Custom script: if GetCSSReqLevel(udg_TempItemType) > GetUnitLevel(udg_TempUnit) then
          • Custom script: call BJDebugMsg("Your hero requires " + I2S(GetCSSReqLevel) + "to learn this skill!!!")
          • Custom script: else
          • Custom script: call UnitAddAbility(udg_TempUnit, udg_TempAbility)
          • Custom script: call SaveInteger(udg_CSS_Hash, 7,GetHandleId(udg_TempUnit), GetCSSPoint(udg_TempUnit) - GetCSSCost(udg_TempItemType))
          • Custom script: call SaveInteger(udg_CSS_Hash,GetHandleId(udg_TempUnit), GetCSSType(udg_TempItemType), udg_TempAbility)
          • Custom script: endif
        • Else - Actions
          • Custom script: if udg_TempInt < GetCSSMaxLevel(udg_TempItemType) then
          • Unit - Increase level of TempAbility for TempUnit
          • Custom script: call SaveInteger(udg_CSS_Hash, 7,GetHandleId(udg_TempUnit), GetCSSPoint(udg_TempUnit) - GetCSSCost(udg_TempItemType))
          • Custom script: else
          • Custom script: call BJDebugMsg("This skill has been already max level !!! " )
          • Custom script: endif
      • Custom script: else
      • Custom script: call BJDebugMsg("Not enought skill point !!! " )
      • Custom script: endif
      • -------- - --------
      • Custom script: else
      • Custom script: call BJDebugMsg("You have had this spell type already!!! " )
      • Custom script: endif
      • -------- - --------
      • Custom script: else
      • Custom script: call BJDebugMsg("Your class can't learn this skill !!! " )
      • Custom script: endif
      • -------- - --------

+
:
COPY CODE IN HEADER AND COPY TO YOUR MAP HEADER

FUNCTION LIST:

+ AddCSS(Abi, Itemtype) or AddCSS(Abi, Itemtype)
+ SetCSSTypeB(Itemtype, boolean)
+ SetCSSClassB(Itemtype, boolean)
+ SetCSSType(itemtype, integer i)
+ SetCSSClass(itemtype, integer i)
+ SetCSSMaxLevel(itemtype, integer i)
+ SetCSSReqLevel(itemtype, integer i)
+ SetCSSCost(itemtype, integer i)
+ SetCSSPoint(unit, integer i)
+ AddCSSPoint(unit, integer i)
+ GetCSSType(GetHandleId(Unit)) or GetCSSType(itemtype)
+ GetCSSClass(GetHandleId(Unit)) or GetCSSClass(itemtype)
+ GetCSSReqLevel(itemtype)
+ GetCSSMaxLevel(itemtype)
+ GetCSSCost(itemtype)
+ GetCSSClassB(itemtype)
+ GetCSSTypeB(itemtype)
+ GetCSSUnitS(itemtype)
+ GetCSSPoint(unit)


- Change varibles name.
- Fix trigger.

I HOPE YOU LIKE IT

Email: [email protected]


Keywords:
spell, buy, sell, ability, custom, system, btdonald
Contents

Custom Spell System (Map)

Reviews
22:15, 10th Oct 2012 Magtheridon96: Approved.
Level 7
Joined
Jan 28, 2012
Messages
266
why did you make Trigger CSS action and Trigger CSS action 1?

think about changing this
  • Custom script: else
  • Custom script: if GetCSSClass(udg_TEMPITEMTYPE) == GetCSSClass(udg_TEMPUNITTYPE) then
into this
  • Custom script: elseif GetCSSCLass(udg_TEMPITEMTYPE) == GetCSSClass(udg_TEMPUNITTYPE) then
and then remove one endif. it would provide a marginal boost to speed(not enough to worry about though,) and it would make your code shorter and cleaner.
 
Level 11
Joined
Dec 3, 2011
Messages
366
why did you make Trigger CSS action and Trigger CSS action 1?

think about changing this
  • Custom script: else
  • Custom script: if GetCSSClass(udg_TEMPITEMTYPE) == GetCSSClass(udg_TEMPUNITTYPE) then
into this
  • Custom script: elseif GetCSSCLass(udg_TEMPITEMTYPE) == GetCSSClass(udg_TEMPUNITTYPE) then
and then remove one endif. it would provide a marginal boost to speed(not enough to worry about though,) and it would make your code shorter and cleaner.

Because that is two part of action => I seperate them.

Tks => I'll fix :D
 
Top