Attaching Effects via LUA? [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Attaching Effects via LUA? [Solved]

Post 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?
Last edited by GAB on Tue Jul 22, 2014 1:36 pm, edited 3 times in total.
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Attaching Effects via LUA?

Post 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
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Attaching Effects via LUA?

Post 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.
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: Attaching Effects via LUA?

Post 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?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Attaching Effects via LUA?

Post 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.
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: Attaching Effects via LUA?

Post 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?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Attaching Effects via LUA?

Post 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.
Post Reply