- Joined
- Nov 13, 2006
- Messages
- 1,814
i want show this methode because i think maybe somebody think its usefull and make a tutorial witj correct english
Few word about system:
- i use unit models for make visually a gathering, each second decrease the target hp until u channel the harvest hidden ability, but if channel ability interrupted then target(materia) healed back, also until harvesting process cant harvest another unit same materia
- i use harvest ability simple reason: i use villager npc and melee ranged transform but if i use ability with 50 range then ranged villager also act like melee, since during this proces i remove unit attachment and replace with pickle, after harvest provcess i remove pickle and reattach the weapon
- npc's sleeping at night, and their house have sleeping effect
- any hero can harvest who got harvest hidden ability, so players too not just bots
- can make more harvester npc, with different job, atm for me 1 harvest herbs another harvest mats.
- when harvester bot return to home then give the harvested items to home and u can buy their, so acctually bots store every collected item at their house (like in settlers), when u buy 1 item then its decrease the item stock in house or in unit by 1.
- u can craft item with mats at market npc (ofc if dont have enough mats then its dont crafted), with progressbar (look like crafting but unit training and unit will removed after item is created)
Now coming the buggy part:
- if u buy from harvester bot during harvesting process then u interupt his job for 1 sec
- sometimes bots go away for a short time but return back to job
so if somebody can fix it the its a fairly good system if u improve this idea line
i upload the map and few ss, also snce i alot time replace the attachment files, i dont gived credits yet, but if somebody want use this attachment pls do that
@Hashjie - not just for rpg, its new way in strategy
Image this because possible:
since every harvester can do cuztomizable job, also easy add a new one if we use 1 timer + linked list for indexing harvesters
- 1 harvester cut down tree, 1 extract stone, 1 extract iron and bring to material headquearter and u build buildings via this materia, so gold+lumber building is past, u can use any materia for building, same like at crafting
- since each headqueater can store 11-12 item type, u can make 1 for constr. materials, 1 for food, 1 for raw food materia (flour,wheat,water etc)
- 1 harvester gather wheat and seed it when he cant harvest in x range more wheat. then 1 carrier harvester bot bring mats to hq, bring wheat to mill, another carry bring flour and water to bakery
- harvester bots could change profession easily if u use a integer array (ex: Job[harvester cv]=x, example 1 woodcutter,2 forester,3 farmer, 4 miller, 5 baker, 6 stone manson ..... 99 carry, 100 soldier, etc)
- if make harvest bots t hero, then u can level up them and example a lv10 woodcutter could be also carpenter etc etc etc
maybe u understand this is a new way, so u can do settler/culture kind from normal wc3
Header & map init
harvest creating (if u modify then u can use linked list so then u can customize easily and change his job with simple select diff. target than normal)
buffing+harvesting same timer
rest harvest thing
the engine, maybe here the problem why the bot hit the target and after 3 sec run away then run back and continue and finish the harvesting
home/sleeping
decrease stock item
Few word about system:
- i use unit models for make visually a gathering, each second decrease the target hp until u channel the harvest hidden ability, but if channel ability interrupted then target(materia) healed back, also until harvesting process cant harvest another unit same materia
- i use harvest ability simple reason: i use villager npc and melee ranged transform but if i use ability with 50 range then ranged villager also act like melee, since during this proces i remove unit attachment and replace with pickle, after harvest provcess i remove pickle and reattach the weapon
- npc's sleeping at night, and their house have sleeping effect
- any hero can harvest who got harvest hidden ability, so players too not just bots
- can make more harvester npc, with different job, atm for me 1 harvest herbs another harvest mats.
- when harvester bot return to home then give the harvested items to home and u can buy their, so acctually bots store every collected item at their house (like in settlers), when u buy 1 item then its decrease the item stock in house or in unit by 1.
- u can craft item with mats at market npc (ofc if dont have enough mats then its dont crafted), with progressbar (look like crafting but unit training and unit will removed after item is created)
Now coming the buggy part:
- if u buy from harvester bot during harvesting process then u interupt his job for 1 sec
- sometimes bots go away for a short time but return back to job
so if somebody can fix it the its a fairly good system if u improve this idea line
i upload the map and few ss, also snce i alot time replace the attachment files, i dont gived credits yet, but if somebody want use this attachment pls do that
@Hashjie - not just for rpg, its new way in strategy
Image this because possible:
since every harvester can do cuztomizable job, also easy add a new one if we use 1 timer + linked list for indexing harvesters
- 1 harvester cut down tree, 1 extract stone, 1 extract iron and bring to material headquearter and u build buildings via this materia, so gold+lumber building is past, u can use any materia for building, same like at crafting
- since each headqueater can store 11-12 item type, u can make 1 for constr. materials, 1 for food, 1 for raw food materia (flour,wheat,water etc)
- 1 harvester gather wheat and seed it when he cant harvest in x range more wheat. then 1 carrier harvester bot bring mats to hq, bring wheat to mill, another carry bring flour and water to bakery
- harvester bots could change profession easily if u use a integer array (ex: Job[harvester cv]=x, example 1 woodcutter,2 forester,3 farmer, 4 miller, 5 baker, 6 stone manson ..... 99 carry, 100 soldier, etc)
- if make harvest bots t hero, then u can level up them and example a lv10 woodcutter could be also carpenter etc etc etc
maybe u understand this is a new way, so u can do settler/culture kind from normal wc3
Header & map init
JASS:
function AddUnitToMatList takes unit u returns nothing
local integer i = 0
loop
exitwhen udg_H_HUA[i] == null
set i = i + 1
endloop
set udg_H_HUA[i] = u
if i > udg_H_Mat_Index then
set udg_H_Mat_Index = i
endif
endfunction
function SearchUnitInMatList takes integer t, integer cv returns integer
local integer i = 0
local integer f = - 1
local integer pv
local integer cvhq = GetUnitUserData( udg_H_Home[cv] )
local integer stock
local real gtime = GetTimeOfDay( )
loop
exitwhen i > udg_H_Mat_Index or f != - 1
set cv = GetUnitUserData( udg_H_HUA[i] )
if udg_Buff_Harvest[cv] == false and gtime < 18.00 and gtime > 6.00 and udg_H_HUA[i] != null and udg_H_Target[cv] == null then
set pv = GetUnitPointValue( udg_H_HUA[i] )
set stock = LoadInteger( udg_H_Stock_Table, cvhq, pv )
if stock < udg_H_StockMax then
if t==1 then
if pv < 50 then
set f = i
endif
elseif t==2 then
if pv >= 50 then
set f = i
endif
endif
endif
endif
set i = i + 1
endloop
return f
endfunction
function RemoveUnitFromMatList takes unit u returns nothing
local integer i = 0
loop
exitwhen udg_H_HUA[i] == u
set i = i + 1
endloop
set udg_H_HUA[i] = null
if i == udg_H_Mat_Index then
set udg_H_Mat_Index = udg_H_Mat_Index - 1
endif
endfunction
harvest creating (if u modify then u can use linked list so then u can customize easily and change his job with simple select diff. target than normal)
JASS:
local integer i = 0
local integer a
local integer v = 1
local integer cv
local integer t
local unit u
local real x
local real y
set x = GetRandomReal(GetRectMinX(udg_Region[1]), GetRectMaxX(udg_Region[1]))
set y = GetRandomReal(GetRectMinY(udg_Region[1]), GetRectMaxY(udg_Region[1]))
set udg_HarvesterBot[0] = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'n005', x, y, 0 )
set x = GetRandomReal(GetRectMinX(udg_Region[0]), GetRectMaxX(udg_Region[0]))
set y = GetRandomReal(GetRectMinY(udg_Region[0]), GetRectMaxY(udg_Region[0]))
set cv = GetUnitUserData(udg_HarvesterBot[0])
set udg_H_Job[cv] = 1
set udg_H_Home[cv] = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'n007', x, y, 0 )
set x = GetRandomReal(GetRectMinX(udg_Region[1]), GetRectMaxX(udg_Region[1]))
set y = GetRandomReal(GetRectMinY(udg_Region[1]), GetRectMaxY(udg_Region[1]))
call TriggerRegisterUnitInRange( gg_trg_Harvester_home, udg_H_Home[cv], 50.00, null )
set udg_HarvesterBot[1] = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'n008', x, y, 0 )
set x = GetRandomReal(GetRectMinX(udg_Region[0]), GetRectMaxX(udg_Region[0]))
set y = GetRandomReal(GetRectMinY(udg_Region[0]), GetRectMaxY(udg_Region[0]))
set cv = GetUnitUserData(udg_HarvesterBot[1])
set udg_H_Job[cv] = 2
set udg_H_Home[cv] = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'n009', x, y, 0 )
call TriggerRegisterUnitInRange( gg_trg_Harvester_home, udg_H_Home[cv], 50.00, null )
buffing+harvesting same timer
JASS:
function Trig_Timer_Actions takes nothing returns nothing
local integer buffvalue // R2I(Pow(buffid, 2)) buffvalue what i add to unit buff value
local integer bv //buff value
local integer i = 0
local integer pv = 0
local integer cc
local integer po = 0
local integer cv
local integer count = 0
local integer buffid = 0
local integer maxbuff = udg_Buff_Max
local integer times = 0
loop
exitwhen i > udg_Buff_IndexB
if udg_Buff_Unit[i] != null then
set cv = GetUnitUserData(udg_Buff_Unit[i])
if IsUnitType(udg_Buff_Unit[i], UNIT_TYPE_DEAD) or udg_Buff_Purge[cv] then
call ClearUnitBuff (i, cv)
else
set bv = udg_Buff_Value[cv]
if bv > 0 then
loop
exitwhen bv == 0
set po = udg_Buff_ID2V[maxbuff - count]
if bv >= po then
set bv = bv - po
set buffid = maxbuff - count//maxbuff - count
set times = LoadInteger(udg_Buff_Timer, cv, buffid)
if times < 1 then
call RemoveUnitBuff (i, buffid)
else
call SaveInteger(udg_Buff_Timer, cv, buffid, times - 1)
endif
endif
set count = count + 1
endloop
endif
set count = 0
set udg_Buff_Purge[cv] = false
endif
endif
set i = i + 1
endloop
set i = 0
loop
exitwhen i > udg_Buff_IndexH
set cv = GetUnitUserData(udg_Buff_HUnit[i])
if IsUnitType(udg_Buff_HUnit[i], UNIT_TYPE_DEAD) or IsUnitType(udg_Buff_HTarget[cv], UNIT_TYPE_DEAD) or OrderId2String(GetUnitCurrentOrder(udg_Buff_HUnit[i])) != "harvest" then
call UnitRemoveAbility( udg_Buff_HUnit[i], udg_HarvesterAbility )
call UnitAddAbility( udg_Buff_HUnit[i], udg_HarvesterAbility )
set udg_Buff_Harvest[GetUnitUserData(udg_Buff_HTarget[cv])] = false
call SetWidgetLife(udg_Buff_HTarget[cv], 100)
set udg_Buff_HUnit[i] = null
set udg_Buff_HTarget[cv] = null
set udg_Buff_Harvested[cv] = 0
else
if udg_Buff_Harvested[cv] < 10 then
call SetWidgetLife(udg_Buff_HTarget[cv], 100 - udg_Buff_Harvested[cv] * 10)
set udg_Buff_Harvested[cv] = udg_Buff_Harvested[cv] + 1
else
call UnitRemoveAbility( udg_Buff_HUnit[i], udg_HarvesterAbility )
call UnitAddAbility( udg_Buff_HUnit[i], udg_HarvesterAbility )
set pv = GetUnitPointValue(udg_Buff_HTarget[cv])
call DestroyEffect ( AddSpecialEffect (udg_Effects[61], GetUnitX(udg_Buff_HTarget[cv]), GetUnitY(udg_Buff_HTarget[cv])))
//call GroupRemoveUnit(udg_H_HUA, udg_Buff_HTarget[cv])
call RemoveUnitFromMatList(udg_Buff_HTarget[cv])
if GetUnitPointValue(udg_Buff_HUnit[i]) < 2000 then
call CreateItemToHero (udg_Buff_HUnit[i], udg_H_Items[pv], 1)
call cattachment (GetPlayerId(GetOwningPlayer(udg_Buff_HUnit[i]))+1,0)
else
//set udg_H_Count[pv] = udg_H_Count[pv] + 1
set cc = LoadInteger(udg_H_Stock_Table, cv, pv) + 1
call SaveInteger(udg_H_Stock_Table, cv, pv, cc)
call AddItemToStock( udg_Buff_HUnit[i], udg_H_Items[pv], cc, cc )
set udg_H_Target[cv] = null
endif
call DestroyEffect( udg_PickAxe[cv] )
set udg_Buff_Harvest[GetUnitUserData(udg_Buff_HTarget[cv])] = false
set udg_Buff_HUnit[i] = null
call KillUnit( udg_Buff_HTarget[cv] )
set udg_Buff_HTarget[cv] = null
set udg_Buff_Harvested[cv] = 0
endif
endif
set i = i + 1
endloop
endfunction
//===========================================================================
function InitTrig_Timer takes nothing returns nothing
set gg_trg_Timer = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Timer, 1.00 )
call TriggerAddAction( gg_trg_Timer, function Trig_Timer_Actions )
endfunction
rest harvest thing
JASS:
function Trig_Harvest_Conditions takes nothing returns boolean
* * * * return udg_H_Unit[GetUnitPointValue(GetOrderTargetUnit())] == GetUnitTypeId(GetOrderTargetUnit()) and udg_Buff_Harvest[GetUnitUserData(GetOrderTargetUnit())] == false and OrderId2String(GetUnitCurrentOrder(GetTriggerUnit())) == "smart"
endfunction
function Trig_Harvest_Actions takes nothing returns nothing
local integer pv = GetUnitPointValue(GetTriggerUnit())
* * if pv < 2000 then
* * call rattachment (GetPlayerId(GetTriggerPlayer())+1,0)
* * endif
* * call IssueTargetOrder( GetTriggerUnit(), "harvest", GetOrderTargetUnit() )
endfunction
//===========================================================================
function InitTrig_Harvest takes nothing returns nothing
* * set gg_trg_Harvest = CreateTrigger( *)
* * call TriggerRegisterAnyUnitEventBJ( gg_trg_Harvest, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
* * call TriggerAddCondition( gg_trg_Harvest, Condition( function Trig_Harvest_Conditions ) )
* * call TriggerAddAction( gg_trg_Harvest, function Trig_Harvest_Actions )
endfunction
JASS:
function Trig_Start_Harvest_Conditions takes nothing returns boolean
return udg_HarvesterAbility == GetSpellAbilityId()
endfunction
function Trig_Start_Harvest_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local integer pv = GetUnitPointValue (u)
set udg_CV=NewHarvesterIndex()
set udg_Buff_Harvest[GetUnitUserData(t)] = true
set udg_Buff_HTarget[GetUnitUserData(u)] = t
set udg_Buff_HUnit[udg_CV] = u
if pv < 2000 then
set udg_PickAxe[udg_CV] = AddSpecialEffectTarget("Pickle.mdl", u, "hand left")
endif
set u = null
set t = null
endfunction
//===========================================================================
function InitTrig_Start_Harvest takes nothing returns nothing
set gg_trg_Start_Harvest = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Start_Harvest, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( gg_trg_Start_Harvest, Condition( function Trig_Start_Harvest_Conditions ) )
call TriggerAddAction( gg_trg_Start_Harvest, function Trig_Start_Harvest_Actions )
endfunction
the engine, maybe here the problem why the bot hit the target and after 3 sec run away then run back and continue and finish the harvesting
JASS:
function Trig_Harvester_bot_Actions takes nothing returns nothing
local integer i = 0
local integer targetid
local integer mat_filter
local unit u
local integer cv
local string horder
local real gtime = GetTimeOfDay( )
loop
exitwhen i > udg_H_Max_Bot
set u = udg_HarvesterBot[i]
set cv = GetUnitUserData( u )
set horder = OrderId2String( GetUnitCurrentOrder( u ) )
if udg_H_Action[cv] != 0 and gtime < 18.00 and gtime > 6.00 then
set udg_H_Action[cv] = 0
call PauseUnit ( udg_HarvesterBot[i], false )
call ShowUnit( udg_HarvesterBot[i], true )
call DestroyEffect ( udg_H_SF[cv] )
set udg_H_Target[cv] = null
endif
if udg_H_Action[cv] == 0 and udg_H_Target[cv] == null then
set mat_filter = udg_H_Job[cv]
set targetid = SearchUnitInMatList ( mat_filter, cv )
if targetid != - 1 then
set udg_H_Target[cv] = udg_H_HUA[targetid]
call IssueTargetOrder( udg_HarvesterBot[i], "smart", udg_H_Target[cv] )
else
set udg_H_Action[cv] = 1
set udg_H_Target[cv] = null
call IssuePointOrder ( u, "move" , GetUnitX( udg_H_Home[cv] ), GetUnitY( udg_H_Home[cv] ) )
endif
endif
if horder != "harvest" and udg_H_Target[cv] != null and udg_H_Action[cv] == 0 then
call IssueTargetOrder( u, "smart", udg_H_Target[cv] )
endif
if (( gtime > 18.00 or gtime < 6.00 ) and udg_H_Target[cv] == null and udg_H_Action[cv] == 0) and horder != "harvest" or udg_H_Action[cv] == 1 and udg_H_Target[cv] == null and horder != "harvest" then
set udg_H_Action[cv] = 1
call IssuePointOrder ( u, "move" , GetUnitX( udg_H_Home[cv] ), GetUnitY( udg_H_Home[cv] ) )
endif
set i = i + 1
endloop
set u = null
endfunction
//===========================================================================
function InitTrig_Harvester_bot takes nothing returns nothing
set gg_trg_Harvester_bot = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Harvester_bot, 3.00 )
call TriggerAddAction( gg_trg_Harvester_bot, function Trig_Harvester_bot_Actions )
endfunction
home/sleeping
JASS:
function Trig_Harvester_home_Conditions takes nothing returns boolean
local integer cv = GetUnitUserData(GetTriggerUnit())
return udg_H_Action[cv] == 1 and udg_H_Job[cv] > 0
endfunction
function Trig_Harvester_home_Actions takes nothing returns nothing
local integer i = 0
local unit u = GetTriggerUnit()
local integer cv = GetUnitUserData(u)
local integer hqcv = GetUnitUserData(udg_H_Home[cv])
local integer stock
local integer hqstock
set udg_H_Action[cv] = 2
call ShowUnit(u, false)
call PauseUnit (u, true)
set udg_H_SF[cv] = AddSpecialEffectTarget(udg_Effects[60], udg_H_Home[cv], "overhead")
loop
exitwhen i > 100
set hqstock = LoadInteger(udg_H_Stock_Table, hqcv, i)
set stock = LoadInteger(udg_H_Stock_Table, cv, i)
if stock > 0 then
call RemoveItemFromStock( u, udg_H_Items[i] )
call AddItemToStock( udg_H_Home[cv], udg_H_Items[i], stock+hqstock, stock+hqstock )
endif
set i = i + 1
endloop
set u = null
endfunction
//===========================================================================
function InitTrig_Harvester_home takes nothing returns nothing
set gg_trg_Harvester_home = CreateTrigger( )
call TriggerAddCondition( gg_trg_Harvester_home, Condition( function Trig_Harvester_home_Conditions ) )
call TriggerAddAction( gg_trg_Harvester_home, function Trig_Harvester_home_Actions )
endfunction
decrease stock item
JASS:
function Trig_Buy_from_Harvesterbot_Conditions takes nothing returns boolean
local integer pv = GetUnitPointValue(GetSellingUnit())
return pv == 1000 or pv > 1999
endfunction
function Trig_Buy_from_Harvesterbot_Actions takes nothing returns nothing
local item it = GetSoldItem()
local unit u = GetSellingUnit()
local integer cv = GetUnitUserData(u)
local integer pv = GetItemLevel(it)
local integer stock = LoadInteger(udg_H_Stock_Table, cv, pv) - 1
call SaveInteger(udg_H_Stock_Table, cv, pv, stock)
if stock == 0 then
call RemoveItemFromStock( u, udg_H_Items[pv] )
else
call AddItemToStock(u, udg_H_Items[pv], stock, stock )
endif
set it = null
endfunction
//===========================================================================
function InitTrig_Buy_from_Harvesterbot takes nothing returns nothing
set gg_trg_Buy_from_Harvesterbot = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Buy_from_Harvesterbot, EVENT_PLAYER_UNIT_SELL_ITEM )
call TriggerAddCondition( gg_trg_Buy_from_Harvesterbot, Condition( function Trig_Buy_from_Harvesterbot_Conditions ) )
call TriggerAddAction( gg_trg_Buy_from_Harvesterbot, function Trig_Buy_from_Harvesterbot_Actions )
endfunction
Attachments
Last edited: