How to catch build event

Everything about mods can be found here.

Moderator: Morax

How to catch build event

Postby Phelom » 12 Jun 2015, 17:07

Hi guys..

I'm creating a map, in the script file i want to catch a build event :

When a player creates/builds something, i would like to call a function to do something else...

Any help ?
Thanks
User avatar
Phelom
Avatar-of-War
 
Posts: 195
Joined: 08 Apr 2015, 15:04
Location: Tizi Ouzou
Has liked: 104 times
Been liked: 25 times
FAF User Name: Phelom/Gurzil

Re: How to catch build event

Postby speed2 » 12 Jun 2015, 17:19

Code: Select all
Supreme Commander - Forged Alliance\gamedata\lua.scd\lua\ScenarioFramework.lua

Triggers are at the beginning,
maybe this one? line 242
Code: Select all
function CreateUnitBuiltTrigger( cb, unit, category )
    TriggerFile.CreateUnitBuiltTrigger( cb, unit, category )
end
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: How to catch build event

Postby Phelom » 12 Jun 2015, 17:27

Thank you, but how to catch it then in my own script ?
User avatar
Phelom
Avatar-of-War
 
Posts: 195
Joined: 08 Apr 2015, 15:04
Location: Tizi Ouzou
Has liked: 104 times
Been liked: 25 times
FAF User Name: Phelom/Gurzil

Re: How to catch build event

Postby Phelom » 12 Jun 2015, 17:29

For example, i want to check if the player has created a specific unit (land factory for example) then display a message... so how should i do ?
User avatar
Phelom
Avatar-of-War
 
Posts: 195
Joined: 08 Apr 2015, 15:04
Location: Tizi Ouzou
Has liked: 104 times
Been liked: 25 times
FAF User Name: Phelom/Gurzil

Re: How to catch build event

Postby speed2 » 12 Jun 2015, 17:38

first you need to import ScenarioFramework at the beginning of the script
Code: Select all
local ScenarioFramework = import('/lua/ScenarioFramework.lua')

Then in function OnStart you set up the trtigger, cb is your callback function
Code: Select all
ScenarioFramework.CreateUnitBuiltTrigger( cb, unit, category )

Try to play with it around a bit, maybe you will need different one for proper functionallity.
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: How to catch build event

Postby Phelom » 12 Jun 2015, 17:48

Thanks a lot... so helpfull !!

I'll try to play with :)
User avatar
Phelom
Avatar-of-War
 
Posts: 195
Joined: 08 Apr 2015, 15:04
Location: Tizi Ouzou
Has liked: 104 times
Been liked: 25 times
FAF User Name: Phelom/Gurzil

Re: How to catch build event

Postby speed2 » 12 Jun 2015, 17:53

Actually Ive noticed that ScenarioFramework is taking triggers from this file:
Code: Select all
Supreme Commander - Forged Alliance\gamedata\lua.scd\lua\scenariotriggers.lua

You might find some more there, Im sure one of them will work as you want. If you will use triggers from this file, import it and use as I decribed post above.
Good luck
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: How to catch build event

Postby Phelom » 12 Jun 2015, 18:01

I tryed this

Code: Select all
function OnStart(self)
   ScenarioFramework.CreateUnitBuiltTrigger( cb, unit, category )
end

cb = function(cb, unit, category)
   
   BroadcastMSG("Well done !", 8);

end


BroadcastMSG is just a function to print text, but i got nothing when i build something,

Any help ?
User avatar
Phelom
Avatar-of-War
 
Posts: 195
Joined: 08 Apr 2015, 15:04
Location: Tizi Ouzou
Has liked: 104 times
Been liked: 25 times
FAF User Name: Phelom/Gurzil

Re: How to catch build event

Postby Phelom » 12 Jun 2015, 18:05

I guess i have to add unit code in the function right ? if so, where can i find those codes ?
User avatar
Phelom
Avatar-of-War
 
Posts: 195
Joined: 08 Apr 2015, 15:04
Location: Tizi Ouzou
Has liked: 104 times
Been liked: 25 times
FAF User Name: Phelom/Gurzil

Re: How to catch build event

Postby speed2 » 12 Jun 2015, 18:14

categories list http://wiki.faforever.com/index.php?tit ... Categories

I think you will have to define unit first for this to work, YourFunctionName is the name of your function, it can be whatever. Dunno how broadcasting some message works. Im sure its in lua files and might be used in some survival maps. You can copy it from there.
Code: Select all
function OnStart(self)
   ScenarioFramework.CreateUnitBuiltTrigger(YourFunctionName, unit, categories.FACTORY * categoriesTECH1)
end

function YourFunctionName()
   BroadcastMSG("Well done !", 8);
end


category can be also specific unit, then you use unit ID, example: categories.uel0001
use UnitDB for finding IDs http://content.faforever.com/faf/unitsDB/
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Next

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest