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

[JASS] As suspected... I need help with my scripts.

Status
Not open for further replies.
Level 5
Joined
May 22, 2006
Messages
150
That is it:

global variables used:
(for type "[x]" means place "x" of an array,
for type array "[x]" means array with "x" places)

JASS:
force "udg_Streitmacht[0]"
force "udg_tempSpielergruppe"
unit array "udg_Katze[6]"
unit "udg_tempEinheit"
integer "udg_Zähler[13]"

Trigger "Katze Hilfe 1":
JASS:
function Trig_Katze_Hilfe_1_Conditions1 takes nothing returns boolean
return IsPlayerInForce(GetFilterPlayer(),udg_Streitmacht[0]) == true and GetFilterPlayer() != GetOwningPlayer(udg_tempEinheit)
endfunction

function Trig_Katze_Hilfe_1_Subactions1 takes nothing returns nothing
  call SetPlayerUnitAvailableBJ('ndog',false,GetEnumPlayer())
endfunction

function Trig_Katze_Hilfe_1_Actions takes nothing returns nothing
  if GetIssuedOrderIdBJ() == UnitId2OrderIdBJ('ndog') then
    set udg_tempEinheit=GetTriggerUnit()
    if udg_Zaehler[13] == 5 then
      call IssueImmediateOrderBJ(udg_tempEinheit,"stop")
    else
      set udg_tempSpielergruppe = GetPlayersMatching(Condition(function Trig_Katze_Hilfe_1_Conditions1))
call ForForce(udg_tempSpielergruppe,function Trig_Katze_Hilfe_1_Subactions1)
set udg_Zaehler[13] = udg_Zaehler[13] + 1
endif
endif
endfunction

function InitTrig_Katze_Hilfe_1 takes nothing returns nothing
  set gg_trg_Katze_Hilfe_1 = CreateTrigger()
  call TriggerRegisterAnyUnitEventBJ(gg_trg_Katze_Hilfe_1,EVENT_PLAYER_UNIT_ISSUED_ORDER)
  call TriggerAddAction(gg_trg_Katze_Hilfe_1,function Trig_Katze_Hilfe_1_Actions)
endfunction

Trigger "Katze Hilfe 2":
JASS:
function Trig_Katze_Hilfe_2_Subactions1 takes nothing returns nothing
  call SetPlayerUnitAvailableBJ('ndog',true,GetEnumPlayer())
endfunction

function Trig_Katze_Hilfe_2_Actions takes nothing returns nothing
  if GetIssuedOrderIdBJ() == String2OrderIdBJ("stop") then
    set udg_Zaehler[13] = udg_Zaehler[13] - 1
    call DestroyForce(udg_tempSpielergruppe)
    call ForForce(udg_Streitmacht[0],function Trig_Katze_Hilfe_2_Subactions1)
  endif
endfunction

function InitTrig_Katze_Hilfe_2 takes nothing returns nothing
  set gg_trg_Katze_Hilfe_2 = CreateTrigger()
  call TriggerRegisterUnitEvent(gg_trg_Katze_Hilfe_2,udg_tempEinheit,EVENT_UNIT_ISSUED_ORDER)
  call TriggerAddAction(gg_trg_Katze_Hilfe_2,function Trig_Katze_Hilfe_2_Actions)
endfunction

Trigger "Katze Bau":
JASS:
function Trig_Katze_Bau_Actions_Subactions1 takes nothing returns nothing
  call SetPlayerUnitAvailableBJ('ndog',true,GetEnumPlayer())
endfunction

function Trig_Katze_Bau_Actions_Subactions2 takes nothing returns nothing
  call SetPlayerUnitAvailableBJ('ndog',false,GetEnumPlayer())
endfunction

function Trig_Katze_Bau_Actions takes nothing returns nothing
  if GetUnitTypeId(GetTrainedUnit()) == 'ndog' then
    set udg_Katze[udg_Zaehler[13]] = GetTrainedUnit()
    call SetUnitOwner(udg_Katze[udg_Zaehler[13]],Player(PLAYER_NEUTRAL_PASSIVE),true)
    if udg_Zaehler[13] == 0 then
      call EnableTrigger(gg_trg_Katze_Steuerung_1)
      call EnableTrigger(gg_trg_Katze_Steuerung_1_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1)
    elseif udg_Zaehler[13] == 1 then
      call EnableTrigger(gg_trg_Katze_Steuerung_2)
      call EnableTrigger(gg_trg_Katze_Steuerung_2_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_2)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1)
    elseif udg_Zaehler[13] == 2 then
      call EnableTrigger(gg_trg_Katze_Steuerung_3)
      call EnableTrigger(gg_trg_Katze_Steuerung_3_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_3)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1)
    elseif udg_Zaehler[13] == 3 then
      call EnableTrigger(gg_trg_Katze_Steuerung_4)
      call EnableTrigger(gg_trg_Katze_Steuerung_4_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_4)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1)
    elseif udg_Zaehler[13] == 4 then
      call EnableTrigger(gg_trg_Katze_Steuerung_5)
      call EnableTrigger(gg_trg_Katze_Steuerung_5_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_5)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1)
    else
      call EnableTrigger(gg_trg_Katze_Steuerung_6)
      call EnableTrigger(gg_trg_Katze_Steuerung_6_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_6)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions2)
    endif
    call DestroyForce(udg_tempSpielergruppe)
  endif
endfunction

function InitTrig_Katze_Bau takes nothing returns nothing
  set gg_trg_Katze_Bau = CreateTrigger()
  call TriggerRegisterAnyUnitEventBJ(gg_trg_Katze_Bau,EVENT_PLAYER_UNIT_TRAIN_FINISH)
  call TriggerAddAction(gg_trg_Katze_Bau,function Trig_Katze_Bau_Actions)
endfunction

Trigger "Katze Tod":
JASS:
function Trig_Katze_Tod_Actions_Subactions1 takes nothing returns nothing
  call SetPlayerUnitAvailableBJ('ndog',true,GetEnumPlayer())
endfunction

