JASS code help

Troll

New Member
Reaction score
4
Code:
// SHARED BOUNTY SYSTEM by ANDREWGOSU.
// ver. 1.2.

// Requires JASS NewGen Pack.

globals
    //LEAVE THESE UNCHANGED
    boolexpr ALLIE_INDICATOR
    boolean array PLAYER_INDICATOR

    //CONFIGURATION

    //SYSTEM
    constant real    RADIUS   = 756. //The radius where the gold is distributed.
    constant integer HANDICAP = 100  //The bounty handicap. E.g 50 is half the normal bounty, 200 double the normal.

    //APPEREANCE
    constant string TEXTTAG_COLOUR  = "|cffffcc00"                                //Colour code of the texttag.
    constant string BOUNTY_ART      = "UI\\Feedback\\GoldCredit\\GoldCredit.mdl"  //Model path of the bounty art.
    constant string ATTACHMENTPOINT = "overhead"                                  //Attachmentpoint of the bounty art.
    
    //TEXTTAG CONFIGURATION
    constant integer TEXTTAG_TEXTSIZE  = 11  //The size of the texttag text.
    constant real    TEXTTAG_VELOCITY  = 64. //Texttag's velocity.
    constant real    TEXTTAG_ANGLE     = 90. //Texttag's angle.
    constant real    TEXTTAG_LIFESPAN  = 5.  //Texttag's lifespan.
    constant real    TEXTTAG_FADEPOINT = 4.  //Texttag's fading point.
endglobals

// SYSTEM
function SharedBounty_Allied takes nothing returns boolean
    return (IsUnitAlly( GetKillingUnit(), GetOwningPlayer(GetFilterUnit()) ) == true)
endfunction

function SharedBounty_Gold takes integer level returns integer
    if     ( level == 1 ) then
        return GetRandomInt( 4, 6 )
    elseif ( level == 2 ) then
        return GetRandomInt( 6, 8 )
    elseif ( level == 3 ) then
        return GetRandomInt( 8, 10 )
    elseif ( level == 4 ) then
        return GetRandomInt( 11, 15 )
    elseif ( level == 5 ) then
        return GetRandomInt( 20, 26 )
    elseif ( level == 6 ) then
        return GetRandomInt( 44, 52 )
    elseif ( level == 7 ) then
        return GetRandomInt( 55, 65 )
    elseif ( level == 8 ) then
        return GetRandomInt( 76, 88 )
    elseif ( level == 9 ) then
        return GetRandomInt( 107, 121 )
    elseif ( level == 10 ) then
        return GetRandomInt( 158, 174 )
    endif
    return 0
endfunction

function SharedBounty_TextTag takes integer bounty, unit receiver returns nothing
    local texttag t          = CreateTextTag()
    local real    textHeight = TextTagSize2Height(TEXTTAG_TEXTSIZE)
    local real    vel        = TextTagSpeed2Velocity(TEXTTAG_VELOCITY)
    local real    xvel       = vel * Cos(TEXTTAG_ANGLE * bj_DEGTORAD)
    local real    yvel       = vel * Sin(TEXTTAG_ANGLE * bj_DEGTORAD)
    
    if ( GetLocalPlayer() == GetOwningPlayer(receiver) ) then
        call SetTextTagText(t, TEXTTAG_COLOUR + "+" + I2S(bounty) + "|r", textHeight)
        call SetTextTagPos( t, GetUnitX(receiver), GetUnitY(receiver), 0 )
        call SetTextTagColor( t, 0, 0, 0, 255 )
        call SetTextTagPermanent( t, false )
        call SetTextTagVelocity(t, xvel, yvel)
        call SetTextTagLifespan( t, TEXTTAG_LIFESPAN )
        call SetTextTagFadepoint( t, TEXTTAG_FADEPOINT )
        call SetTextTagVisibility( t, true )
    endif
    
    set t = null
endfunction

function SharedBounty_CreateBounty takes nothing returns nothing
    local group   g     = CreateGroup()
    local unit    a     = GetTriggerUnit()
    local integer level = GetUnitLevel(a)
    local integer i     = 0
    local integer id
    local unit    receiver
    local player  owner
    local integer amount
    local unit array receivers
    
    call DestroyEffect(AddSpecialEffectTarget(BOUNTY_ART, a, ATTACHMENTPOINT))
    loop
        exitwhen ( i == bj_MAX_PLAYERS )
        set PLAYER_INDICATOR[i] = true
        set i = i + 1
    endloop
    set i = 0
    call GroupEnumUnitsInRange( g, GetUnitX(a), GetUnitY(a), RADIUS, ALLIE_INDICATOR )
    loop
        set receiver = FirstOfGroup(g)
        exitwhen ( receiver == null )
        set owner = GetOwningPlayer(receiver)
        set id    = GetPlayerId(owner)
        if ( IsUnitType( receiver, UNIT_TYPE_HERO ) == true ) then
            if ( PLAYER_INDICATOR[id] == true ) then
                set PLAYER_INDICATOR[id] = false
                set i = i + 1
                set receivers[i] = receiver
            endif
        endif
        call GroupRemoveUnit( g, receiver )
    endloop
    call DestroyGroup(g)
    set amount = SharedBounty_Gold(level) / i * (HANDICAP / 100)
    if ( amount < 1 ) then
       set amount = 1
    endif   
    loop
        exitwhen ( i == 0 )
        set owner = GetOwningPlayer(receivers[i])
        call SetPlayerState( owner, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD) + amount )
        call SharedBounty_TextTag( amount, receivers[i] )
        set receivers[i] = null
        set i = i - 1
    endloop
    
    set a        = null
    set g        = null
    set receiver = null
    set owner    = null
endfunction

function InitTrig_SharedBounty takes nothing returns nothing
    set gg_trg_SharedBounty = CreateTrigger()
    set ALLIE_INDICATOR = Condition(function SharedBounty_Allied)
    call TriggerRegisterPlayerUnitEvent( gg_trg_SharedBounty, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH, null )
    call TriggerAddAction( gg_trg_SharedBounty, function SharedBounty_CreateBounty )   
    call SetPlayerState( Player(PLAYER_NEUTRAL_AGGRESSIVE), PLAYER_STATE_GIVES_BOUNTY, IntegerTertiaryOp( false, 1, 0 ) )
endfunction


this is the shared bounty system from theresources section i guess i can edit it? right? because is a free resource and all. but but i don' know , just a very poor one .. anyways, this shares the bounty for all players who attack the same unit equal to how much dmg they did on the target, now the problem is this only gives bounty if the attacking unit is a hero and the attacked unti is a neutral hostile, can you modify it or tell me how to so they can share gold only with attacking player units? i am making a footmen map and i would like t oadd this system, understand? so, it can trigger with units owned by players too .. but dispalying can it be posible?


and btw how to make it so it works with buildings too? in short words, i want this code modified so it can be used to share the bounty in a footmen frenzy map. which is only pvp . you know
 

Yizzy

New Member
Reaction score
20
I'm not experianced with Jass, but I would look at the line:
Code:
if ( IsUnitType( receiver, UNIT_TYPE_HERO ) == true ) then

and
Code:
call TriggerRegisterPlayerUnitEvent( gg_trg_SharedBounty, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH, null )

..
 

saw792

Is known to say things. That is all.
Reaction score
280
Well it really should... it's fairly straightforward once you've been given the lines to edit.

Anyway, if you want it to work when any unit makes a kill, and not just a hero change this section:
JASS:
//Ignore this comment.. it is for formatting only
        set id    = GetPlayerId(owner)
        if ( IsUnitType( receiver, UNIT_TYPE_HERO ) == true ) then
            if ( PLAYER_INDICATOR[id] == true ) then
                set PLAYER_INDICATOR[id] = false
                set i = i + 1
                set receivers<i> = receiver
            endif
        endif
        call GroupRemoveUnit( g, receiver )</i>

to this:
JASS:
//Ignore this comment.. it is for formatting only
        set id    = GetPlayerId(owner)
            if ( PLAYER_INDICATOR[id] == true ) then
                set PLAYER_INDICATOR[id] = false
                set i = i + 1
                set receivers<i> = receiver
            endif
        call GroupRemoveUnit( g, receiver )</i>


If you want it to work for killing any player units change this:
to this:

Enjoy.
 

Troll

New Member
Reaction score
4
Well it really should... it's fairly straightforward once you've been given the lines to edit.

Anyway, if you want it to work when any unit makes a kill, and not just a hero change this section:
JASS:
//Ignore this comment.. it is for formatting only
        set id    = GetPlayerId(owner)
        if ( IsUnitType( receiver, UNIT_TYPE_HERO ) == true ) then
            if ( PLAYER_INDICATOR[id] == true ) then
                set PLAYER_INDICATOR[id] = false
                set i = i + 1
                set receivers<i> = receiver
            endif
        endif
        call GroupRemoveUnit( g, receiver )</i>

to this:
JASS:
//Ignore this comment.. it is for formatting only
        set id    = GetPlayerId(owner)
            if ( PLAYER_INDICATOR[id] == true ) then
                set PLAYER_INDICATOR[id] = false
                set i = i + 1
                set receivers<i> = receiver
            endif
        call GroupRemoveUnit( g, receiver )</i>


If you want it to work for killing any player units change this:
to this:

Enjoy.


thx so much to you mate! rep+


btw it shows the additional gold text over the hero, what i need to modify so it shows the text over the killing unit?
 

Troll

New Member
Reaction score
4
bump? i know you need 24 ours but i think people just forgot about this thread and will not see my edit on the last post.
 

Builder Bob

Live free or don't
Reaction score
249
change the function SharedBounty_TextTag to take the killing unit as well.
JASS:
function SharedBounty_TextTag takes unit killingUnit, integer bounty, unit receiver returns nothing


modify the function call to include the killing unit.
JASS:
call SharedBounty_TextTag(GetKillingUnit(), amount, receivers<i>)</i>


set the text tag position to the killing unit.
JASS:
call SetTextTagPos( t, GetUnitX(killingUnit), GetUnitY(killingUnit), 0 )


set killingUnit to null at the end of the function SharedBounty_TextTag to prevent leaking.
JASS:
set killingUnit = null



Edit: now that I look over it again, a lot more should be changed if you want the text tag to only show over the killing unit. As it is now it looks like the bounty shows over every unit that gets the bounty. I don't have too much time to change that much. Sorry. I hope someone will help you do the necessary changes

With the changes I suggested, one texttag per unit that receives the bounty will be shown above the killing unit. Quite inefficient, I know.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top