Lobster
Old Fogey ofthe site
- Reaction score
- 90
(I need a better screenshot, if its really necessary, ill make a different one)
A material selling system based off final fantasy 12s. Sell X item A's, and Y item B's, and a reward item becomes availible at a shop. The counter then resets.
Its simple to add items, but impossible to remove items, unfortunately.
To add items call:
JASS:
Made in Vjass
JASS:
library materials initializer onInit
library materials initializer onInit
globals
private integer totalMaterials = 0
private materials array matlist
private integer array solditems
endglobals
function AddMaterial takes integer matA, integer matB, integer rwrd , integer NeededA, integer NeededB, unit shop returns nothing
set matlist[totalMaterials] = materials.create()
set matlist[totalMaterials].shopunit = shop
set matlist[totalMaterials].materialA = matA
set matlist[totalMaterials].materialB = matB
set matlist[totalMaterials].reward = rwrd
set matlist[totalMaterials].NeededA = NeededA
set matlist[totalMaterials].NeededB = NeededB
set matlist[totalMaterials].totalA = 0
set matlist[totalMaterials].totalB = 0
set totalMaterials = totalMaterials + 1
endfunction
struct materials
integer materialA = 0
integer materialB = 0
integer reward = 0
integer totalA = 0
integer totalB = 0
integer NeededA = 0
integer NeededB = 0
unit shopunit = null
endstruct
private function onSell takes nothing returns boolean
local integer i = 0
local integer imax = totalMaterials
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer( u )
call DisplayTextToPlayer( p, 0., 0., "Item sold !" )
loop
exitwhen i == imax
if GetItemTypeId( GetSoldItem() ) == matlist<i>.materialA then
set matlist<i>.totalA = matlist<i>.totalA + 1
endif
if GetItemTypeId( GetSoldItem() ) == matlist<i>.materialB then
set matlist<i>.totalB = matlist<i>.totalB + 1
endif
if matlist<i>.totalA >= matlist<i>.NeededA and matlist<i>.totalB >= matlist<i>.NeededB then
call AddItemToStock( matlist<i>.shopunit ,matlist<i>.reward, 1, 1 )
set matlist<i>.totalA = 0
set matlist<i>.totalB = 0
endif
set i = i+1
endloop
set p = null
set u = null
return false
endfunction
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PAWN_ITEM)
call TriggerAddCondition( t, Condition( function onSell ) )
endfunction
endlibrary</i></i></i></i></i></i></i></i></i></i></i></i></i></i>
Link:
http://www.epicwar.com/maps/127999/
Now uses komaqtion's code