function Trig_Katze_Tod_Actions takes nothing returns nothing
  if GetUnitTypeId(GetDyingUnit()) == 'ndog' then
    if udg_Zaehler[13] == 5 then
      call DisableTrigger(gg_trg_Katze_Steuerung_6)
      call DisableTrigger(gg_trg_Katze_Steuerung_6_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_6_Streifzug)
    elseif udg_Zaehler[13] == 4 then
      call DisableTrigger(gg_trg_Katze_Steuerung_5)
      call DisableTrigger(gg_trg_Katze_Steuerung_5_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_5_Streifzug)
    elseif udg_Zaehler[13] == 3 then
      call DisableTrigger(gg_trg_Katze_Steuerung_4)
      call DisableTrigger(gg_trg_Katze_Steuerung_4_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_4_Streifzug)
    elseif udg_Zaehler[13] == 2 then
      call DisableTrigger(gg_trg_Katze_Steuerung_3)
      call DisableTrigger(gg_trg_Katze_Steuerung_3_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_3_Streifzug)
    elseif udg_Zaehler[13] == 1 then
      call DisableTrigger(gg_trg_Katze_Steuerung_2)
      call DisableTrigger(gg_trg_Katze_Steuerung_2_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_2_Streifzug)
    else
      call DisableTrigger(gg_trg_Katze_Steuerung_1)
      call DisableTrigger(gg_trg_Katze_Steuerung_1_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
    endif
    set udg_Zaehler[13] = udg_Zaehler[13] - 1
    call ForForce(udg_Streitmacht[0],function Trig_Katze_Tod_Actions_Subactions1)
  endif
endfunction

function InitTrig_Katze_Tod takes nothing returns nothing
  set gg_trg_Katze_Tod = CreateTrigger()
  call TriggerRegisterAnyUnitEventBJ(gg_trg_Katze_Tod,EVENT_PLAYER_UNIT_DEATH)
  call TriggerAddAction(gg_trg_Katze_Tod,function Trig_Katze_Tod_Actions)
endfunction

Trigger "Katze Steuerung 1":
JASS:
function Trig_Katze_Steuerung_1_Actions takes nothing returns nothing
  if GetUnitTypeId(GetTriggerUnit()) == 'nfro' or GetUnitTypeId(GetTriggerUnit()) == 'ndwm' or GetUnitTypeId(GetTriggerUnit()) == 'nrat' then
    call DisableTrigger(gg_trg_Katze_Steuerung_1)
    call DisableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
    call IssueTargetOrderBJ(udg_Katze[0],"attack",GetTriggerUnit())
  endif
endfunction

function InitTrig_Katze_Steuerung_1 takes nothing returns nothing
  set gg_trg_Katze_Steuerung_1 = CreateTrigger()
  call DisableTrigger(gg_trg_Katze_Steuerung_1)
  call TriggerRegisterUnitInRangeSimple(gg_trg_Katze_Steuerung_1,1000,udg_Katze[0])
  call TriggerAddAction(gg_trg_Katze_Steuerung_1,function Trig_Katze_Steuerung_1_Actions)
endfunction

Trigger "Katze Steuerung 1 Hilfe":
JASS:
function Trig_Katze_Steuerung_1_Hilfe_Actions takes nothing returns nothing
  if GetKillingUnitBJ() == udg_Katze[0] then
    call EnableTrigger(gg_trg_Katze_Steuerung_1)
    call EnableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
  endif
endfunction

function InitTrig_Katze_Steuerung_1_Hilfe takes nothing returns nothing
  set gg_trg_Katze_Steuerung_1_Hilfe = CreateTrigger()
  call DisableTrigger(gg_trg_Katze_Steuerung_1_Hilfe)
  call TriggerRegisterPlayerUnitEventSimple(gg_trg_Katze_Steuerung_1_Hilfe,Player(PLAYER_NEUTRAL_PASSIVE),EVENT_PLAYER_UNIT_DEATH)
  call TriggerAddAction(gg_trg_Katze_Steuerung_1_Hilfe,function Trig_Katze_Steuerung_1_Hilfe_Actions)
endfunction

Trigger "Katze Steuerung 1 Streifzug":
JASS:
function Trig_Katze_Steuerung_1_Streifzug_Actions takes nothing returns nothing
  local location array tempPunkt
  local rect tempGebiet
  set tempPunkt[0] = GetUnitLoc(udg_Katze[0])
  set tempGebiet = RectFromCenterSizeBJ(tempPunkt[0],1000.00,1000.00)
  set tempPunkt[1] = GetRandomLocInRect(tempGebiet)
  call IssuePointOrderLocBJ(udg_Katze[0],"move",tempPunkt[1])
  call TriggerSleepAction(3.00)
  call RemoveLocation(tempPunkt[0])
  call RemoveLocation(tempPunkt[1])
  call RemoveRect(tempGebiet)
endfunction

function InitTrig_Katze_Steuerung_1_Streifzug takes nothing returns nothing
  set gg_trg_Katze_Steuerung_1_Streifzug = CreateTrigger()
  call DisableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
  call TriggerRegisterTimerEventPeriodic(gg_trg_Katze_Steuerung_1_Streifzug,GetRandomReal(10.00,20.00))
  call TriggerAddAction(gg_trg_Katze_Steuerung_1_Streifzug,function Trig_Katze_Steuerung_1_Streifzug_Actions)
endfunction

The last three triggers exist fife more times, these version's only difference are the numbers set into the arrays.


It should work this way:
I have got six players and each one is able to build the unit "Katze" ('ndog').
Each time one of these Players finishes the training of this unit type, the Trigger "Katze Bau" is supposed to save a reference to this unit in the unit array "udg_Katze".
Which place of the array is used shall depend on the number of such units already existing on the map.
Now, the three triggers "Katze Steuerung x", "Katze Steuerung x Hilfe" and "Katze Steuerung x Streifzug" should be activated, for x is the number of the built unit. (the first one should have x=1, the second one x=2 and so on up to a maximum of x=6)

That's not all this construction is supposed to do but here my problems start:
The first unit I create works (nearly) perfectly.
But the second and each next one does not!
The triggers are ether not activated or the units are not saved in the correct array place.
I thought about it a pretty long time but I do not get it, where my code is wrong. ~~

So, if somebody may have a lot of free time and whould enjoy to examine complicated code...
Your help whould be very welcome.
 
Level 2
Joined
Sep 10, 2004
Messages
21
Hm...pity I don´t have the time to do this right now but otherwise, here are the translations for Purple:

Streitmacht=force
Spielergruppe=player group=force
Katze=cat
TempEinheit=TempUnit
Zähler=counter
Katze Hilfe=cat help
Katze Bau=cat training(/building)
Katze Tod=cat death
Katze Steuerung (Hilfe)=cat control (help)
Katze Steuerung Streifzug=cat control wander(move around)
TempPunkt=TempPoint
TempGebiet=TempRegion

And @LordZsar1: Please don´t post JASS code this way! This forum has a jass formatting script that makes JASS scripts much easier to read! The "Code" option you used is ONLY for GUI!

And I realize there are a lot of germans in this forum (including me) but IMO Scripts are also much easier to read if ALL names and references are in English as JASS is English too. And everyone else will be able understand your scripts easier.
Thanks :wink:
 
Level 5
Joined
May 22, 2006
Messages
150
Ah, sorry.
I am not common with such supportive forums. ^^

Okay then, here is my code with english names...
What if I had only used alphanummeric identifiers? ^^

global variables used:
(for type "[x]" means place "x" of an array,
for type array "[x]" means array with "x" places)

JASS:
force "udg_force[0]" 
force "udg_tempForce" 
unit array "udg_cat[6]" 
unit "udg_tempUnit" 
integer "udg_counter[13]"

Trigger "helpCat1":
JASS:
function Trig_helpCat1_Conditions1 takes nothing returns boolean 
return IsPlayerInForce(GetFilterPlayer(),udg_force[0]) == true and GetFilterPlayer() != GetOwningPlayer(udg_tempUnit) 
endfunction 

function Trig_helpCat1_Subactions1 takes nothing returns nothing 
call SetPlayerUnitAvailableBJ('ndog',false,GetEnumPlayer()) 
endfunction 

function Trig_helpCat1_Actions takes nothing returns nothing 
if GetIssuedOrderIdBJ() == UnitId2OrderIdBJ('ndog') then 
set udg_tempUnit=GetTriggerUnit() 
if udg_counter[13] == 5 then 
call IssueImmediateOrderBJ(udg_tempUnit,"stop") 
else 
set udg_tempForce = GetPlayersMatching(Condition(function Trig_helpCat1_Conditions1)) 
call ForForce(udg_tempForce,function Trig_helpCat1_Subactions1) 
set udg_counter[13] = udg_counter[13] + 1 
endif 
endif 
endfunction 

function InitTrig_helpCat1 takes nothing returns nothing 
set gg_trg_helpCat1 = CreateTrigger() 
call TriggerRegisterAnyUnitEventBJ(gg_trg_helpCat1,EVENT_PLAYER_UNIT_ISSUED_ORDER) 
call TriggerAddAction(gg_trg_helpCat1,function Trig_helpCat1_Actions) 
endfunction

Trigger "helpCat2":
JASS:
function Trig_helpCat2_Subactions1 takes nothing returns nothing 
call SetPlayerUnitAvailableBJ('ndog',true,GetEnumPlayer()) 
endfunction 

function Trig_helpCat2_Actions takes nothing returns nothing 
if GetIssuedOrderIdBJ() == String2OrderIdBJ("stop") then 
set udg_counter[13] = udg_counter[13] - 1 
call DestroyForce(udg_tempForce) 
call ForForce(udg_Force[0],function Trig_helpCat2_Subactions1) 
endif 
endfunction 

function InitTrig_helpCat2 takes nothing returns nothing 
set gg_trg_helpCat2 = CreateTrigger() 
call TriggerRegisterUnitEvent(gg_trg_helpCat2,udg_tempUnit,EVENT_UNIT_ISSUED_ORDER) 
call TriggerAddAction(gg_trg_helpCat2,function Trig_helpCat2_Actions) 
endfunction

Trigger "trainCat":
JASS:
function Trig_trainCat_Subactions1 takes nothing returns nothing 
call SetPlayerUnitAvailableBJ('ndog',true,GetEnumPlayer()) 
endfunction 

function Trig_trainCat_Subactions2 takes nothing returns nothing 
call SetPlayerUnitAvailableBJ('ndog',false,GetEnumPlayer()) 
endfunction 

function Trig_trainCat_Actions takes nothing returns nothing 
if GetUnitTypeId(GetTrainedUnit()) == 'ndog' then 
set udg_cat[udg_counter[13]] = GetTrainedUnit() 
call SetUnitOwner(udg_cat[udg_Counter[13]],Player(PLAYER_NEUTRAL_PASSIVE),true) 
if udg_counter[13] == 0 then 
call EnableTrigger(gg_trg_controlCat1) 
call EnableTrigger(gg_trg_helpControlCat1) 
call EnableTrigger(gg_trg_controlCat1Wander) 
call ForForce(udg_Force[0],function Trig_trainCat_Subactions1) 
elseif udg_counter[13] == 1 then 
call EnableTrigger(gg_trg_controlCat2) 
call EnableTrigger(gg_trg_helpControlCat2) 
call EnableTrigger(gg_trg_controlCat2Wander) 
call ForForce(udg_Force[0],function Trig_trainCat_Subactions1) 
elseif udg_counter[13] == 2 then 
call EnableTrigger(gg_trg_controlCat3) 
call EnableTrigger(gg_trg_helpControlCat3) 
call EnableTrigger(gg_trg_controlCat3Wander) 
call ForForce(udg_Streitmacht[0],function Trig_trainCat_Subactions1) 
elseif udg_counter[13] == 3 then 
call EnableTrigger(gg_trg_controlCat4) 
call EnableTrigger(gg_trg_helpControlCat4) 
call EnableTrigger(gg_trg_controlCat4Wander) 
call ForForce(udg_Force[0],function Trig_trainCat_Subactions1) 
elseif udg_counter[13] == 4 then 
call EnableTrigger(gg_trg_controlCat5) 
call EnableTrigger(gg_trg_helpControlCat5) 
call EnableTrigger(gg_trg_controlCat5Wander) 
call ForForce(udg_Force[0],function Trig_trainCat_Subactions1) 
else 
call EnableTrigger(gg_trg_controlCat6) 
call EnableTrigger(gg_trg_helpControlCat6) 
call EnableTrigger(gg_trg_controlCat6Wander) 
call ForForce(udg_Streitmacht[0],function Trig_trainCat_Subactions2) 
endif 
call DestroyForce(udg_tempForce) 
endif 
endfunction 

function InitTrig_trainCat takes nothing returns nothing 
set gg_trg_trainCat = CreateTrigger() 
call TriggerRegisterAnyUnitEventBJ(gg_trg_trainCat,EVENT_PLAYER_UNIT_TRAIN_FINISH) 
call TriggerAddAction(gg_trg_trainCat,function Trig_trainCat_Actions) 
endfunction

Trigger "killCat":
JASS:
function Trig_killCat_Subactions1 takes nothing returns nothing 
call SetPlayerUnitAvailableBJ('ndog',true,GetEnumPlayer()) 
endfunction 

function Trig_killCat_Actions takes nothing returns nothing 
if GetUnitTypeId(GetDyingUnit()) == 'ndog' then 
if udg_counter[13] == 5 then 
call DisableTrigger(gg_trg_controlCat6) 
call DisableTrigger(gg_trg_helpControlCat6) 
call DisableTrigger(gg_trg_controlCat6Wander) 
elseif udg_counter[13] == 4 then 
call DisableTrigger(gg_trg_controlCat5) 
call DisableTrigger(gg_trg_helpControlCat5) 
call DisableTrigger(gg_trg_controlCat5Wander) 
elseif udg_counter[13] == 3 then 
call DisableTrigger(gg_trg_controlCat4) 
call DisableTrigger(gg_trg_helpControlCat4) 
call DisableTrigger(gg_trg_controlCat4Wander) 
elseif udg_counter[13] == 2 then 
call DisableTrigger(gg_trg_controlCat3) 
call DisableTrigger(gg_trg_helpControlCat3) 
call DisableTrigger(gg_trg_controlCat3Wander) 
elseif udg_counter[13] == 1 then 
call DisableTrigger(gg_trg_controlCat2) 
call DisableTrigger(gg_trg_helpControlCat2) 
call DisableTrigger(gg_trg_controlCat2Wander) 
else 
call DisableTrigger(gg_trg_controlCat1) 
call DisableTrigger(gg_trg_helpControlCat1) 
call DisableTrigger(gg_trg_controlCat1Wander) 
endif 
set udg_counter[13] = udg_counter[13] - 1 
call ForForce(udg_Force[0],function Trig_killCat_Subactions1) 
endif 
endfunction 

function InitTrig_killCat takes nothing returns nothing 
set gg_trg_killCat = CreateTrigger() 
call TriggerRegisterAnyUnitEventBJ(gg_trg_killCat,EVENT_PLAYER_UNIT_DEATH) 
call TriggerAddAction(gg_trg_killCat,function Trig_killCat_Actions) 
endfunction

Trigger "controlCat1":
JASS:
function Trig_controlCat1_Actions takes nothing returns nothing 
if GetUnitTypeId(GetTriggerUnit()) == 'nfro' or GetUnitTypeId(GetTriggerUnit()) == 'ndwm' or GetUnitTypeId(GetTriggerUnit()) == 'nrat' then 
call DisableTrigger(gg_trg_controlCat1) 
call DisableTrigger(gg_trg_controlCat1Wander) 
call IssueTargetOrderBJ(udg_cat[0],"attack",GetTriggerUnit()) 
endif 
endfunction 

function InitTrig_controlCat1 takes nothing returns nothing 
set gg_trg_controlCat1 = CreateTrigger() 
call DisableTrigger(gg_trg_controlCat1) 
call TriggerRegisterUnitInRangeSimple(gg_trg_controlCat1,1000,udg_cat[0]) 
call TriggerAddAction(gg_trg_controlCat1,function Trig_controlCat1_Actions) 
endfunction

Trigger "helpControlCat1":
JASS:
function Trig_helpControlCat1_Actions takes nothing returns nothing 
if GetKillingUnitBJ() == udg_cat[0] then 
call EnableTrigger(gg_trg_controlCat1) 
call EnableTrigger(gg_trg_controlCat1Wander) 
endif 
endfunction 

function InitTrig_helpControlCat1 takes nothing returns nothing 
set gg_trg_helpControlCat1 = CreateTrigger() 
call DisableTrigger(gg_trg_helpControlCat1) 
call TriggerRegisterPlayerUnitEventSimple(gg_trg_helpControlCat1,Player(PLAYER_NEUTRAL_PASSIVE),EVENT_PLAYER_UNIT_DEATH) 
call TriggerAddAction(gg_trg_helpControlCat1,function Trig_helpControlCat1_Actions) 
endfunction

Trigger "controlCat1Wander":
JASS:
function Trig_controlCat1Wander_Actions takes nothing returns nothing 
local location array tempPoint 
local rect tempRectangle 
set tempPoint[0] = GetUnitLoc(udg_Cat[0]) 
set tempRectangle = RectFromCenterSizeBJ(tempPoint[0],1000.00,1000.00) 
set tempPoint[1] = GetRandomLocInRect(tempRectangle) 
call IssuePointOrderLocBJ(udg_cat[0],"move",tempPoint[1]) 
call TriggerSleepAction(3.00) 
call RemoveLocation(tempPoint[0]) 
call RemoveLocation(tempPoint[1]) 
call RemoveRect(tempRectangle) 
endfunction 

function InitTrig_controlCat1Wander takes nothing returns nothing 
set gg_trg_controlCat1Wander = CreateTrigger() 
call DisableTrigger(gg_trg_controlCat1Wander) 
call TriggerRegisterTimerEventPeriodic(gg_trg_controlCat1Wander,GetRandomReal(10.00,20.00)) 
call TriggerAddAction(gg_trg_controlCat1Wander,function Trig_controlCat1Wander_Actions) 
endfunction

Hey, while rewriting this piece of text, I encountered my first fatal fault:

Excerpt from Trigger "Katze_Bau" (now "trainCat"), function "Trig_Katze_Bau_Actions" (now "Trig_trainCat_Actions"):

That is what was there before:
JASS:
if udg_Zaehler[13] == 0 then 
call EnableTrigger(gg_trg_Katze_Steuerung_1) 
call EnableTrigger(gg_trg_Katze_Steuerung_1_Hilfe) 
call EnableTrigger(gg_trg_Katze_Steuerung_1_Streifzug) 
call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 1 then 
call EnableTrigger(gg_trg_Katze_Steuerung_2) 
call EnableTrigger(gg_trg_Katze_Steuerung_2_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_2) 


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 2 then 
call EnableTrigger(gg_trg_Katze_Steuerung_3) 
call EnableTrigger(gg_trg_Katze_Steuerung_3_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_3) 


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 3 then 
call EnableTrigger(gg_trg_Katze_Steuerung_4) 
call EnableTrigger(gg_trg_Katze_Steuerung_4_Hilfe) 


call EnableTrigger([b]gg_trg_Katze_Steuerung_4) 


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 4 then 
call EnableTrigger(gg_trg_Katze_Steuerung_5) 
call EnableTrigger(gg_trg_Katze_Steuerung_5_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_5) 


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
else 
call EnableTrigger(gg_trg_Katze_Steuerung_6) 
call EnableTrigger(gg_trg_Katze_Steuerung_6_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_6) 


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions2) 
endif

