• 🏆 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!

[vJASS] Custom Exp System

Status
Not open for further replies.
Level 6
Joined
Dec 6, 2009
Messages
168
Hello, I'm a noob to jass. I have tried making my exp system into vjass but it doesn't work for more than one player, and it's buggy.

Plz tell me how I can make it more efficent and how to make it work properly :thumbs_up:

All help is appreciated and +rep to anyone helping ofc! :grin:

JASS:
scope CEXP initializer Init
//--------------------------------------------------------------
//--------------------------------------------------------------
//Setting the global exp for units
//--------------------------------------------------------------
//--------------------------------------------------------------


globals
  private constant real Radius = 1000
  private constant integer ExpLevel = 50
endglobals


private function filter takes nothing returns boolean
  local unit u = GetFilterUnit()
  local boolean b1 = IsUnitType( u, UNIT_TYPE_DEAD) == FALSE
  local boolean b2 = IsUnitType( u, UNIT_TYPE_HERO) == TRUE
  local boolean b3 = IsUnitAlly( u, GetOwningPlayer(GetKillingUnit())) == TRUE 
  local boolean b4 = IsUnitIllusion(u) == FALSE

  set u = null
  return b1 and b2 and b3 and b4
endfunction





private function GiveXP takes nothing returns nothing
  local unit u = GetTriggerUnit()
  local unit Killer = GetKillingUnit()
  local unit f
  local location l = GetUnitLoc(u)
  local player p = GetOwningPlayer(Killer)
  local group g = CreateGroup()
  local integer KilledUnitLevel
  local integer KillerLevel
  local real ExpGain
  local integer ExpGainFinal

  set KilledUnitLevel = GetUnitLevel(u)
  set KillerLevel = GetUnitLevel(Killer)
  set ExpGain = ExpLevel

call GroupEnumUnitsInRangeOfLoc( g, l, Radius, Condition(function filter))

//=============================================================================


if ( KillerLevel == KilledUnitLevel ) then
    else
        if ( KillerLevel == ( GetUnitLevel(GetEnumUnit()) + 1 ) ) or ( KillerLevel == ( GetUnitLevel(GetEnumUnit()) - 1 ) )  then
           set ExpGain = ExpGain * 0.90
        else
            if ( KillerLevel == ( KilledUnitLevel + 2 )) or ( KillerLevel == ( KilledUnitLevel - 2 ) ) then
               set ExpGain = ExpGain * 0.80
            else
                if ( KillerLevel == ( KilledUnitLevel + 3 )) or ( KillerLevel == ( KilledUnitLevel - 3 ) ) then
                   set ExpGain = ExpGain * 0.70
                else
                   set ExpGain = 0.00
                endif
            endif
        endif
    endif


//=============================================================================
   
        set ExpGainFinal = (R2I(ExpGain))
        loop
        set f = FirstOfGroup(g)
           exitwhen f == null
             call AddHeroXP(f, ExpGainFinal, TRUE)
             if GetOwningPlayer(f) == GetLocalPlayer() then
             call CreateTextTagLocBJ( ( "+" + ( I2S(ExpGainFinal) + "Exp" ) ), l, 50.00, 11.00, 20.00, 20.00, 80.00, 0 )
             call SetTextTagVelocity( GetLastCreatedTextTag(), 80.00, 90 )
             call SetTextTagPermanent( GetLastCreatedTextTag(), false )
             call SetTextTagLifespan( GetLastCreatedTextTag(), 3.00 )
             call SetTextTagFadepoint( GetLastCreatedTextTag(), 2.50 )
             call GroupRemoveUnit(g, f)
             endif
        endloop
      
      call DestroyGroup(g)
      call RemoveLocation(l)
      set g = null
      set u = null
      set Killer = null
      set f = null
endfunction





//===========================================================================
private function Init takes nothing returns nothing
   local trigger t = CreateTrigger()
   call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
   call TriggerAddAction(t, function GiveXP )
   set t = null
