Page 1 of 1
Attaching Effects via LUA? [Solved]
Posted: Tue Jul 22, 2014 11:31 am
by GAB
Well, I'm trying to attach an effect to a certain object through LUA commands but it is not working. I put the effect
kas1_bonfire_yellow in a effects folder below my
Worlds/ABC just like pretty much any other effect.
I first tried this:
Code: Select all
AttachEffectToObject(CreateEffect("kas1_bonfire_yellow"), "myg1_bldg_fire_effect")
print("Effect Code Ran")
but then I got this error
Code: Select all
Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\LuaCallbacks_Mission.cpp(4519)
Effect class "kas1_bonfire_yellow" not found
Effect Code Ran
Then I tried this:
Code: Select all
AttachEffectToObject("kas1_bonfire_yellow", "myg1_bldg_fire_effect")
print("Effect Code Ran")
And got no errors but the effect simply wasn't attached to the object.
What I'm looking for here is simply a way of having a nice control though LUA over which effect is attached to what object and when.
Any help?
Re: Attaching Effects via LUA?
Posted: Tue Jul 22, 2014 11:35 am
by Locutus
The code is correct, please take a look at the topic which was answered minutes before you opened this one;)
viewtopic.php?f=27&t=30459
Re: Attaching Effects via LUA?
Posted: Tue Jul 22, 2014 11:42 am
by Marth8880
Here's what I use to attach the shield item pickup effect in my mod to units who pick up the item:
Code: Select all
local charPtr = GetCharacterUnit(character)
local shieldPfx = CreateEffect("com_sfx_pickup_shield")
local charPos = GetEntityMatrix(charPtr)
AttachEffectToMatrix(shieldPfx, charPos)
If it's an object to which you're attaching the effect, GetCharacterUnit(character) won't work; you'll likely need to use something like GetObjectPtr or something.
Re: Attaching Effects via LUA?
Posted: Tue Jul 22, 2014 11:50 am
by GAB
AttachEffectToObject(CreateEffect("kas1_bonfire_yellow"), "myg1_bldg_fire_effect") worked. As Locutus mentioned in the post he linked, the effect has to be in the map's .req file (in the envfx section just for the record).
Problem solved. But it just makes me wonder, why when you attach an effect to an object though the .odf file you don't need to reference anything in the map's .req but when you want to use the LUA you have to reference the effect there?
Re: Attaching Effects via LUA?
Posted: Tue Jul 22, 2014 11:52 am
by Marth8880
GAB wrote:why when you attach an effect to an object though the .odf file you don't need to reference anything in the map's .req but then you want to use the LUA you have to reference the effect there?
I think it's because when you reference a file in an ODF, the referenced file is probably sort of "paired" and munged with the ODF or something along those lines.
Re: Attaching Effects via LUA?
Posted: Tue Jul 22, 2014 12:15 pm
by GAB
I just noticed that this fuctions seemingly attaches the effect to the origin of the object, which is inconvenient in some cases. Is there a way to attach the effect to a specific hardpoint or such things are only possible with matrices?
Re: Attaching Effects via LUA?
Posted: Tue Jul 22, 2014 12:24 pm
by Marth8880
GAB wrote:Is there a way to attach the effect to a specific hardpoint or such things are only possible with matrices?
You'd be best off simply offsetting the effect in Particle Editor.