This is how is has to look (and how it does look now):
JASS:
if udg_Zaehler[13] == 0 then 
call EnableTrigger(gg_trg_Katze_Steuerung_1) 
call EnableTrigger(gg_trg_Katze_Steuerung_1_Hilfe) 
call EnableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1)
elseif udg_Zaehler[13] == 1 then 
call EnableTrigger(gg_trg_Katze_Steuerung_2) 
call EnableTrigger(gg_trg_Katze_Steuerung_2_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_2_Streifzug)


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 2 then 
call EnableTrigger(gg_trg_Katze_Steuerung_3) 
call EnableTrigger(gg_trg_Katze_Steuerung_3_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_3_Streifzug)


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 3 then 
call EnableTrigger(gg_trg_Katze_Steuerung_4) 
call EnableTrigger(gg_trg_Katze_Steuerung_4_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_4_Streifzug)


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
elseif udg_Zaehler[13] == 4 then 
call EnableTrigger(gg_trg_Katze_Steuerung_5) 
call EnableTrigger(gg_trg_Katze_Steuerung_5_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_5_Streifzug)


call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions1) 
else 
call EnableTrigger(gg_trg_Katze_Steuerung_6) 
call EnableTrigger(gg_trg_Katze_Steuerung_6_Hilfe) 