endfunction
endscope
  • Custom EXP Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- Set Shared EXP Range --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • Set EXP_ShareRange = 1000.00
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- Set EXP / Unit Level Init --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • Set EXP_Gain_UnitLVL[1] = 10.00
      • Set EXP_Gain_UnitLVL[2] = 15.00
      • Set EXP_Gain_UnitLVL[3] = 22.00
      • Set EXP_Gain_UnitLVL[4] = 50.00
      • Set EXP_Gain_UnitLVL[5] = 100.00
      • Set EXP_Gain_UnitLVL[6] = 110.00
      • Set EXP_Gain_UnitLVL[7] = 120.00
      • Set EXP_Gain_UnitLVL[8] = 130.00
      • Set EXP_Gain_UnitLVL[9] = 140.00
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- Set Specific Unit EXP --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • Set EXP_Gain_UnitType[1] = Wolf Boss
      • Set EXP_Gain_BossType[2] = (Real((Point-value of EXP_Gain_UnitType[1])))
      • Set EXP_Gain_UnitType[2] = Wolf Boss Big
      • Set EXP_Gain_BossType[5] = (Real((Point-value of EXP_Gain_UnitType[2])))
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- Set EXP / Unit Level End --------
      • -------- --------------------------------------------------------------------------- --------
      • -------- --------------------------------------------------------------------------- --------
  • Custom EXP System
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to (==) False
      • ((Triggering unit) belongs to an enemy of (Owner of (Killing unit))) Equal to (==) True
    • Actions
      • Set EXP_Unit = (Triggering unit)
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Real((Point-value of EXP_Unit))) Equal to (==) EXP_Gain_BossType[(Level of EXP_Unit)]
          • Then - Actions
            • Set TempLoc = (Position of EXP_Unit)
            • Set EXP_GainGroup = (Units within EXP_ShareRange of TempLoc matching ((((Matching unit) belongs to an ally of (Owner of (Killing unit))) Equal to (==) True) and ((((Matching unit) is A Hero) Equal to (==) True) and ((((Matching unit) is alive) Equal to (==) True) and (((Matching
            • Set EXP_UnitKillLVL = (Level of EXP_Unit)
            • Set EXP_Gain = EXP_Gain_BossType[(Level of EXP_Unit)]
            • Custom script: set bj_wantDestroyGroup=true
            • Unit Group - Pick every unit in EXP_GainGroup and do (Actions)
              • Loop - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • EXP_UnitKillLVL Equal to (==) (Level of (Picked unit))
                  • Then - Actions
                  • Else - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • Multiple ConditionsOr - Any (Conditions) are true
                          • Conditions
                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 1)
                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 1)
                      • Then - Actions
                      • Else - Actions
                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • Multiple ConditionsOr - Any (Conditions) are true
                              • Conditions
                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 2)
                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 2)
                          • Then - Actions
                          • Else - Actions
                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • If - Conditions
                                • Multiple ConditionsOr - Any (Conditions) are true
                                  • Conditions
                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 3)
                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 3)
                              • Then - Actions
                              • Else - Actions
                                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                  • If - Conditions
                                    • Multiple ConditionsOr - Any (Conditions) are true
                                      • Conditions
                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 4)
                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 4)
                                  • Then - Actions
                                  • Else - Actions
                                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                      • If - Conditions
                                        • Multiple ConditionsOr - Any (Conditions) are true
                                          • Conditions
                                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 5)
                                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 5)
                                      • Then - Actions
                                      • Else - Actions
                                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                          • If - Conditions
                                            • Multiple ConditionsOr - Any (Conditions) are true
                                              • Conditions
                                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 6)
                                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 6)
                                          • Then - Actions
                                            • Set EXP_Gain = (EXP_Gain x 0.90)
                                          • Else - Actions
                                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                              • If - Conditions
                                                • Multiple ConditionsOr - Any (Conditions) are true
                                                  • Conditions
                                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 7)
                                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 7)
                                              • Then - Actions
                                                • Set EXP_Gain = (EXP_Gain x 0.70)
                                              • Else - Actions
                                                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                  • If - Conditions
                                                    • Multiple ConditionsOr - Any (Conditions) are true
                                                      • Conditions
                                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 8)
                                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 8)
                                                  • Then - Actions
                                                    • Set EXP_Gain = (EXP_Gain x 0.50)
                                                  • Else - Actions
                                                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                      • If - Conditions
                                                        • Multiple ConditionsOr - Any (Conditions) are true
                                                          • Conditions
                                                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 9)
                                                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 9)
                                                      • Then - Actions
                                                        • Set EXP_Gain = (EXP_Gain x 0.20)
                                                      • Else - Actions
                                                        • Set EXP_Gain = 0.00
                • Set TempInt = (Player number of (Owner of (Picked unit)))
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Multiple ConditionsOr - Any (Conditions) are true
                        • Conditions
                          • (Picked unit) Equal to (==) (Killing unit)
                          • (Owner of (Picked unit)) Equal to (==) (Owner of (Killing unit))
                    • Then - Actions
                      • Set EXP_GainFinal = (Integer(EXP_Gain))
                      • Hero - Add EXP_GainFinal experience to (Picked unit), Show level-up graphics
                      • Custom script: if GetOwningPlayer(GetEnumUnit()) == GetLocalPlayer() then
                      • Floating Text - Create floating text that reads (+ + ((String(EXP_GainFinal)) + Exp)) at TempLoc with Z offset 50.00, using font size 11.00, color (20.00%, 20.00%, 80.00%), and 0.00% transparency
                      • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
                      • Floating Text - Change (Last created floating text): Disable permanence
                      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                      • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
                      • Custom script: endif
                    • Else - Actions
                      • Set EXP_GainFinal = (Integer(EXP_Gain))
                      • Hero - Add EXP_GainFinal experience to (Picked unit), Show level-up graphics
                      • Custom script: if GetOwningPlayer(GetEnumUnit()) == GetLocalPlayer() then
                      • Floating Text - Create floating text that reads (+ + ((String(EXP_GainFinal)) + Exp)) at TempLoc with Z offset 50.00, using font size 11.00, color (20.00%, 20.00%, 80.00%), and 0.00% transparency
                      • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
                      • Floating Text - Change (Last created floating text): Disable permanence
                      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                      • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
                      • Custom script: endif
            • Custom script: call RemoveLocation(udg_TempLoc)
          • Else - Actions
            • Set TempLoc = (Position of EXP_Unit)
            • Set EXP_GainGroup = (Units within EXP_ShareRange of TempLoc matching ((((Matching unit) belongs to an ally of (Owner of (Killing unit))) Equal to (==) True) and ((((Matching unit) is A Hero) Equal to (==) True) and ((((Matching unit) is alive) Equal to (==) True) and (((Matching
            • Set EXP_UnitKillLVL = (Level of EXP_Unit)
            • Set EXP_Gain = EXP_Gain_UnitLVL[EXP_UnitKillLVL]
            • Custom script: set bj_wantDestroyGroup=true
            • Unit Group - Pick every unit in EXP_GainGroup and do (Actions)
              • Loop - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • EXP_UnitKillLVL Equal to (==) (Level of (Picked unit))
                  • Then - Actions
                  • Else - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • Multiple ConditionsOr - Any (Conditions) are true
                          • Conditions
                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 1)
                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 1)
                      • Then - Actions
                        • Set EXP_Gain = (EXP_Gain x 0.95)
                      • Else - Actions
                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • Multiple ConditionsOr - Any (Conditions) are true
                              • Conditions
                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 2)
                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 2)
                          • Then - Actions
                            • Set EXP_Gain = (EXP_Gain x 0.85)
                          • Else - Actions
                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • If - Conditions
                                • Multiple ConditionsOr - Any (Conditions) are true
                                  • Conditions
                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 3)
                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 3)
                              • Then - Actions
                                • Set EXP_Gain = (EXP_Gain x 0.60)
                              • Else - Actions
                                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                  • If - Conditions
                                    • Multiple ConditionsOr - Any (Conditions) are true
                                      • Conditions
                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 4)
                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 4)
                                  • Then - Actions
                                    • Set EXP_Gain = (EXP_Gain x 0.40)
                                  • Else - Actions
                                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                      • If - Conditions
                                        • Multiple ConditionsOr - Any (Conditions) are true
                                          • Conditions
                                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 5)
                                            • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 5)
                                      • Then - Actions
                                        • Set EXP_Gain = (EXP_Gain x 0.30)
                                      • Else - Actions
                                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                          • If - Conditions
                                            • Multiple ConditionsOr - Any (Conditions) are true
                                              • Conditions
                                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 6)
                                                • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 6)
                                          • Then - Actions
                                            • Set EXP_Gain = (EXP_Gain x 0.15)
                                          • Else - Actions
                                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                              • If - Conditions
                                                • Multiple ConditionsOr - Any (Conditions) are true
                                                  • Conditions
                                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 7)
                                                    • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 7)
                                              • Then - Actions
                                                • Set EXP_Gain = (EXP_Gain x 0.10)
                                              • Else - Actions
                                                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                  • If - Conditions
                                                    • Multiple ConditionsOr - Any (Conditions) are true
                                                      • Conditions
                                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) + 8)
                                                        • EXP_UnitKillLVL Equal to (==) ((Level of (Picked unit)) - 8)
                                                  • Then - Actions
                                                    • Set EXP_Gain = (EXP_Gain x 0.05)
                                                  • Else - Actions
                                                    • Set EXP_Gain = 0.00
                • Set TempInt = (Player number of (Owner of (Picked unit)))
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Multiple ConditionsOr - Any (Conditions) are true
                        • Conditions
                          • (Picked unit) Equal to (==) (Killing unit)
                          • (Owner of (Picked unit)) Equal to (==) (Owner of (Killing unit))
                    • Then - Actions
                      • Set EXP_GainFinal = (Integer(EXP_Gain))
                      • Hero - Add EXP_GainFinal experience to (Picked unit), Show level-up graphics
                      • Custom script: if GetOwningPlayer(GetEnumUnit()) == GetLocalPlayer() then
                      • Floating Text - Create floating text that reads (+ + ((String(EXP_GainFinal)) + Exp)) at TempLoc with Z offset 50.00, using font size 11.00, color (20.00%, 20.00%, 80.00%), and 0.00% transparency
                      • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
                      • Floating Text - Change (Last created floating text): Disable permanence
                      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                      • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
                      • Custom script: endif
                    • Else - Actions
                      • Set EXP_GainFinal = (Integer(EXP_Gain))
                      • Hero - Add EXP_GainFinal experience to (Picked unit), Show level-up graphics
                      • Custom script: if GetOwningPlayer(GetEnumUnit()) == GetLocalPlayer() then
                      • Floating Text - Create floating text that reads (+ + ((String(EXP_GainFinal)) + Exp)) at TempLoc with Z offset 50.00, using font size 11.00, color (20.00%, 20.00%, 80.00%), and 0.00% transparency
                      • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
                      • Floating Text - Change (Last created floating text): Disable permanence
                      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                      • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
                      • Custom script: endif
            • Custom script: call RemoveLocation(udg_TempLoc)
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
Replace TRUE by true
Replace FALSE by false
JASS:
local boolean b1 = IsUnitType( u, UNIT_TYPE_DEAD) == FALSE
  local boolean b2 = IsUnitType( u, UNIT_TYPE_HERO) == TRUE
  local boolean b3 = IsUnitAlly( u, GetOwningPlayer(GetKillingUnit())) == TRUE 
  local boolean b4 = IsUnitIllusion(u) == FALSE
