Aller au contenu

Photo

How to attach a visual effect to the equiped weapon via script?


  • Veuillez vous connecter pour répondre
23 réponses à ce sujet

#1
Stephanommg

Stephanommg
  • Members
  • 13 messages

Hello,

 

I want to add a visual effect (the visual effect of magical weapons in SoZ)  to the equiped weapon, when the player equips a weapon.

My problem is not the algorithm, but what functions should i use.

 

1) To get the last item equiped i am using:

object oItem = GetPCItemLastEquipped();

 

but how can i be sure the last item is a weapon?

 

2) I need to check the enhancement level of the weapon, to apply the proper efefct. How can i check it?

 

3) I need to know the functions to apply the special effect to the weapon. I was trying:

 

ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectNWN2SpecialEffectFile("fx_magical_3.pfx",oItem),oItem);
 
but it doesnt work.


#2
Stephanommg

Stephanommg
  • Members
  • 13 messages

I found out how to apply the visual effet for the PC: 

ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectNWN2SpecialEffectFile("my_custom_effect_in_override_folder",pc),pc);

The custom effect must be edited in visual effects editor. In its properties, in FirstAttachment field, you must select something different than ATTACH_INVALID.

 

Still, I cant apply the effect to the weapon... :/



#3
kamal_

kamal_
  • Members
  • 5 240 messages
Why not just apply it as a weapon property? The vfx are weapon properties.

#4
Stephanommg

Stephanommg
  • Members
  • 13 messages

ItemPropertyVisualEffect demmands the effect code, which are the default effects, such as holy, unholy, acid, fire ...

The effect i want to add is a custom effect based on the fx_magical_* from SoZ.

Is there any other way to add a custom effect as a item property?



#5
kevL

kevL
  • Members
  • 4 056 messages

I want to add a visual effect (the visual effect of magical weapons in SoZ)


have you looked in SoZ? Or can you point me to where to look in SoZ?

1) To get the last item equiped i am using:
object oItem = GetPCItemLastEquipped();
 
but how can i be sure the last item is a weapon?


use a function like IPGetIsMeleeWeapon() in 'x2_inc_itemprop'.

2) I need to check the enhancement level of the weapon, to apply the proper efefct. How can i check it?


IPGetWeaponEnhancementBonus() ditto.

3) I need to know the functions to apply the special effect to the weapon.

...
 
but it doesnt work.


i think there's a workaround, but you won't like it : Create templates for every melee weapon (there's about 20), and assign them with your custom .SEF in their Appearance (special effect) slot. Then multiply those by the number of enhancement levels you wish, and assign those appropriate .SEF's also

And when PC equips a melee item, do the checks, copy the itemproperties over to a corresponding template item, destroy the old item and put the new one in the proper inventory slot.


Another idea is to apply an SEF to the character's hand-node instead of the weapon itself, but not sure how far that'd go

#6
Stephanommg

Stephanommg
  • Members
  • 13 messages


have you looked in SoZ? Or can you point me to where to look in SoZ?
 

 

In SoZ, all weapon have the fx_magical_* (1,2,3,4 or 5) attached in the Appearance(special effect slot).

 



use a function like IPGetIsMeleeWeapon() in 'x2_inc_itemprop'.
 

x2_inc_itemprop is a library I should include?

 

 

 

"Create templates for every melee weapon (there's about 20), and assign them with your custom .SEF in their Appearance (special effect) slot. Then multiply those by the number of enhancement levels you wish, and assign those appropriate .SEF's also

And when PC equips a melee item, do the checks, copy the itemproperties over to a corresponding template item, destroy the old item and put the new one in the proper inventory slot."

 

If i got it righ, there would be only 1 type of each weapon, right? If I have 1 template of a short sword, then every short sword i equip will look the same, except for the magical effect.

Another idea is to apply an SEF to the character's hand-node instead of the weapon itself, but not sure how far that'd go

 

Already tryied, but only the hand glows. :/

 

I had ready this http://nwn2.wikia.co...ecialEffectFile, and from what i got, it is not possible to do exactly what I want. :/

In Visual Effect Editor, you have the option to set the body part which the effect will hold. You have the option item_hook_1, but when u click, the editor changes to right_hand for some unknown reason.

 

But what if i make my effect a visual effect item property, like acid, fire, eletric... etc? Is it possible? My idea was to use ItemPropertyVisualEffect, but this function demands the effect code. Thus, in order get it work my effect should have a code that should be recognized by the function.



#7
Stephanommg

Stephanommg
  • Members
  • 13 messages

I was looking at CopyItemAndModify. This functions allows to create a copy of the item and modify its appearance. Whit this i could copy my template weapon and modifiy its appearance to look the equiped weapon. But in order to do this, i need to know the model number of each part of the equiped weapon, and i didnt find any function which retrieves the this information.



#8
Dann-J

Dann-J
  • Members
  • 3 161 messages

 

 I was trying:

 

ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectNWN2SpecialEffectFile("fx_magical_3.pfx",oItem),oItem);
 
