• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Unit gain xp in range

Status
Not open for further replies.
Level 3
Joined
Mar 20, 2008
Messages
27
JASS:
function Trig_JassExp_Actions takes nothing returns nothing
   local player ow = Player ( PLAYER_NEUTRAL_AGGRESIVE )
   local unit dy = GetDyingUnit ()
   local unit he
   local real x = GetUnitX ( dy )
   local real y = GetUnitY ( dy )
   local real rd = 1024.00
   local hl
   local ml = GetUnitLevel ( dy )
   local integer xp = ( 10 * ml )
   local group hg = CreateGroup ()
     call GroupEnumUnitsInRange ( hg, x, y, rd, null )
loop
   set he = FirstOfGroup ( hg )
   set hl = GetUnitLevel ( he )
exitwhen he == null
if IsUnitEnemy ( he, ow ) == true then
   call AddHeroXP ( he, xp, true )
endif
   set hl = 0
   call GroupRemoveUnit ( hg, he )
endloop
   call DestroyGroup ( hg )
set ow = null
set rd = 0
set x = 0
set y = 0
set hg = null
set he = null
set dy = null
set xp = 0
set ml = 0
endfunction

//=====
function InitTrig_JassExp takes nothing returns nothing
   local trigger JassExpT = CreateTrigger ()
   call TriggerRegisterAnyUnitEventBJ ( JassExpT, EVENT_PLAYER_UNIT_DEATH )
   call TriggerAddAction ( JassExpT, function Trig_JassExp_Actions )
endfunction
This script works, but what i want to do is add a limit, i give an example:
Hero level 2 kills creep level 1 gains 10 xp (that works)
hero level 5 kills creep level 1 gains 0 xp.
there should be a maximum level and minimum level to the hero vs the creep to get a level.
Any Help Appreciated hope i didn't confuse you ;)
 
Last edited:
Level 5
Joined
Dec 18, 2007
Messages
205
hi.

first of all you can replace this line
JASS:
call GroupAddGroup ( hg, GetUnitsInRangeOfLocAll ( rd, p ) )
with
JASS:
set hg=GetUnitsInRangeOfLocAll(rd,p)
because it's faster and doing the same.

i think the error is in this line:

JASS:
if IsUnitEnemy ( he, ow ) == true then

because only hero can get xp, correct?
try replacing it with
JASS:
if IsUnitEnemy(he,ow)==true and IsUnitType(he,UNIT_TYPE_HERO)==true then

also you can shorten your if statement to this:
JASS:
if IsUnitEnemy(he,ow)==true and IsUnitType(he,UNIT_TYPE_HERO)==true then
 call AddHeroXP ( he, xp, true )
 call BJDebugMsg ("Yes XP")
else
 call BJDebugMsg ("No XP")
endif
call GroupRemoveUnit ( hg, he )
so you don't need that groupremoveunit() twice because it is done anyways.

finally you don't need to clear all variables. reals and integers dont need to be nulled. so just skip these two actions
JASS:
set rd = 0
set xp = 0

greetings

edit: lol, you just edited, when i was writing this, i'll have to read it again^^

so, once again.

first of all this does not work:

JASS:
   local hl
   local ml = GetUnitLevel ( dy )

because u must define them like this:

JASS:
   local integer hl
   local integer ml = GetUnitLevel ( dy )

so to make getting xp like this you must varify the xp in every loop-run.

skip this:
JASS:
   local integer xp = ( 10 * ml )
so it's just
JASS:
   local integer xp

then place an action in the THEN-action of the if-statement (replace the if like in the previous post to only run when the unit is a hero, this saves space)

JASS:
if ... then
    set xp=R2I((12.5-I2R(GetHeroLevel(he))*2.5)*I2R(ml))
    if xp<0 then
        set xp=0
    endif
    call AddHeroXP ( he, xp, true )
endif

this will add xp that gets lower until the hero is level 5
level 1=100%xp
level 2=75%xp
..
level 5=0%xp

greetings

eidt: just saw what you wanted.