->
JASS:
local boolean b1 = not IsUnitType( u, UNIT_TYPE_DEAD)
  local boolean b2 = IsUnitType( u, UNIT_TYPE_HERO)
  local boolean b3 = IsUnitAlly( u, GetOwningPlayer(GetKillingUnit())) 
  local boolean b4 = not IsUnitIllusion(u)
->
JASS:
return not IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(GetKillingUnit())) and not IsUnitIllusion(GetFilterUnit())

Don't use location but real instead.

Clear your BJs into natives.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
I didn't find it, so I quickly wrote a new one.
I might lack features you need, also I didn't try it out.
You'll need Table to use this resource.
JASS:
library CustomExp initializer init /*
*************************************************************************************
*
*   Designed to add experience based on UnitTypeId and unit level
*
*************************************************************************************
*
*   */uses/*
*       
*       */ Table                                /*  -
*       */ optional RegisterPlayerUnitEvent     /*  -   
*
************************************************************************************
*
*       Settings
*/

globals
    private constant real EXP_RADIUS = 700.
    private group GROUP = CreateGroup()
    private integer array LVL_BASED
    private Table table
    private player LOCAL_PLAYER
    private constant real TIME_LIFE = 1.5
    private constant real TIME_FADE = 0.8
    private constant real SIZE_MIN  = 0.018    
    private constant real Z_OFFSET  = 50  