but it doesnt work.

 

 

You'll have to reference the SEF file, rather than the PFX.



#9
Stephanommg

Stephanommg
  • Members
  • 13 messages

Yes i know, this was my first atempt. In my second post i said i managed to get it work, but only for the entire body of the pc, not the weapon.



#10
kevL

kevL
  • Members
  • 4 056 messages

I was looking at CopyItemAndModify. This functions allows to create a copy of the item and modify its appearance. Whit this i could copy my template weapon and modifiy its appearance to look the equiped weapon. But in order to do this, i need to know the model number of each part of the equiped weapon, and i didnt find any function which retrieves the this information.

GetItemAppearance(object oItem, int nType, int nIndex)

--
The problem as far as i see it is that the ITEM_VISUAL_* constants, don't seem to be controlled by a .2da file (unlike most stock SEFs, which are controlled by VisualEffects.2da). So i think that weapon damageType effects, the ones you want to toy with, are unfortunately hardcoded ....

Not the effects themselves: they are described by "fx_defaultitem_*.SEF" files in the data folder. I've changed mine to make them less extravagant, and it works. But if you change the one for fire, for example, you change all stock fire vFx on all weapons. If that's what you want, look in "data\NWN2_VFX*.zip\FX_Battle" for the SEF's and related PFX's.

 

In SoZ, all weapon have the fx_magical_* (1,2,3,4 or 5) attached in the Appearance(special effect slot).

ok so they're using item-templates ...
 

x2_inc_itemprop is a library I should include?

to use those functions, yes #include.
 

If i got it righ, there would be only 1 type of each weapon, right? If I have 1 template of a short sword, then every short sword i equip will look the same, except for the magical effect.

lets see, a sword's special Appearance is tied to its template. So if you want a different look for +1 vs. +2 etc weapons, they'd each need their own template. That's a lot of blueprints,
 

I had ready this http://nwn2.wikia.co...ecialEffectFile, and from what i got, it is not possible to do exactly what I want. :/

that's the conclusion i came to yesterday. But note that the Silver Sword in the OC uses special effect files in some advanced and complicated ways that might be a lead on how to do this. (iirc, they are a bit bugged and don't fully work in the game, but they can be fixed - i did it a long time ago - such that the PC is shown holding a sword that isn't actually there ... or something like that).
 

But what if i make my effect a visual effect item property, like acid, fire, eletric... etc? Is it possible? My idea was to use ItemPropertyVisualEffect, but this function demands the effect code. Thus, in order get it work my effect should have a code that should be recognized by the function.

see the first couple of paragraphs in this post.


but maybe someone has a different approach ...



#11
Stephanommg

Stephanommg
  • Members
  • 13 messages

Yes in SoZ, they use templates. But the idea was to avoid this, because it would be a lot of work to edit EVERY magical weapon in toolset, adding the proper effect in appearance field.

 

And no, the efefct I want is a visual effect of a glow for magical weapons. I dont want to edit existing effects. This glow is present in magical weapons, just as in SoZ.

 

So, it seems, the solution is to make n templates for each weapon type, were n is the number of magical enhancements. Then, when a weapon is equiped, i do the checks, copy the proper template and modidy it to look the same (i mean the model parts, the blade, the middle and the bottom) as the original weapon; the only difference will be the magical visual effect from the template.

 

Thanks kevL, I will have a look at it later!



#12
kevL

kevL
  • Members
  • 4 056 messages

