• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[JASS] Percentage gold reduction

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
I seem to have run into a stumbling block. I tried to reduce it(gold). It returned 0. I tried it by converting it to a real. But it still returned 0. I tried to do the equation first and then do it that way. I ran into a problem with meshing a real and an integer. Any ideas?
 
Maybe:
  • Untitled Trigger 002
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player 1 (Red) Current gold) Less than (<) 100
        • Then - Actions
          • Player - Add -1 to Player 1 (Red) Current gold
        • Else - Actions
          • Player - Set Player 1 (Red) Current gold to ((Player 1 (Red) Current gold) - ((Player 1 (Red) Current gold) / 100))
 
this is the last one I attempted. I didnt even finish the second part as i noticed the first gold reduction failed:
JASS:
function Trig_Computer_Kills_Light_Conditions takes nothing returns boolean
    if ( not ( GetDyingUnit() == udg_Player_Hero[GetPlayerId(GetOwningPlayer(GetDyingUnit()))] ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(GetKillingUnit()) == Player(11) ) ) then
        return false
    endif
    if ( not ( IsPlayerInForce(GetOwningPlayer(GetDyingUnit()), udg_Ability_Pheonix) == false ) ) then
        return false
    endif
    if ( not ( IsUnitInGroup(GetTriggerUnit(), udg_Creation_Group) == false ) ) then
        return false
    endif
    return true
endfunction

function Trig_Computer_Kills_Light_Actions takes nothing returns nothing
    local unit d = GetTriggerUnit()
    local unit k = GetKillingUnit()
    local player p = GetOwningPlayer(d)
    local real x = GetUnitX(d)
    local real y = GetUnitY(d)
    local integer seventy = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) * R2I(.70)
    local integer fifty = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) * R2I(.50)
    local integer thirty = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) * R2I(.30)
    local location base
    call DisplayTextToPlayer(p, x, y, I2S(seventy))
    call DestroyEffect(AddSpecialEffect("Units\\NightElf\\Wisp\\WispExplode.mdl", x, y))
    if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "TRIGSTR_241")
    endif
    if ( (GetRectMinX(gg_rct_SeventyLoss) <= x) and (x <= GetRectMaxX(gg_rct_SeventyLoss)) and (GetRectMinY(gg_rct_SeventyLoss) <= y) and (y <= GetRectMaxY(gg_rct_SeventyLoss)) ) then
        set udg_Gold = GetPlayerState((p), PLAYER_STATE_RESOURCE_GOLD) - seventy
        set udg_Loss_Amount[GetPlayerId(p)] = ( udg_Loss_Amount[GetPlayerId(p)] + udg_Gold )
        call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, - udg_Gold)
    else
        set udg_Gold = GetPlayerState((p), PLAYER_STATE_RESOURCE_GOLD)
        set udg_Loss_Amount[GetPlayerId(p)] = ( udg_Loss_Amount[GetPlayerId(p)] + udg_Gold )
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, 0 )
    endif
    call MultiboardSetItemValueBJ( GetLastCreatedMultiboard(), 3, ( udg_Rows[GetPlayerId(p)] + 1 ), I2S(udg_Loss_Amount[GetPlayerId(p)]) )
    if ( GetHeroLevel(GetDyingUnit()) > 5 ) then
        call TriggerSleepAction( 25.00 )
    else
        call TriggerSleepAction( 15.00 )
    endif
    set base = Location(GetRectCenterX(gg_rct_Dark_Base_Hero), GetRectCenterY(gg_rct_Dark_Base_Hero))
    if (GetLocalPlayer() == p) then
        call PanCameraToTimed(GetLocationX(base), GetLocationY(base), 2.00)
        call ResetToGameCamera(1.00)
    endif
    call ReviveHeroLoc( d, base, true )
    call RemoveLocation(base)
    set d = null
    set k = null
    set p = null
endfunction

Any optimizations are also approved :P Is there anyway to remove all those "if(not" ?? But ya. This is what I have. Any help is greatly appreciated.
 
JASS:
function Trig_Computer_Kills_Light_Conditions takes nothing returns boolean
    return GetTriggerUnit() == udg_Player_Hero[GetPlayerId(GetTriggerPlayer())] and GetOwningPlayer(GetKillingUnit()) == Player(11) and not IsPlayerInForce(GetTriggerPlayer(), udg_Ability_Pheonix) and not IsUnitInGroup(GetTriggerUnit(), udg_Creation_Group) 
endfunction
    
function Trig_Computer_Kills_Light_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetTriggerPlayer()
    local integer id = GetPlayerId(p)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local integer seventy = R2I(GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) * 0.7)
    
    // R2I truncates after the decimal point, turning any number below 1 into
    // 0, so you want to do R2I with the total gold amount, not with the 0.7.
    
    call DisplayTextToPlayer(p, 0, 0, I2S(seventy))
    call DestroyEffect(AddSpecialEffect("Units\\NightElf\\Wisp\\WispExplode.mdl", x, y))
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "TRIGSTR_241")
    if ( (GetRectMinX(gg_rct_SeventyLoss) <= x) and (x <= GetRectMaxX(gg_rct_SeventyLoss)) and (GetRectMinY(gg_rct_SeventyLoss) <= y) and (y <= GetRectMaxY(gg_rct_SeventyLoss)) ) then
        set udg_Gold = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) - seventy
        set udg_Loss_Amount[id] = udg_Loss_Amount[id] + udg_Gold
        call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, - udg_Gold)
    else
        set udg_Gold = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
        set udg_Loss_Amount[id] = udg_Loss_Amount[id] + udg_Gold
        call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, 0 )
    endif
    call MultiboardSetItemValueBJ(bj_lastCreatedMultiboard, 3, udg_Rows[id] + 1, I2S(udg_Loss_Amount[id]) )
    if ( GetHeroLevel(u) > 5 ) then
        call TriggerSleepAction( 25.00 )
    else
        call TriggerSleepAction( 15.00 )
    endif
    set x = GetRectCenterX(gg_rct_Dark_Base_Hero)
    set y = GetRectCenterY(gg_rct_Dark_Base_Hero)
    if (GetLocalPlayer() == p) then
        call PanCameraToTimed(x, y, 2.00)
        call ResetToGameCamera(1.00)
    endif
    call ReviveHero(u, x, y, true )
    set u = null
    set p = null
endfunction

This is only partially optimized, but I found the flaw (commented)
 
okay, I partially understand most of that. However, the flaw you mentioned, That was my initial problem, trying to calculate gold loss through a percentage. As you can see, I want gold loss to be 70% of the total value of the GetOwningPlayer(u) (I think I caught a hiccup there as well. The player is not triggering the function, the unit is).

EDIT: I familiarized (hopefully) the rest of it.

Are you saying that the calculation has to be done through a real? In doing that, would I convert the gold amount to a real first, then calculate, and transfer it back?
 
Status
Not open for further replies.
Back
Top