endglobals

    native UnitAlive takes integer id returns boolean

    private function LevelDifferenceFactor takes integer hero, integer dead returns real
        local real value = 1.//= calculate your level difference here.
        return value
    endfunction
    
    private constant function FilterUnits takes unit gainer, unit dying returns boolean
        return IsUnitType(gainer, UNIT_TYPE_HERO) and  IsUnitEnemy(gainer, GetOwningPlayer(dying)) 
    endfunction
    
    private constant function setup takes nothing returns nothing
        //LVL based exp
        set LVL_BASED[1] = 20
        set LVL_BASED[2] = 40
        //Footman gives + 10 extra exp, ghouls give + 12 extra.
        set table['hfoo'] = 10
        set table['ugho'] = 12
    endfunction

    private function core takes nothing returns boolean
        local unit dead      = GetTriggerUnit()
        local integer i      = GetUnitTypeId(dead)
        local integer lvl    = GetUnitLevel(dead)
        local integer basexp = table[i] + LVL_BASED[lvl]
        local integer finalxp  
        local unit u
        local texttag text
        
        call GroupEnumUnitsInRange(GROUP, GetUnitX(dead), GetUnitY(dead), EXP_RADIUS, null)
        loop
            set u = FirstOfGroup(GROUP)
            exitwhen u == null
            call GroupRemoveUnit(GROUP, u)
            if UnitAlive(u) and FilterUnits(u, dead) then
                /*
                *   Hero exp has to be an integer.
                */
                set finalxp = R2I(basexp*LevelDifferenceFactor(GetHeroLevel(u), lvl)+0.5) 
                call AddHeroXP(u, finalxp, true)
                /*
                *   Add your texttag here
                */
                set text = CreateTextTag()
                call SetTextTagPermanent(text, false)
                call SetTextTagLifespan(text, TIME_LIFE)
                call SetTextTagFadepoint(text, TIME_FADE)
                call SetTextTagText(text, I2S(finalxp), SIZE_MIN)
                call SetTextTagColor(text, 255, 255, 255, 255)
                call SetTextTagPos(text, GetUnitX(u), GetUnitY(u), Z_OFFSET)
                if LOCAL_PLAYER == GetOwningPlayer(u) then
                    call SetTextTagVisibility(text, true)
                endif
            endif
        endloop
        set text = null
        set dead = null
        return false
    endfunction

    private function init takes nothing returns nothing
        static if LIBRARY_RegisterPlayerUnitEvent then
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function core)
        else
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t, function core)
            set t = null
        endif
        set table = Table.create()
        set LOCAL_PLAYER = GetLocalPlayer()
        call setup()
    endfunction
endlibrary
 
Last edited:
Level 6
Joined
Dec 6, 2009
Messages
168
I changed this:
JASS:
native UnitAlive takes integer id returns boolean
Integer should be unit since you can't turn a unit into an integer :)

So I modified your system to benefit me and this is how it turned out :)
Thank you and tell me if there is some from what I have changed, + rep :D

JASS:
library CustomExp initializer init /*
*************************************************************************************
*
*   Designed to add experience based on UnitTypeId and unit level
*
*************************************************************************************
*
*   */uses/*
*       
*       */ Table                                /*  -
*       */ optional RegisterPlayerUnitEvent     /*  -   
*
************************************************************************************
*
*       Settings
*/

globals
    private constant real EXP_RADIUS = 1000.
    private group GROUP = CreateGroup()
    private integer array LVL_BASED
    private Table table
    private player LOCAL_PLAYER
    private constant real TIME_LIFE = 2.5
    private constant real TIME_FADE = 1.5
    private constant real SIZE_MIN  = 0.025    
    private constant real Z_OFFSET  = 50  
endglobals

    native UnitAlive takes unit id returns boolean

    private function LevelDifferenceFactor takes integer hero, integer dead returns real
    local real value = 1.0
    
    if ( hero == dead ) then
    else
        if ( hero == ( dead + 1 ) ) or ( hero == ( dead - 1 ) )  then
           set value = 0.90
        else
            if ( hero == ( dead + 2 )) or ( hero == ( dead - 2 ) ) then
               set value = 0.80
            else
                if ( hero == ( dead + 3 )) or ( hero == ( dead - 3 ) ) then
                   set value = 0.70
                else
                   set value = 0.00
                endif
            endif
        endif
    endif
        
        return value
    endfunction
    
    private constant function FilterUnits takes unit gainer, unit dying returns boolean
        return IsUnitType(gainer, UNIT_TYPE_HERO) and  IsUnitEnemy(gainer, GetOwningPlayer(dying)) 
    endfunction
    
    private function setup takes nothing returns nothing
        //LVL based exp
        set LVL_BASED[1] = 20
        set LVL_BASED[2] = 40
        //Footman gives + 10 extra exp, ghouls give + 12 extra.
        set table['hfoo'] = 10
        set table['ugho'] = 12
    endfunction

    private function core takes nothing returns boolean
        local unit dead      = GetTriggerUnit()
        local integer i      = GetUnitTypeId(dead)
        local integer lvl    = GetUnitLevel(dead)
        local integer basexp = table[i] + LVL_BASED[lvl]
        local integer finalxp  
        local unit u
        local texttag text
        
        call GroupEnumUnitsInRange(GROUP, GetUnitX(dead), GetUnitY(dead), EXP_RADIUS, null)
        loop
            set u = FirstOfGroup(GROUP)
            exitwhen u == null
            call GroupRemoveUnit(GROUP, u)
            if UnitAlive(u) and FilterUnits(u, dead) then
                /*
                *   Hero exp has to be an integer.
                */
                set finalxp = R2I(basexp*LevelDifferenceFactor(GetHeroLevel(u), lvl)+0.5)
                call AddHeroXP(u, finalxp, true)
                /*
                *   Add your texttag here
                */
                set text = CreateTextTag()
                call SetTextTagPermanent(text, false)
                call SetTextTagLifespan(text, TIME_LIFE)
                call SetTextTagFadepoint(text, TIME_FADE)
                call SetTextTagText(text, I2S(finalxp), SIZE_MIN)
                call SetTextTagColor(text, 51, 51, 204, 255)
                call SetTextTagPos(text, GetUnitX(dead), GetUnitY(dead), Z_OFFSET)
                if LOCAL_PLAYER == GetOwningPlayer(u) then
                    call SetTextTagVisibility(text, true)
                endif
            endif
        endloop
        set text = null
        set dead = null
        return false
    endfunction

    private function init takes nothing returns nothing
        static if LIBRARY_RegisterPlayerUnitEvent then
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function core)
        else
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t, function core)
            set t = null
        endif
        set table = Table.create()
        set LOCAL_PLAYER = GetLocalPlayer()
        call setup()
    endfunction
endlibrary
 
Status
Not open for further replies.
Top