call EnableTrigger(gg_trg_Katze_Steuerung_6_Streifzug)

 
call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Actions_Subactions2) 
endif

This trigger is fully operational - 2/3 of my problem are solved.
Unbelievable that such a simple mistake slipped through more than a dozen controls of mine... ~~
I am already too old. ^^

Remaining dysfunction:

Trigger "controlCat1" does not make the unit attack specified targets as it is supposed to do.
 
Level 2
Joined
Sep 10, 2004
Messages
21
ummm...the new version of the excerpt of trainCat is the same?(german names?) or did I miss something?
But if that whole function is messed nothing would work so I think its alright.
The cat doesnt attack targets? Perhaps a range of 1000 is too much and the cat changes targets too often; or you should replace the IssueTargetOrderBJ functon with the native one, this sometimes helps. Another reason could be that the trigger is not (re-)activated correctly.
 
Level 5
Joined
May 22, 2006
Messages
150
[...] the new version of the excerpt of trainCat is the same?
Yes, that is exactly what I thought a thousand times while looking over it again and again to find out, what is wrong.
These lines are different:

JASS:
call EnableTrigger(gg_trg_Katze_Steuerung_x)

JASS:
call EnableTrigger(gg_trg_Katze_Steuerung_x_Streifzug)

For each time exept the first one "x=1" I used them. ~~
That is, why only the first "cat" moved around while the others held their position.
Some mistakes are so simple... ~~


Let us see...

Range of 1000 has been an experimental value.
I tried 250 first, then 300, 500, 750 and finally 1000.

Native function of IssueTargetOrderBJ...
That is IssueTargetOrder - the only use of the BJ function is... none! Simple waste of time.
May it work or not, that i will change at once.

Trigger activation?
Do not have time to check it yet, that will take a whole bunch of this wealthy ressource. ^^

Okay, ether in one hour or in two days i will know if one of these two possiblities is right.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
hmm, cant look at this now, but ill have a look tonight ( prob not, gotta code a system for someone ) or tomorrow at this time

EDIT: the problem is that you are putting the DisableTrigger( gg_trg_controlCat1 ) before the triggerregisgterunitevent and triggeraddaction.

Since InitTrigs are only run on startup, this cancels the only chance to init the trigger

to fix this ( and still have the trigger disable as supposed to ) move the DisableTrigger to the end.
 
Level 5
Joined
May 22, 2006
Messages
150
Sorry but no, I have a lot of working triggers which make use of this order.

I isolated the problem by inserting text messages into my code:
It is the EventListener of "ControlCatX".

I only do not know, why.
Unit types are correct, syntax is right, the variable is set...
Must be the function itself. ~~
 
Level 5
Joined
May 22, 2006
Messages
150
Whenever I want more than one function to deal with an object, I prefer global variables as long as I use the trigger system.
... It should be possible to recode my whole script into a triggerless syntax, but the map I am working on has 135 of these and to be sure I am simply too lazy to do such a bunch of work.

Yes, these BJ-things are aggravating and most of them have already been replaced - I waited with cleaning these functions as they did not work yet.

... function "TriggerRegisterUnitInRange(trigger,unit,real,boolexpr)" does not work with Condition "null".
I will test, if it works with a filter.

postscript:
The function does not work at all. ~~
Not to wonder about why a trigger is not working if there is no event returned.
 
Level 5
Joined
May 22, 2006
Messages
150
I already did.
As I wrote in the last postscript: No event is thrown.
I used a text message to test it - nothing happened.

Any idea for an alternate construction?
 
Level 5
Joined
May 22, 2006
Messages
150
Here three triggers become activated...

JASS:
if udg_Zaehler[13] == 0 then
call EnableTrigger(gg_trg_catControl1)
call EnableTrigger(gg_trg_helpCatControl1)
call EnableTrigger(gg_trg_catControl1Wander)
call ForForce(udg_Streitmacht[0],function Trig_Katze_Bau_Subactions1)
[...]

"gg_trg_catControl1Wander" works. It makes the cat moving around.

In order to expose the problem, I altered "gg_trg_catControl1":

JASS:
function Trig_catControl1_Actions takes nothing returns nothing
call DisplayTimedTextToForce(GetPlayersAll(),5.00,"Cat 1 engages target.")
call DisableTrigger(gg_trg_catControl1)
call DisableTrigger(gg_trg_catControl1Wander)
call IssueTargetOrder(udg_Katze[0],"attack",GetTriggerUnit())
endfunction

As you see: If the wrong position of "DisableTrigger()" whould cause my trouble, at least the text whould be displayed - no text appeared, when I moved my test unit into range.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
right after the DisableTrigger in ControlCat1, try putting a BJDebugMsg( "bwahahahaahahaha" )

after the events, conds, actions and stuff ( at teh end of the InitTrig ), put a BJDebugMsg( "hahahaahahah" )

see if both fire. if the first does but not the second, you are having a thread crash somewhere. if neither fire, then the DisableTrigger should be moved to the end of the InitTrig. if Both fire, it is in the action or conditions itself. if both fire, tell me and ill have another look xD
 
Level 5
Joined
May 22, 2006
Messages
150
You forgot one case: What if the second one fires, but not the first one?
As I foresaw, that is exactly what happened.

Right after starting my game, the second message appeared.
When I moved my test units into range, nothing happened...

It whould have been very strange, if it whould have been else... Or do you not trust me? ^^
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
here is why only the SECOND should never activate

-If there was a thread crash BEFORE the first, then neither would activate

-If there was no trouble, both would activate

-If there was a thread crash AFTER the first, only the first would activate

those are all the scenarios that i can think of xD
 
Level 5
Joined
May 22, 2006
Messages
150
Well, then join me in simply accepting the fact that it does not work and help me to find an alternate way to do what I want to be done.
It is no help for anybody to think in an infinite loop - as long as you do not want to script a first person mode, there they are quite useful. ^^
 
Level 5
Joined
May 22, 2006
Messages
150
Well, possibly via ICQ (I can contact with AIM) or via E-Mail, what do you prefer? The file has a size of 2.310.570 Bytes.

Ah, but all the names are german.
Of course, names are irrelevant, as long as they stay the same, but reading could be more difficult for you than for the VM.
 
Level 5
Joined
May 22, 2006
Messages
150
I have exactly one Trigger in my map, which is not already written in custom text. ^^

And ... what is XFire?
Surely some imensely useful function, I did not recognize as I am blind to anything important. ^^
 
Level 5
Joined
May 22, 2006
Messages
150
Well then, I hope that works... via AIM I can only send you files while you are online... And while I am online too, of course.

... If these things are not compatible, I will not recognize it, I worry...
 
Level 5
Joined
May 22, 2006
Messages
150
Ah yes, beautiful school - half a blessing, half a curse...

Well, via E-Mail you could still get it, if you are owner of a data stick (an mp3-player for example) and the school's PC has a fitting interface.

I could simply name the file after something you can admit to need (in informatics "PostFixCalculator.java" or something similar for example) and then you may grab it onto your data-container.
Renaming the file at home - ready.

All you need is an E-Mail account with more than 2.2 Mb store capacity.
 
Level 5
Joined
May 22, 2006
Messages
150
Well, I count that as "no".

Then, tell me your idea and let me do the work - I feel more comfortable that way, anyway. ^^
 
Level 5
Joined
May 22, 2006
Messages
150
I have no idea how to understand your last sentence. ^^
Anyway, I registered to X-Fire (and even yet I do not like it ~~) and sent you an "invitation to become my friend".

Strange it is, I think, to call somebody I barely know about more than the fact of his very existence "friend"...
 
Level 5
Joined
May 22, 2006
Messages
150
Ah, well then, if you are living in GMT - 5, you should have a good chance to catch me around eight (am) till one (pm) o'clock.
As I sense, that you will have schoolish work to do this time, I could also arrange half an hour starting from one (am) o'clock.

Does not sound very comfortable, does it? ^^
 
Level 5
Joined
May 22, 2006
Messages
150
There is a lot of unfinished stuff inside.
"Triggers\Sonstiges\" is the directory, you should look inside mainly.

If you want me to explain a certain triggers work, do not hesitate to ask.
 
Level 5
Joined
May 22, 2006
Messages
150
There is a lot of unfinished stuff inside.
"Triggers\Sonstiges\" is the directory, you should look inside mainly.

If you want me to explain a certain trigger's work, do not hesitate to ask.
 
Level 5
Joined
May 22, 2006
Messages
150
Huh? ... No.
In "gg_trg_Katze_Bau.Trig_Katze_Bau_Actions" I enable these triggers:
"gg_trg_Katze_Steuerung_1"
"gg_trg_Katze_Steuerung_1_Hilfe"
"gg_trg_Katze_Steuerung_1_Streifzug"

Thus, I have to disable "gg_trg_Katze_Steuerung_1" and "gg_trg_Katze_Steuerung_1_Streifzug" for preventing them from interrupting the cat's attack move.
The trigger "gg_trg_Katze_Steuerung_1_Hilfe" reactivates them after the target has been killed.
... Or should reactivate them. Due to the little problem, that they are never deactivated and the target is never attacked, the trigger will never fire.
... And it does not need to. ~~
 
Level 5
Joined
Feb 16, 2006
Messages
151
I am not sure, but this is not supposed to work at all....
JASS:
call ForForce(udg_Force[0],function Trig_trainCat_Subactions1)
Are you using a function from another trigger at this spot?
You can't...
You would have to put it into the header, because if you disable the Trigger consisting of this function, that function will also be gone...
As for the rest...
I think there are far too global many triggers for this......and we don't have to use so many as are not in GUI, aren't we?
BTW, I still don't know what it is supposed to do, please explain in your own words...
Oder sogar auf Deutsch :>
 
Level 5
Joined
May 22, 2006
Messages
150
Ah, das ist eine große Erleichterung. ^^
Ich habe zwar kein Problem damit, muntere Reden beliebiger Länge auf Englisch zu halten, aber die Schilderung spezifischer Problemstellungen ist dann doch etwas problematisch.

Schauen wir einmal...
Zunächst:
Dein Verweis auf das "GUI" ist berechtigt - diesen Komplex begann ich, bevor ich auch nur ansatzweise JASS verstand und habe ihn erst später konvertiert, weil ich mit den Beschränkungen des "GUI" nicht weitergekommen bin.
Da er nicht funktioniert, habe ich ihn noch nicht gänzlich rationalisiert, weil ich nicht prüfen könnte, ob ich dabei wohl eventuell einen oder mehrere Fehler gemacht hätte und sich also die Suche nach der Ursache des nicht-Funktionierens verkompliziert hätte.

Der Komplex (der nur teilweise hier geschildert ist) hat folgende Ziele:

- Erfassung des Baus eines spezifischen Einheitentyps durch eine spezifische Spielergruppe (funktioniert)
- Speicherung der fertiggestellten Einheit im Array "udg_Katze[]" gemäß ihrer Seriennummer (funktioniert)
- Zuordnung der fertiggestellten Einheit zum Spieler "Neutral passiv" (funktioniert)
- Streifzug der Einheit über die Karte (funktioniert)
- Unterbrechung des Streifzuges der Einheit bei Annäherung an ein definiertes Ziel und Angriff dieses Zieles (funktioniert nicht!)
- Wiederaufnahme des Streifzuges nach Tötung des Ziels (ungeprüft, da Streifzug nie eingestellt)

Bekannte Symptome der Fehlfunktion:
Keine Aktion des Auslösers "gg_trg_Katze_Steuerung_x" (x={1,...,6}) wird ausgelöst, sobald der Entfernungsgrenzwert zu einem definierten Ziel unterschritten wurde.

Fehlereingrenzung:
Der parallel zum Auslöser "gg_trg_Katze_Steuerung_x" laufende Auslöser "gg_trg_Katze_Steuerung_x_Streifzug" funktioniert ordnungsgemäß.
->
Der Auslöser, der die Auslöser "gg_trg_Katze_Steuerung_x", "gg_trg_Katze_Steuerung_x_Streifzug" und "gg_trg_Katze_Steuerung_x_Hilfe" bei Fertigstellung der Einheit aktivieren soll, funktioniert ordnungsgemäß.
->
Der Auslöser "gg_trg_Katze_Steuerung_x" ist zum Zeitpunkt der Überprüfung nicht inaktiv.
->
Die Ereignisregistration sollte bei Unterschreitung der Grenzwertentfernung zwischen udg_Katze[x] und einem definierten Ziel reagieren.
->
Die Aktionen des Auslösers sollten in diesem Moment ausgeführt werden.

...

Die Zeile, die du zitierst, stammt aus dem Auslöser "gg_trg_Katze_Bau" wie auch die Funktion "Trig_Katze_Bau_Subactions1".
 
Level 5
Joined
Feb 16, 2006
Messages
151
Ach weisst du, kack auf GUI >_>...
Mach wie ich das gemacht hab, soll heissen:
Du speicherst die Einheit via "SetHandleHandle" in den Trigger mit der RegisterUnitInRange:
JASS:
local trigger cat_help_trg = null
local unit cat
set cat = GetTrainedUnit()//GetSoldUnit()//oder CreateUnit(...), wie dus haben willst
if (GetUnitTypeId(cat) == 'H001') then//cat1
set cat_help_trg = gg_trg_controlCat1
elseif (GetUnitTypeId(cat) == 'H002') then//cat2
//...
//etc...
endif
if (cat_helper_trg != null ) then
call TriggerRegisterUnitInRangeSimple(cat_helper_trg,1000,cat)
call SetHandleHandle(cat_helper_trg,"Cat",cat)
endif
Das ist der Trigger fuer verkaufte/tranierte cats...
du hast dann 6 mal gg_trg_controlCat1(2,3,4,5,6),
die dann die verkauften Units mit "GetHandleUnit" aufnehmen und verarbeiten koennen.
JASS:
local unit cat = GetHandleUnit(GetTriggeringTrigger(),"Cat")
Die Handle-Funktionen hatte ich dir im anderen Thread gepostet, muessten reichen.[/code]
 
Level 5
Joined
May 22, 2006
Messages
150
1.
Warum benutzt du die BJ-Funktion "TriggerRegisterUnitInRangeSimple"?

2.
Dass das nicht funktionieren wird, sehe ich mit geschlossenen Augen. ^^
Der Typ meiner Katzen ist nämlich immer und ausschließlich 'ndog' - da ändert sich nicht ein Bit.
 
Level 5
Joined
Feb 16, 2006
Messages
151
Oder halt...
JASS:
TriggerRegisterUnitInRange(trig, whichUnit, range, null)
Ach und, du hast immer die selbe Einheit des gleichen Types?
Hmm....
Tja, dann musst du jedes mal einen lokalen Trigger erstellen, statt globale Trigger zu benutzen.
JASS:
function cat_trg_action takes nothing returns nothing
local unit cat = GetHandleUnit(GetTriggeringTrigger(),"Cat")
...
endfunction
function ??? takes nothing returns nothing
...
local trigger cat_help_trg = CreateTrigger()
...
local unit cat
set cat = GetTrainedUnit()//GetSoldUnit()//oder CreateUnit(...), wie dus haben willst
call TriggerRegisterUnitInRange(cat_helper_trg,1000,cat,null)
call TriggerAddAction(cat_helper_trg,function cat_trg_action)
call SetHandleHandle(cat_helper_trg,"Cat",cat)
...
endfunction
Wenn die Aktion der "angenaehrten Katze" immer die selbe ist(was ich mal hoffe), solltest du die Funktion "cat_trg_action" in den header packen...
 
Level 5
Joined
May 22, 2006
Messages
150
... Ich glaube, ich habe den Fehler gefunden...

Die Variable "udg_Katze[0]" wird mit dem Wert "null" initialisiert...
Der Auslöser wird also mit dem Ereignis "TriggerRegisterUnitInRange(Auslöser,null,Radius,Fallunterscheidung)" initialisiert.
Und also kann da nichts passieren, weil niemals eine Einheit einen Abstand von x - sei es reele oder selbst komplexe Zahl - zu nichts einnehmen kann.

Himmel!
Was mache ich den da...
Ich kann dies beim ersten Mal durch "Ereignis hinzufügen" umgehen - aber wenn diese erste Katze getötet wird, kann ich das entsprechende Ereignis nicht mehr entfernen!
Was tun!?

Nachtrag:
Ich habe es getestet - das ist der Fehler.
Fatal!

As this may be important for others too, here is the translation of my report... At least a try to translate it:

The variable "udg_Katze[0]" is being initialised with the value "null" on start of the map.
So, the trigger is initialised with the event "TriggerRegisterUnitInRange(trigger,null,range,boolean expression)".
Thus, there cannot happen anything, as never a unit comes in any range to nothing!

The problem may be solved on the first activation by adding the event then instead of on map start.
But if or when the cat is killed, there seems not to be a way to remove this event!
So, there would be a whole lot of "dead" events in the trigger, which would decrease effectivity...
What may I do?
 
Level 5
Joined
Feb 16, 2006
Messages
151
Ach, echt?
Hast du ueberhaupt meinen Post gelesen?
Ausserdem ist es ueberhaupt nicht schlimm, dass die Katze getoetet wird. Im schlimmsten Fall Removest du jede Katze die tot ist, und der Event bleibt fuer immer da, ohne was zu machen.
 
Level 5
Joined
May 22, 2006
Messages
150
Ich war noch nicht fertig. ~~
Das Forum hat nur mal eben zehn Minuten (nun gut, wohl etwas weniger) gebraucht, um mich von der Eintragung wieder zurückzubringen.

... Du hast das, was ich eben schrieb, nie konkret ausgesagt und es hat sich mir, da du stets meine komplette Struktur geändert hast, auch nicht aus dem Quelltext erschlossen.

Wie auch immer:

I will use UmMi's idea of a local trigger, hoping that "DestroyTrigger(trigger)" also destroys a triggers events.
Then I will create a new trigger on every death of a cat, which I grant the same function as "action" but an ever new generated event.

In a minute or two I will post the altered code as postscript.

postscript (okay, not only two minutes):

Just tested - It works.

global variables:
JASS:
trigger array udg_Katze_Steuerung
Easier as the triggers have to be accessed by three functions.

"global" functions
JASS:
//This enables the picked players to train new cats.

function Trig_Katze_Subactions1 takes nothing returns nothing
  call SetPlayerTechMaxAllowed(GetEnumPlayer(),'ndog',-1)
endfunction

//This disables the picked players to train new cats.

function Trig_Katze_Subactions2 takes nothing returns nothing
  call SetPlayerTechMaxAllowed(GetEnumPlayer(),'ndog',0)
endfunction

//If a unit enters a cats range, this returns if the unit is a possible target.

function Trig_Katze_Steuerung_Conditions takes nothing returns boolean
  return GetUnitTypeId(GetTriggerUnit()) == 'nfro' or GetUnitTypeId(GetTriggerUnit()) == 'ndwm' or GetUnitTypeId(GetTriggerUnit()) == 'nrat'
endfunction

//These ones are all identical exept for the array indices
//They make the specified cat attack the unit, which entered its range.

function Trig_Katze_Steuerung_1_Actions takes nothing returns nothing
  call DisableTrigger(udg_Katze_Steuerung[0])
  call DisableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
  call IssueTargetOrder(udg_Katze[0],"attack",GetTriggerUnit())
endfunction

function Trig_Katze_Steuerung_2_Actions takes nothing returns nothing
  call DisableTrigger(udg_Katze_Steuerung[1])
  call DisableTrigger(gg_trg_Katze_Steuerung_2_Streifzug)
  call IssueTargetOrder(udg_Katze[1],"attack",GetTriggerUnit())
endfunction

function Trig_Katze_Steuerung_3_Actions takes nothing returns nothing
  call DisableTrigger(udg_Katze_Steuerung[2])
  call DisableTrigger(gg_trg_Katze_Steuerung_3_Streifzug)
  call IssueTargetOrder(udg_Katze[2],"attack",GetTriggerUnit())
endfunction

function Trig_Katze_Steuerung_4_Actions takes nothing returns nothing
  call DisableTrigger(udg_Katze_Steuerung[3])
  call DisableTrigger(gg_trg_Katze_Steuerung_4_Streifzug)
  call IssueTargetOrder(udg_Katze[3],"attack",GetTriggerUnit())
endfunction

function Trig_Katze_Steuerung_5_Actions takes nothing returns nothing
  call DisableTrigger(udg_Katze_Steuerung[4])
  call DisableTrigger(gg_trg_Katze_Steuerung_5_Streifzug)
  call IssueTargetOrder(udg_Katze[4],"attack",GetTriggerUnit())
endfunction

function Trig_Katze_Steuerung_6_Actions takes nothing returns nothing
  call DisableTrigger(udg_Katze_Steuerung[5])
  call DisableTrigger(gg_trg_Katze_Steuerung_6_Streifzug)
  call IssueTargetOrder(udg_Katze[5],"attack",GetTriggerUnit())
endfunction

trigger "Katze Hilfe 1"
JASS:
//This filters out the players, which did not build the cat currently being under construction but would be able to.

function Trig_Katze_Hilfe_1_Conditions takes nothing returns boolean
  return IsPlayerInForce(GetFilterPlayer(),udg_Streitmacht[0]) and GetFilterPlayer() != GetOwningPlayer(udg_tempEinheit)
endfunction

//This stops training of a cat if the maximum amount of cats has already been reached.
//It also counts each try to train a cat.

function Trig_Katze_Hilfe_1_Actions takes nothing returns nothing
  if GetIssuedOrderId() == 'ndog' then
    set udg_tempEinheit = GetTriggerUnit()
    if udg_Zaehler[13] == 5 then
      call IssueImmediateOrder(udg_tempEinheit,"stop")
    else
      set udg_tempSpielergruppe = GetPlayersMatching(Condition(function Trig_Katze_Hilfe_1_Conditions))
      call ForForce(udg_tempSpielergruppe,function Trig_Katze_Subactions2)
      set udg_Zaehler[13] = udg_Zaehler[13] + 1
    endif
  endif
endfunction

function InitTrig_Katze_Hilfe_1 takes nothing returns nothing
  set gg_trg_Katze_Hilfe_1 = CreateTrigger()
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Hilfe_1,Player(0),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Hilfe_1,Player(1),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Hilfe_1,Player(2),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Hilfe_1,Player(3),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Hilfe_1,Player(4),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Hilfe_1,Player(8),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
  call TriggerAddAction(gg_trg_Katze_Hilfe_1,function Trig_Katze_Hilfe_1_Actions)
endfunction

trigger "Katze Hilfe 2"
JASS:
//This counts each training of a cat, that was stopped by the owning player.

function Trig_Katze_Hilfe_2_Actions takes nothing returns nothing
  if GetIssuedOrderId() == OrderId("stop") then
    set udg_Zaehler[13] = udg_Zaehler[13] - 1
    call DestroyForce(udg_tempSpielergruppe)
    call ForForce(udg_Streitmacht[0],function Trig_Katze_Hilfe_Subactions1)
  endif
endfunction

function InitTrig_Katze_Hilfe_2 takes nothing returns nothing
  set gg_trg_Katze_Hilfe_2 = CreateTrigger()
  call TriggerRegisterUnitEvent(gg_trg_Katze_Hilfe_2,udg_tempEinheit,ConvertUnitEvent(75))
  call TriggerAddAction(gg_trg_Katze_Hilfe_2,function Trig_Katze_Hilfe_2_Actions)
endfunction

trigger "Katze Bau"
JASS:
//This enables/creates the controlling triggers for each of the six cats.

function Trig_Katze_Bau_Actions takes nothing returns nothing
  if GetTrainedUnitType() == 'ndog' then
    set udg_Katze[udg_Zaehler[13]] = GetTrainedUnit()
    call SetUnitOwner(udg_Katze[udg_Zaehler[13]],Player(15),true)
    if udg_Zaehler[13] == 0 then
      set udg_Katze_Steuerung[0] = CreateTrigger()
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[0],udg_Katze[0],750,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[0],udg_Katze[0],500,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[0],udg_Katze[0],250,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerAddAction(udg_Katze_Steuerung[0],function Trig_Katze_Steuerung_1_Actions)
      call EnableTrigger(gg_trg_Katze_Steuerung_1_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions1)
    elseif udg_Zaehler[13] == 1 then
      set udg_Katze_Steuerung[1] = CreateTrigger()
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[1],udg_Katze[1],750,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[1],udg_Katze[1],500,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[1],udg_Katze[1],250,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerAddAction(udg_Katze_Steuerung[1],function Trig_Katze_Steuerung_2_Actions)
      call EnableTrigger(gg_trg_Katze_Steuerung_2_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_2_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions1)
    elseif udg_Zaehler[13] == 2 then
      set udg_Katze_Steuerung[2] = CreateTrigger()
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[2],udg_Katze[2],750,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[2],udg_Katze[2],500,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[2],udg_Katze[2],250,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerAddAction(udg_Katze_Steuerung[2],function Trig_Katze_Steuerung_3_Actions)
      call EnableTrigger(gg_trg_Katze_Steuerung_3_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_3_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions1)
    elseif udg_Zaehler[13] == 3 then
      set udg_Katze_Steuerung[3] = CreateTrigger()
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[3],udg_Katze[3],750,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[3],udg_Katze[3],500,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[3],udg_Katze[3],250,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerAddAction(udg_Katze_Steuerung[3],function Trig_Katze_Steuerung_4_Actions)
      call EnableTrigger(gg_trg_Katze_Steuerung_4_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_4_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions1)
    elseif udg_Zaehler[13] == 4 then
      set udg_Katze_Steuerung[4] = CreateTrigger()
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[4],udg_Katze[4],750,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[4],udg_Katze[4],500,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[4],udg_Katze[4],250,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerAddAction(udg_Katze_Steuerung[4],function Trig_Katze_Steuerung_5_Actions)
      call EnableTrigger(gg_trg_Katze_Steuerung_5_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_5_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions1)
    else
      set udg_Katze_Steuerung[5] = CreateTrigger()
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[5],udg_Katze[5],750,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[5],udg_Katze[5],500,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerRegisterUnitInRange(udg_Katze_Steuerung[5],udg_Katze[5],250,Condition(function Trig_Katze_Steuerung_Conditions))
      call TriggerAddAction(udg_Katze_Steuerung[5],function Trig_Katze_Steuerung_6_Actions)
      call EnableTrigger(gg_trg_Katze_Steuerung_6_Hilfe)
      call EnableTrigger(gg_trg_Katze_Steuerung_6_Streifzug)
      call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions2)
    endif
    call DestroyForce(udg_tempSpielergruppe)
  endif
