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

[Solved] bug in trigger

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi,
this trigger give gold to a unit "shop" when a player put an item into the shop and use the "shop" ability sell.
but strangely it give 6 times the amount it should, so i guess there is a problem in the loop inventory trigger wich detect the items and quantity to sell the total gold to give.

[Jass=]
function Sell_Actions takes nothing returns nothing
local integer i = 0
local integer value = 0
local integer quantity = 0
local integer total = 0
local integer team = 0
local integer bonus = 0
local integer bonus1 = 0
local integer bonus2 = 0
local real x
local real y
local unit seller
local item it
local player owner
// Set variables
set seller = GetTriggerUnit()
set x = GetUnitX(seller)
set y = GetUnitY(seller)
set owner = udg_SelectTempPlayer[GetUnitUserData(seller)]
// Set team of selling unit
if IsUnitInForce(seller, udg_Team[1]) == true then
set team = 1
elseif IsUnitInForce(seller, udg_Team[2]) == true then
set team = 2
elseif IsUnitInForce(seller, udg_Team[3]) == true then
set team = 3
endif
// This loop in the inventory of selling unit, check if slot has an item, if so it run the function "GetItemGoldCostById()" to find the gold cost of item and store it into 'value'.
// it store the charge of the item in 'quantity' and add the (value x quantity) to the 'total'.
loop
exitwhen i > 5
if UnitItemInSlot(seller, i) != null then
set value = GetItemGoldCostById(GetItemTypeId(UnitItemInSlot(seller, i)))
set quantity = GetItemCharges(UnitItemInSlot(seller, i))
endif
if GetItemTypeId(UnitItemInSlot(seller, i)) == 'I066' then
set udg_Ring_boolean = false
call KillUnit( udg_Ring_Resurrect )
endif
if value > 0 then
set total = total + ( value * quantity )
call RemoveItem( UnitItemInSlot(seller, i) )
endif
set i = i + 1
endloop
if total != 0 then
if team != 0 then
set udg_Job_Merchant_Xp[team] = ( udg_Job_Merchant_Xp[team] + ( total * 2 ) )
if udg_Job_Merchant_Lvl[team] < 3 then
set udg_B = team
call TriggerExecute( gg_trg_Merchant_Lvl )
endif
if udg_Job_Merchant_Lvl[team] > 0 then
set bonus1 = total * udg_Job_Merchant_Lvl[team]
set bonus2 = bonus1 / 10
if bonus2 >= 1 then
set bonus = bonus2
endif
endif
endif
set it = CreateItem( 'I03B', x, y )
call SetItemCharges( it, ( total + bonus ) )
call UnitAddItem( seller, it )
call DisplayTimedTextToPlayer( owner, 0, 0, 6.00, "|c0000c400Troll:|r |c00ffff64Me haz made " + I2S(total) + " Goldz with|r |c00ffff64" + I2S(bonus) + " bonus.|r" )
else
call DisplayTimedTextToPlayer( owner, 0, 0, 6.00, "|c0000c400Troll:|r |c00ffff64Ther'z no valuable itemz to sell, mon!|r" )
endif
set seller = null
set it = null
set owner = null
endfunction

//===========================================================================
function InitTrig_Recipe_Sell takes nothing returns nothing
set gg_trg_Recipe_Sell = CreateTrigger( )
call TriggerAddAction( gg_trg_Recipe_Sell, function Sell_Actions )
endfunction
[/code]
 
Level 4
Joined
Jan 27, 2010
Messages
133
JASS:
loop
        exitwhen i > 5

// Must re-set every time loop iterates
        set value=0
        set quantity=0

        if UnitItemInSlot(seller, i) != null then
            set value = GetItemGoldCostById(GetItemTypeId(UnitItemInSlot(seller, i)))
            set quantity = GetItemCharges(UnitItemInSlot(seller, i))
        endif
        if GetItemTypeId(UnitItemInSlot(seller, i)) == 'I066' then
            set udg_Ring_boolean = false
            call KillUnit( udg_Ring_Resurrect )
        endif
        if value > 0 then
            set total = total + ( value * quantity )
            call RemoveItem( UnitItemInSlot(seller, i) )
        endif
        set i = i + 1
    endloop
 
Status
Not open for further replies.
Top