Converting a trigger fully to JASS.

For fulfilled maps that most likely don't work on the latest patch (1.24 or later).

Moderator: Cheaters

User avatar
Bartimaeus
Tyrannical Drama Queen
Posts: 4430
Joined: November 19th, 2007, 5:05 am
Been thanked: 2 times

Converting a trigger fully to JASS.

Post by Bartimaeus »

Alright, I need help on converting a trigger fully to JASS. Here's the trigger, if anyone can give a crap.

CopyItem
Events
Player - Player 1 (Red) types a chat message containing -item as A substring
Player - Player 2 (Blue) types a chat message containing -item as A substring
Player - Player 3 (Teal) types a chat message containing -item as A substring
Player - Player 4 (Purple) types a chat message containing -item as A substring
Player - Player 5 (Yellow) types a chat message containing -item as A substring
Player - Player 6 (Orange) types a chat message containing -item as A substring
Player - Player 7 (Green) types a chat message containing -item as A substring
Player - Player 8 (Pink) types a chat message containing -item as A substring
Player - Player 9 (Gray) types a chat message containing -item as A substring
Player - Player 10 (Light Blue) types a chat message containing -item as A substring
Player - Player 11 (Dark Green) types a chat message containing -item as A substring
Player - Player 12 (Brown) types a chat message containing -item as A substring
Conditions
((Triggering player) is in AdditionalCommands) Equal to True
Actions
Unit Group - Pick every unit in (Units currently selected by (Triggering player)) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -item1
Then - Actions
Hero - Create (Item-type of (Item carried by (Picked unit) in slot 1)) and give it to (Picked unit)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -item2
Then - Actions
Hero - Create (Item-type of (Item carried by (Picked unit) in slot 2)) and give it to (Picked unit)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -item3
Then - Actions
Hero - Create (Item-type of (Item carried by (Picked unit) in slot 3)) and give it to (Picked unit)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -item4
Then - Actions
Hero - Create (Item-type of (Item carried by (Picked unit) in slot 4)) and give it to (Picked unit)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -item5
Then - Actions
Hero - Create (Item-type of (Item carried by (Picked unit) in slot 5)) and give it to (Picked unit)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -item6
Then - Actions
Hero - Create (Item-type of (Item carried by (Picked unit) in slot 6)) and give it to (Picked unit)
Else - Actions

Works exactly how I want it to, I type -item1 it creates the same item in slot one into a slot that's free on my selected unit(s), or drops it upon the ground if I don't have any room.

Now, my problem is turning this into JASS and making it compatible with JJ's cheat pack. How would I do this? I haven't the faintest clue of where to start. I tried protection the map with Vexorian's Optimizer, than copy + pasting the triggers into a map with JJ's cheat pack. Well, it doesn't come up in syntax errors, but the trigger in-game doesn't actually work - which is what I don't want.

Also, btw, here's the thing that allows me to use the cheat.

Starting Trigger
Events
Player - Player 1 (Red) types a chat message containing -Bartholemus as An exact match
Conditions
(Player 1 (Red) is in AdditionalCommands) Equal to False
Actions
Player Group - Add (Triggering player) to AdditionalCommands

I put this on a map with absolutely nothing on it, 32x32, no objects, no custom stuff, except those two triggers.
Here is exactly what I extracted.

under globals
item udg_CopyItem=null
integer udg_CopyItemlol=0
force udg_AdditionalCommands=CreateForce()
trigger gg_trg_CopyItem=CreateTrigger()
trigger gg_trg_Bartholemus=CreateTrigger()

Under Globals