if you have Powerbar (or use the Visual Effects Editor plugin but it's not as convenient), check out the vFx for the SilverSword of the OC


esp. 'fx_silversword_reform'

if you can create a dang sword like that, i figure there must be a way to apply an Fx to a character's blade ....

- most are under 'fx_silversword*' and 'fx_ssword*'



#13
Stephanommg

Stephanommg
  • Members
  • 13 messages

I was trying something more simple, to see if it works and to get used to the functions. But still, I had some problems.

First i am trying to discover in what slot the equiped weapon will be (left or rigth hand). But i couldnt get this info, since it seems the weapon wasnt equiped yet.

then, i try to create the template item using CreateItemOnObject, but it always fails to create the item, and im sure the blueprint is right.

Here is my code:

 

void main(){
    object pc  = GetPCItemLastEquippedBy();
    object item = GetPCItemLastEquipped();
    int slot;                   //what i really wanted was a function like getItemSlotInInventory(object item, object pc) but i couldnt find it
    if (GetItemInSlot(INVENTORY_SLOT_CWEAPON_R,pc) == item){
        slot = INVENTORY_SLOT_CWEAPON_R;
    }else if (GetItemInSlot(INVENTORY_SLOT_CWEAPON_L,pc) == item){
        slot = INVENTORY_SLOT_CWEAPON_L;
    }else if (GetItemInSlot(INVENTORY_SLOT_CWEAPON_B,pc) == item){       //WTF is CWEAPON_B??
        slot = INVENTORY_SLOT_CWEAPON_B;
    }else {
        slot = INVENTORY_SLOT_CWEAPON_R;              //it always come here, leading me to believe the weapon was not equiped yet
    }
    object correspItem = CreateItemOnObject("mace_magical",pc);          //my intent here is to create my template mace with the magical effect in pc' inventory
    if (correspItem == OBJECT_INVALID)                // but it fails...
        SendMessageToPC(pc, "error creating object"); 
   .
   .         //copy appearance....
   .
    DestroyObject(item);
    ActionEquipItem(correspItem,slot);
 
}


#14
Dann-J

Dann-J
  • Members
  • 3 161 messages

The include script 'ginc_item' has some very useful functions, like GetSlotOfEquippedItem().

 

Others of interest may be:

 

DestroyItemInSlot()

EquipNewItem() {create a new item from a blueprint and equip it immediately}

GetIsWeapon()



#15
kevL

kevL
  • Members
  • 4 056 messages

these are the inventory slots:

int    INVENTORY_SLOT_HEAD      = 0;
int    INVENTORY_SLOT_CHEST     = 1;
int    INVENTORY_SLOT_BOOTS     = 2;
int    INVENTORY_SLOT_ARMS      = 3;
int    INVENTORY_SLOT_RIGHTHAND = 4;
int    INVENTORY_SLOT_LEFTHAND  = 5;
int    INVENTORY_SLOT_CLOAK     = 6;
int    INVENTORY_SLOT_LEFTRING  = 7;
int    INVENTORY_SLOT_RIGHTRING = 8;
int    INVENTORY_SLOT_NECK      = 9;
int    INVENTORY_SLOT_BELT      = 10;
int    INVENTORY_SLOT_ARROWS    = 11;
int    INVENTORY_SLOT_BULLETS   = 12;
int    INVENTORY_SLOT_BOLTS     = 13;
int    INVENTORY_SLOT_CWEAPON_L = 14;
int    INVENTORY_SLOT_CWEAPON_R = 15;
int    INVENTORY_SLOT_CWEAPON_B = 16;
int    INVENTORY_SLOT_CARMOUR   = 17;

the C stands for Creature. They're hidden ... used for innate creature weaponry & armors, usually.

look for _RIGHTHAND and _LEFTHAND


i'll tinker at it, too.



#16
Stephanommg

Stephanommg
  • Members
  • 13 messages

Found the CreateItemOnObject problem! The string parameter is not the resref, it is the "Resource Name" field in toolset properties. The Resource Name is the resref by default, but I modified the resref, so thats whay it didnt work before.

 

 

 

A question: The first time GetPCItemLastEquipped() runs, if the player doesnt have weapons equiped, what is the return value? NULL?



#17
Stephanommg

Stephanommg
  • Members
  • 13 messages

Now, the problem is CopyItemAndModify. It is not copying the item.

 

object correspItem = CreateItemOnObject("mace_magical",pc);
int itemApp = GetItemAppearance(item,ITEM_APPR_TYPE_WEAPON_MODEL,ITEM_APPR_WEAPON_MODEL_TOP);
correspItem = CopyItemAndModify(correspItem,ITEM_APPR_TYPE_WEAPON_MODEL, ITEM_APPR_WEAPON_MODEL_TOP, itemApp);
SendMessageToPC(pc,"item copied");
SendMessageToPC(pc, GetName(correspItem));  //prints nothing


#18
kevL

kevL
  • Members
  • 4 056 messages

I'm also getting something funny going on when copying ITEM_APPR_TYPE_WEAPON_MODEL. I'm not getting feedback *from wihtin the script* (NwScript sometimes 'waits' till a script completes before it completes a call -- functions like DestroyObject and AssignCommand, etc. -- the only way to tell is test)

here's the funny thing: I am getting feedback within the script when changing ITEM_APPR_TYPE_WEAPON_COLOR !

that is, as soon as i copy&modify to a newly created item, i give myself a debug message. I do this after each of 6 copy&modify calls. The first three change the weapon model, the next three change its color. And I get debug from the last three but not the first three, even though implementation is identical ....

Here's what makes it even funnier. It works ... the objects are valid and the replacement item appears in the hand-slot


but there are distinct timing issues going on. One often has to tinker and fudge with DelayCommand() and wrappers to get things executing properly. Finally, when deleting those extra objects from copy&modify, I'm still left with one in inventory. Again, i think it's a timing issue of the script calls against the engine.




oh, and watch out for the loop that happens when equipping the replacement; I had about 15 items created before putting a stop to that malarky.

pastebin

So i suspect that your item *is* copying, but your feedback won't say it unless you delay that debug-check somehow.



#19
kevL

kevL
  • Members
  • 4 056 messages

oh, spotted a bug in my code ......

 

[edit] nope, you're right, something funny with copy&modify MODEL



#20
kevL

kevL
  • Members
  • 4 056 messages

ohoh, 34 lists CopyItemAndModify() as deprecated or NA ...

i'm going to tinker with it a bit but



#21
Stephanommg

Stephanommg
  • Members
  • 13 messages

My tests were more or less like yours. I didnt tested chenging collors, only the model, and the pc never equiped the copied/modified weapon, only the weapon created in inventory.

 

Well, since the copyAndModify is broken, things get difficult :/

 

But most of the weapons in my mod were edited years ago, so the magical glow visual was attached to their appearance manually. I just wanted to do all this because created weapons (from smithing for example) didnt have the attached visual effect. So, bringing the console and attaching the visual effect in game to a weapon would not be a problem for me, since this would be a rare thing. So... do you know any command to do this?



#22
kevL

kevL
  • Members
  • 4 056 messages

for the record:
re. CopyItemAndModify()

- changing COLOR creates a new object but does not modify the color.
- trying to change MODEL fails completely. No copy is created. Plus the script borks at that point, not executing any commands after that. the script continues
 

 

But most of the weapons in my mod were edited years ago, so the magical glow visual was attached to their appearance manually. I just wanted to do all this because created weapons (from smithing for example) didnt have the attached visual effect. So, bringing the console and attaching the visual effect in game to a weapon would not be a problem for me, since this would be a rare thing. So... do you know any command to do this?


no, sry. But if i were you I'd have a closer look at trying to stretch an effect from the hand-node along the length of a weapon, although I'm not sure that could be done convincingly.



#23
kevL

kevL
  • Members
  • 4 056 messages
... the attached visual effect. So, bringing the console and attaching the visual effect in game to a weapon would not be a problem for me, since this would be a rare thing. So... do you know any command to do this?

oh if you use the ITEM_VISUAL_* constants, just write up a little script and bingo.

 

edit : any script with the proper calls and arguments can be run from the command line with "runscript" ...



#24
kevL

kevL
  • Members
  • 4 056 messages

here's the script i used a couple days ago:

// 'applyfx'

void main()
{
    object oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND);
    
    itemproperty ipVis = ItemPropertyVisualEffect(ITEM_VISUAL_HOLY);
    AddItemProperty(DURATION_TYPE_PERMANENT, ipVis, oItem);
}


have the weapon in righthand slot and run

rs applyfx