for an min-max-level creep-hero xp-system (what a name^^)
i suggest using something like the following (a bit complicated):

JASS:
set xp=R2I(((10.+I2R(GetUnitLevel(dy))*2.5)-(I2R(GetHeroLevel(he))*2.5))*I2R(GetUnitLevel(dy)))

to summarize it:
JASS:
creep-level  hero-level   xp-rate   xp received
1            2            75%       7
1            5+           0%        0
3            5            50%       15
7            5            150%      105

xp given: xp-rate*(10*level of dying unit)

if you have any questions don't hesitate to ask, it IS quite complex
 
Last edited by a moderator:
Level 3
Joined
Mar 20, 2008
Messages
27
Okay i got your idea the script looks like the following:
JASS:
function Trig_JassExp_Actions takes nothing returns nothing
    local player ow = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local unit dy = GetDyingUnit()
    local unit he
    local real x = GetUnitX(dy)
    local real y = GetUnitY(dy)
    local real rd = 1024.
    local integer hl
    local integer ml = GetUnitLevel(dy)
    local integer xp = ml*10
    local group hg = CreateGroup()
    call GroupEnumUnitsInRange(hg, x, y, rd, null)
    loop
        set he = FirstOfGroup(hg)
        set hl = GetUnitLevel(he)
        exitwhen he == null
        if IsUnitEnemy(he, ow) == true And(IsUnitType(he, UNIT_TYPE_HERO)) == true And(GetUnitLevel(hl) >= GetUnitLevel(ml)-4) And(GetUnitLevel(hl) <= GetUnitLevel(ml)+4) then
            call AddHeroXP(he, xp, true)
        endif
            call GroupRemoveUnit(hg, he)
    endloop
    call DestroyGroup(hg)
    set ow = null
    set hg = null
    set he = null
    set dy = null
endfunction
//===========================================================================
function InitTrig_JassExp takes nothing returns nothing
    local trigger JassExpT = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(JassExpT, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction(JassExpT, function Trig_JassExp_Actions)
endfunction
I will be thinking about systems, that could help.
And as you say, it complicated ( i always get into complicated situations :bored: )
Edit:
The system i talks about should be like this:
Creep lvl X give X * 10 xp UNLESS
hero is 5 lvls higher than X
hero is 5 lvls lower than X.
That should be a bit more understandable ( For me it is, :D )
Updated the script to where i have come, and now i get the error on the "if" line its says " Expected 'then' "
2nd edit:
Okay i solved it here's what the script looks like :D
JASS:
function Trig_JassExp_Actions takes nothing returns nothing
    local player ow = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local unit dy = GetDyingUnit()
    local unit he
    local real x = GetUnitX(dy)
    local real y = GetUnitY(dy)
    local real rd = 1024.
    local integer hl
    local integer ml = GetUnitLevel(dy)
    local integer xp = ml*10
    local group hg = CreateGroup()
    call GroupEnumUnitsInRange(hg, x, y, rd, null)
    loop
        set he = FirstOfGroup(hg)
        set hl = GetUnitLevel(he)
        exitwhen he == null
        if IsUnitEnemy(he, ow) == true and (IsUnitType(he, UNIT_TYPE_HERO)) == true and ( hl >= ml-4) and (hl <= ml+4)  then
            call AddHeroXP(he, xp, true)
        endif
            call GroupRemoveUnit(hg, he)                                               
    endloop
    call DestroyGroup(hg)
    set ow = null
    set hg = null
    set he = null
    set dy = null
endfunction
//===========================================================================
function InitTrig_JassExp takes nothing returns nothing
    local trigger JassExpT = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(JassExpT, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction(JassExpT, function Trig_JassExp_Actions)
endfunction
 
Last edited:
Level 3
Joined
Mar 20, 2008
Messages
27
It seems so, but now i've been working on a new script, where i get tons of errors, should i post it here or make a new thread ?
 
Level 5
Joined
Dec 18, 2007
Messages
205
post here and i will look and some others myb too.
make a new thread and i must find it first, but then other persons know what you want can help you faster than i can.
 
Status
Not open for further replies.
Top