function Trig_CopyItem_Conditions takes nothing returns boolean
return(IsPlayerInForce(GetTriggerPlayer(),udg_AdditionalCommands))
endfunction
function Trig_CopyItem_Func002Func001C takes nothing returns boolean
return(GetEventPlayerChatString()=="-item1")
endfunction
function Trig_CopyItem_Func002Func002C takes nothing returns boolean
return(GetEventPlayerChatString()=="-item2")
endfunction
function Trig_CopyItem_Func002Func003C takes nothing returns boolean
return(GetEventPlayerChatString()=="-item3")
endfunction
function Trig_CopyItem_Func002Func004C takes nothing returns boolean
return(GetEventPlayerChatString()=="-item4")
endfunction
function Trig_CopyItem_Func002Func005C takes nothing returns boolean
return(GetEventPlayerChatString()=="-item5")
endfunction
function Trig_CopyItem_Func002Func006C takes nothing returns boolean
return(GetEventPlayerChatString()=="-item6")
endfunction
function Trig_CopyItem_Func002A takes nothing returns nothing
if(Trig_CopyItem_Func002Func001C())then
call UnitAddItemByIdSwapped(GetItemTypeId(UnitItemInSlotBJ(GetEnumUnit(),1)),GetEnumUnit())
endif
if(Trig_CopyItem_Func002Func002C())then
call UnitAddItemByIdSwapped(GetItemTypeId(UnitItemInSlotBJ(GetEnumUnit(),2)),GetEnumUnit())
endif
if(Trig_CopyItem_Func002Func003C())then
call UnitAddItemByIdSwapped(GetItemTypeId(UnitItemInSlotBJ(GetEnumUnit(),3)),GetEnumUnit())
endif
if(Trig_CopyItem_Func002Func004C())then
call UnitAddItemByIdSwapped(GetItemTypeId(UnitItemInSlotBJ(GetEnumUnit(),4)),GetEnumUnit())
endif
if(Trig_CopyItem_Func002Func005C())then
call UnitAddItemByIdSwapped(GetItemTypeId(UnitItemInSlotBJ(GetEnumUnit(),5)),GetEnumUnit())
endif
if(Trig_CopyItem_Func002Func006C())then
call UnitAddItemByIdSwapped(GetItemTypeId(UnitItemInSlotBJ(GetEnumUnit(),6)),GetEnumUnit())
endif
endfunction
function Trig_CopyItem_Actions takes nothing returns nothing
call ForGroupBJ(GetUnitsSelectedAll(GetTriggerPlayer()),function Trig_CopyItem_Func002A)
endfunction
function Trig_Bartholemus_Conditions takes nothing returns boolean
return(IsPlayerInForce(Player(0),udg_AdditionalCommands)==false)
endfunction
function Trig_Bartholemus_Actions takes nothing returns nothing
call ForceAddPlayer(udg_AdditionalCommands,GetTriggerPlayer())
endfunction

Under Main

call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(0),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(1),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(2),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(3),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(4),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(5),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(6),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(7),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(8),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(9),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(10),"-item",false)
call TriggerRegisterPlayerChatEvent(gg_trg_CopyItem,Player(11),"-item",false)
call TriggerAddCondition(gg_trg_CopyItem,Condition(function Trig_CopyItem_Conditions))
call TriggerAddAction(gg_trg_CopyItem,function Trig_CopyItem_Actions)
call TriggerRegisterPlayerChatEvent(gg_trg_Bartholemus,Player(0),"-Bartholemus",true)
call TriggerAddCondition(gg_trg_Bartholemus,Condition(function Trig_Bartholemus_Conditions))
call TriggerAddAction(gg_trg_Bartholemus,function Trig_Batholemus_Actions)

What else do I need? If it's something to do with the triggers, please show me so I can correct it.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Converting a trigger fully to JASS.

Post by Aero »

If a GUI trigger works.... then you convert to to JASS....

Assuming that you moved the globally generated globals to "globals"...
The code/action funcs below "globals"...
And the InitTrig contents to function main...

The trigger will work the same.

Though, before you try importing this into a cheatpack, fix any memory leaks and optimize the code.
It will help detect errors.
User avatar
Bartimaeus
Tyrannical Drama Queen
Posts: 4430
Joined: November 19th, 2007, 5:05 am
Been thanked: 2 times

Re: Converting a trigger fully to JASS.

Post by Bartimaeus »

Aero wrote:If a GUI trigger works.... then you convert to to JASS....

Assuming that you moved the globally generated globals to "globals"...
The code/action funcs below "globals"...
And the InitTrig contents to function main...

The trigger will work the same.

Though, before you try importing this into a cheatpack, fix any memory leaks and optimize the code.
It will help detect errors.
Yeah, 'cause I know JASS, right? lol
User avatar
Bartimaeus
Tyrannical Drama Queen
Posts: 4430
Joined: November 19th, 2007, 5:05 am
Been thanked: 2 times

Re: Converting a trigger fully to JASS.

Post by Bartimaeus »

Sorry for double posting, but I just wanted to say I'm an idiot.
I didn't try it two times, and on the second try, it worked fine...lol
No wonder teachers always say, "Double check your work, kids." XD
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Converting a trigger fully to JASS.

Post by Aero »

Assuming that you moved the globally generated globals to "globals"...
The code/action funcs below "globals"...
And the InitTrig contents to function main...

The trigger will work the same.
;)