endfunction

function InitTrig_Katze_Bau takes nothing returns nothing
  set gg_trg_Katze_Bau = CreateTrigger()
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Bau,Player(0),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Bau,Player(1),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Bau,Player(2),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Bau,Player(3),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Bau,Player(4),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Bau,Player(8),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
  call TriggerAddAction(gg_trg_Katze_Bau,function Trig_Katze_Bau_Actions)
endfunction

trigger "Katze Tod"
JASS:
//This stops/destroys the controlling triggers for each of the six cats.

function Trig_Katze_Tod_Actions takes nothing returns nothing
  if GetUnitTypeId(GetDyingUnit()) == 'ndog' then
    if udg_Zaehler[13] == 5 then
      call DestroyTrigger(udg_Katze_Steuerung[5])
      call DisableTrigger(gg_trg_Katze_Steuerung_6_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_6_Streifzug)
    elseif udg_Zaehler[13] == 4 then
      call DestroyTrigger(udg_Katze_Steuerung[4])
      call DisableTrigger(gg_trg_Katze_Steuerung_5_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_5_Streifzug)
    elseif udg_Zaehler[13] == 3 then
      call DestroyTrigger(udg_Katze_Steuerung[3])
      call DisableTrigger(gg_trg_Katze_Steuerung_4_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_4_Streifzug)
    elseif udg_Zaehler[13] == 2 then
      call DestroyTrigger(udg_Katze_Steuerung[2])
      call DisableTrigger(gg_trg_Katze_Steuerung_3_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_3_Streifzug)
    elseif udg_Zaehler[13] == 1 then
      call DestroyTrigger(udg_Katze_Steuerung[1])
      call DisableTrigger(gg_trg_Katze_Steuerung_2_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_2_Streifzug)
    else
      call DestroyTrigger(udg_Katze_Steuerung[0])
      call DisableTrigger(gg_trg_Katze_Steuerung_1_Hilfe)
      call DisableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
    endif
    set udg_Zaehler[13] = udg_Zaehler[13] - 1
    call ForForce(udg_Streitmacht[0],function Trig_Katze_Subactions1)
  endif
endfunction

function InitTrig_Katze_Tod takes nothing returns nothing
  set gg_trg_Katze_Tod = CreateTrigger()
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Tod,Player(15),EVENT_PLAYER_UNIT_DEATH,null)
  call TriggerAddAction(gg_trg_Katze_Tod,function Trig_Katze_Tod_Actions)
endfunction

trigger "Katze Steuerung 1 Hilfe"
JASS:
//While ordered to attack, the cat's controlling triggers are turned off.
//This reactivates them on death of the target.

function Trig_Katze_Steuerung_1_Hilfe_Actions takes nothing returns nothing
  if GetKillingUnit() == udg_Katze[0] then
    call EnableTrigger(udg_Katze_Steuerung[0])
    call EnableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
  endif
endfunction

function InitTrig_Katze_Steuerung_1_Hilfe takes nothing returns nothing
  set gg_trg_Katze_Steuerung_1_Hilfe = CreateTrigger()
  call DisableTrigger(gg_trg_Katze_Steuerung_1_Hilfe)
  call TriggerRegisterPlayerUnitEvent(gg_trg_Katze_Steuerung_1_Hilfe,Player(15),EVENT_PLAYER_UNIT_DEATH,null)
  call TriggerAddAction(gg_trg_Katze_Steuerung_1_Hilfe,function Trig_Katze_Steuerung_1_Hilfe_Actions)
endfunction

trigger "Katze Steuerung 1 Streifzug"
JASS:
//This makes the cat wandering around like the ability 'AWan' but more randomly.

function Trig_Katze_Steuerung_1_Streifzug_Actions takes nothing returns nothing
  local location array tempPunkt
  local real array tempReal
  local rect tempGebiet
  set tempPunkt[0] = GetUnitLoc(udg_Katze[0])
  set tempReal[0] = GetLocationX(tempPunkt[0])
  set tempReal[1] = GetLocationY(tempPunkt[0])
  set tempGebiet = Rect(tempReal[0]-500,tempReal[1]-500,tempReal[0]+500,tempReal[1]+500)
  set tempReal[0] = GetRectMinX(tempGebiet)
  set tempReal[1] = GetRectMaxX(tempGebiet)
  set tempReal[2] = GetRectMinY(tempGebiet)
  set tempReal[3] = GetRectMaxY(tempGebiet)
  set tempPunkt[1] = Location(GetRandomReal(tempReal[0],tempReal[1]),GetRandomReal(tempReal[2],tempReal[3]))
  call IssuePointOrderLoc(udg_Katze[0],"move",tempPunkt[1])
  call TriggerSleepAction(3.00)
  call RemoveLocation(tempPunkt[0])
  call RemoveLocation(tempPunkt[1])
  call RemoveRect(tempGebiet)
  set tempPunkt[0] = null
  set tempPunkt[1] = null
  set tempGebiet = null
endfunction

function InitTrig_Katze_Steuerung_1_Streifzug takes nothing returns nothing
  set gg_trg_Katze_Steuerung_1_Streifzug = CreateTrigger()
  call DisableTrigger(gg_trg_Katze_Steuerung_1_Streifzug)
  call TriggerRegisterTimerEvent(gg_trg_Katze_Steuerung_1_Streifzug,GetRandomReal(10.00,20.00),true)
  call TriggerAddAction(gg_trg_Katze_Steuerung_1_Streifzug,function Trig_Katze_Steuerung_1_Streifzug_Actions)
endfunction

There are ten more triggers, which are simple copies of "Katze Steuerung 1 Hilfe" and "Katze Steuerung 1 Streifzug" with the numbers increasing up to six and with other indices for the cat-array.

There is a lot more to enhance but yet it works and as I and others spent a pretty big amount of time to make it do, I would dare to say that it is good work.

What may be better?

A filter in EventListener or an "if"-structure in "Actions"-function?
Returning values from one function to another or using globals?

(Before dooming globals from the beginning - think about that they are much saver than locals, do not need more space and are as useful while functions are not supposed to work parallel.)
 
Status
Not open for further replies.
Top