- Joined
- May 12, 2008
- Messages
- 35
i have a map I'm working on that i need to figure out a way to spawn a person at a building and go to another one. but there is more than one building one and none of them are made at start. is it even possible?
function ConvoyReachesTargetConds takes nothing returns boolean
return GetSpellAbilityId() == 'A003'
endfunction
function ConvoyReachesTarget takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
local string s = I2S(H2I(u))
local unit u2 = I2U(GetStoredInteger(udg_GameCache,s,"sender"))
local unit u3 = I2U(GetStoredInteger(udg_GameCache,s,"target"))
if GetOwningPlayer(u3) != p then
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)*.75))
call SetPlayerState(GetOwningPlayer(u3),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(GetOwningPlayer(u3),PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)/4))
else
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)/4))
endif
if GetWidgetLife(u2) > 0 and GetWidgetLife(u3) > 0 then
call SendConvoy(p,u2,u3)
endif
call FlushStoredMission(udg_GameCache,s)
call RemoveUnit(u)
set u = null
set u2 = null
set u3 = null
endfunction
function InitTrig_ConvoyReachesTarget takes nothing returns nothing
set gg_trg_ConvoyReachesTarget = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ConvoyReachesTarget,EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(gg_trg_ConvoyReachesTarget,Condition(function ConvoyReachesTargetConds))
call TriggerAddAction(gg_trg_ConvoyReachesTarget,function ConvoyReachesTarget)
endfunction
function SetConvoyDestinationConds takes nothing returns boolean
return GetSpellAbilityId() == 'A004'
endfunction
function SetConvoyDestination takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD) > 299 and GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER) > 9 then
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)-300)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)-10)
call SendConvoy(p,u,GetSpellTargetUnit())
endif
set u = null
endfunction
function InitTrig_SetConvoyDestination takes nothing returns nothing
set gg_trg_SetConvoyDestination = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_SetConvoyDestination,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_SetConvoyDestination,Condition(function SetConvoyDestinationConds))
call TriggerAddAction(gg_trg_SetConvoyDestination,function SetConvoyDestination)
endfunction
function ReorderConvoyConds takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 'h00Z' and GetIssuedOrderId() == 851971
endfunction
function ReorderConvoy takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit u2 = I2U(GetStoredInteger(udg_GameCache,I2S(H2I(u)),"target"))
call PauseUnit(u,true)
call IssueImmediateOrder(u,"stop")
call PauseUnit(u,false)
call IssueImmediateOrder(u,"stop")
if GetWidgetLife(u2) > 0 then
call IssueTargetOrder(u,"cripple",u2)
endif
set u = null
set u2 = null
endfunction
function InitTrig_ReorderConvoy takes nothing returns nothing
set gg_trg_ReorderConvoy = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ReorderConvoy,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterAnyUnitEventBJ(gg_trg_ReorderConvoy,EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddCondition(gg_trg_ReorderConvoy,Condition(function ReorderConvoyConds))
call TriggerAddAction(gg_trg_ReorderConvoy,function ReorderConvoy)
endfunction
function ConvoyDeathConds takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 'h00Z'
endfunction
function ConvoyDeath takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
local string s = I2S(H2I(u))
local unit u2 = I2U(GetStoredInteger(udg_GameCache,s,"sender"))
local unit u3 = I2U(GetStoredInteger(udg_GameCache,s,"target"))
if GetWidgetLife(u2) > 0 and GetWidgetLife(u3) > 0 and u3 == I2U(GetStoredInteger(udg_GameCache,I2S(H2I(u2)),"target")) then
call SendConvoy(p,u2,u3)
endif
call FlushStoredMission(udg_GameCache,s)
set u = null
set u2 = null
set u3 = null
endfunction
function CleanupUselessConvoysFilter takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'h00Z' and GetUnitCurrentOrder(GetFilterUnit()) != 852189
endfunction
function CleanupUselessConvoys takes nothing returns nothing
local unit u
call GroupEnumUnitsInRect(udg_enumGrp,bj_mapInitialPlayableArea,Filter(function CleanupUselessConvoysFilter))
loop
set u = FirstOfGroup(udg_enumGrp)
exitwhen u == null
call FlushStoredMission(udg_GameCache,I2S(H2I(u)))
call RemoveUnit(u)
call GroupRemoveUnit(udg_enumGrp,u)
endloop
endfunction
function InitTrig_CleanupUselessConvoys takes nothing returns nothing
set gg_trg_CleanupUselessConvoys = CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_CleanupUselessConvoys,1,true)
call TriggerAddAction(gg_trg_CleanupUselessConvoys,function CleanupUselessConvoys)
endfunction
if GetOwningPlayer(u3) != p then
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)*.75))
call SetPlayerState(GetOwningPlayer(u3),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(GetOwningPlayer(u3),PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)/4))
else
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)/4))
endif
if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD) > 299 and GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER) > 9 then
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)-300)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)-10)
call SendConvoy(p,u,GetSpellTargetUnit())
endif
//Constants
constant function ConvoyAbilityOrderString takes nothing returns string
return "cripple" //orderstring of the ability the convoys cast on the target markets
endfunction
constant function ConvoyUnitTypeId takes nothing returns integer
return 'h00Z' //unit id of the convoy
endfunction
constant function ConvoyAbilityId takes nothing returns integer
return 'A003' //ability id of the ability the convoys cast on the target markets
endfunction
constant function ConvoySendAbilityId takes nothing returns integer
return 'A004' //ability id of the ability to establish a trade route
endfunction
//Map Header
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2U takes integer i returns unit
return i
return null
endfunction
function SendConvoy takes player p, unit send, unit targ returns nothing
local unit u = CreateUnit(p,ConvoyUnitTypeId(),GetUnitX(send),GetUnitY(send),0)
local string s = I2S(H2I(u))
call IssueTargetOrder(u,ConvoyAbilityOrderString(),targ)
call StoreInteger(udg_GameCache,s,"sender",H2I(send))
call StoreInteger(udg_GameCache,s,"target",H2I(targ))
set u = null
endfunction
//Triggers
function ConvoyReachesTargetConds takes nothing returns boolean
return GetSpellAbilityId() == ConvoyAbilityId()
endfunction
function ConvoyReachesTarget takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
local string s = I2S(H2I(u))
local unit u2 = I2U(GetStoredInteger(udg_GameCache,s,"sender"))
local unit u3 = I2U(GetStoredInteger(udg_GameCache,s,"target"))
if GetOwningPlayer(u3) != p then
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)*.75))
call SetPlayerState(GetOwningPlayer(u3),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(GetOwningPlayer(u3),PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)/4))
else
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+R2I(GetUnitState(u,UNIT_STATE_MANA)/4))
endif
if GetWidgetLife(u2) > 0 and GetWidgetLife(u3) > 0 then
call SendConvoy(p,u2,u3)
endif
call FlushStoredMission(udg_GameCache,s)
call RemoveUnit(u)
set u = null
set u2 = null
set u3 = null
endfunction
function InitTrig_ConvoyReachesTarget takes nothing returns nothing
set gg_trg_ConvoyReachesTarget = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ConvoyReachesTarget,EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(gg_trg_ConvoyReachesTarget,Condition(function ConvoyReachesTargetConds))
call TriggerAddAction(gg_trg_ConvoyReachesTarget,function ConvoyReachesTarget)
endfunction
function SetConvoyDestinationConds takes nothing returns boolean
return GetSpellAbilityId() == ConvoySendAbilityId()
endfunction
function SetConvoyDestination takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD) > 299 and GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER) > 9 then
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)-300)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)-10)
call SendConvoy(p,u,GetSpellTargetUnit())
endif
set u = null
endfunction
function InitTrig_SetConvoyDestination takes nothing returns nothing
set gg_trg_SetConvoyDestination = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_SetConvoyDestination,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_SetConvoyDestination,Condition(function SetConvoyDestinationConds))
call TriggerAddAction(gg_trg_SetConvoyDestination,function SetConvoyDestination)
endfunction
function ReorderConvoyConds takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == ConvoyUnitTypeId() and GetIssuedOrderId() == 851971
endfunction
function ReorderConvoy takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit u2 = I2U(GetStoredInteger(udg_GameCache,I2S(H2I(u)),"target"))
call PauseUnit(u,true)
call IssueImmediateOrder(u,"stop")
call PauseUnit(u,false)
call IssueImmediateOrder(u,"stop")
if GetWidgetLife(u2) > 0 then
call IssueTargetOrder(u,ConvoyAbilityOrderString(),u2)
endif
set u = null
set u2 = null
endfunction
function InitTrig_ReorderConvoy takes nothing returns nothing
set gg_trg_ReorderConvoy = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ReorderConvoy,EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterAnyUnitEventBJ(gg_trg_ReorderConvoy,EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddCondition(gg_trg_ReorderConvoy,Condition(function ReorderConvoyConds))
call TriggerAddAction(gg_trg_ReorderConvoy,function ReorderConvoy)
endfunction
function ConvoyDeathConds takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == ConvoyUnitTypeId()
endfunction
function ConvoyDeath takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
local string s = I2S(H2I(u))
local unit u2 = I2U(GetStoredInteger(udg_GameCache,s,"sender"))
local unit u3 = I2U(GetStoredInteger(udg_GameCache,s,"target"))
if GetWidgetLife(u2) > 0 and GetWidgetLife(u3) > 0 and u3 == I2U(GetStoredInteger(udg_GameCache,I2S(H2I(u2)),"target")) then
call SendConvoy(p,u2,u3)
endif
call FlushStoredMission(udg_GameCache,s)
set u = null
set u2 = null
set u3 = null
endfunction
function CleanupUselessConvoysFilter takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == ConvoyUnitTypeId() and GetUnitCurrentOrder(GetFilterUnit()) != 852189
endfunction
function CleanupUselessConvoys takes nothing returns nothing
local unit u
call GroupEnumUnitsInRect(udg_enumGrp,bj_mapInitialPlayableArea,Filter(function CleanupUselessConvoysFilter))
loop
set u = FirstOfGroup(udg_enumGrp)
exitwhen u == null
call FlushStoredMission(udg_GameCache,I2S(H2I(u)))
call RemoveUnit(u)
call GroupRemoveUnit(udg_enumGrp,u)
endloop
endfunction
function InitTrig_CleanupUselessConvoys takes nothing returns nothing
set gg_trg_CleanupUselessConvoys = CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_CleanupUselessConvoys,1,true)
call TriggerAddAction(gg_trg_CleanupUselessConvoys,function CleanupUselessConvoys)
endfunction