ActivateItem Script Question
Zephirius
Member Posts: 419
Just trying to create a potion of Cause Serious Wounds. Didn't see any in the toolset.
As is it now the PC goes through all of the animations, but no spell?
As is it now the PC goes through all of the animations, but no spell?
}
// Potion of Cause Serious Wounds
object oUsed7 = GetItemActivated();
if (GetTag(oUsed7) == "SERIOUS_WOUNDS")
{
object oPC = GetItemActivatedTarget();
//object oPC = GetItemActivator();
AssignCommand(oPC, ActionCastSpellAtObject
(SPELL_INFLICT_SERIOUS_WOUNDS, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
}
0
Comments
object oPC = GetItemActivator(); AssignCommand(oPC, ActionCastSpellAtObject (SPELL_INFLICT_SERIOUS_WOUNDS, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));But it is a "touch" spell and I'm not sure how that works (on successful touch) if a player does it on themselves and so may not function as you intend.It might be best just to apply effects in this case rather than having the player cast a spell. Something like:
effect eDamage = EffectDamage(d8(3)); AssignCommand(oPC, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC));// Potion of Cause Serious Wounds object oUsed7 = GetItemActivated(); if (GetTag(oUsed7) == "SERIOUS_WOUNDS") { object oPC = GetItemActivatedTarget(); //object oPC = GetItemActivator(); effect ePotion = EffectVisualEffect(VFX_IMP_HEAD_EVIL); ApplyEffectToObject(DURATION_TYPE_INSTANT, ePotion, oPC); effect eDamage = EffectDamage(d6(3), DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL); ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC); //AssignCommand(GetItemActivatedTarget(), ActionCastSpellAtObject //(SPELL_INFLICT_SERIOUS_WOUNDS, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));As a touch attack it does "work". In the chat window the feedback indicates a successful hit occurred on the PC. But that's all that happens.
void main()
{
if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
object oPC = GetItemActivator();
object oItem = GetItemActivated();
{
//do stuff here
}
}
#include "x2_inc_switches" void main() { if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_ACTIVATE) { object oPC = GetItemActivator(); object oItem = GetItemActivated(); //do stuff here } }BTW Just a couple of things - By rejigging the if() statement I've removed the need for that return statement which in turn makes it so there is only a single exit point from the function. Doing so is said to make code easier to debug.Also I removed your extraneous { } around your comment as it served no purpose and if you are not careful can cause problems in whatever code you place there.
TR
I never declare variables inside brackets (after an if statement) I always declare them at the top of the script. Im not sure if this is a good or bad thing but its just a habit I developed over the years.
As to variables declared in smaller scopes, it just depends. If for example in this case you had them before the if so they were executed even if it was not ACTIVATE then you'd be doing a few extra "syscalls" and instructions. As written there's really no difference here. If you do all your variables that way then you are probably doing a few extra instructions here or there in your scripts but I don't think that will matter much. We are beyond the days of having to micro optimize instruction counts
#include "x2_inc_switches" // Potion of Cause Serious Wounds void main() { if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_ACTIVATE) { object oPC = GetItemActivator(); object oItem = GetItemActivated(); if (GetTag(oItem) == "serious_wounds") { int iHD = GetHitDice(oPC); effect eDamage = EffectDamage(d8(3) + iHD, DAMAGE_TYPE_NEGATIVE, DAMAGE_POWER_NORMAL); effect eVisual = EffectVisualEffect(VFX_IMP_NEGATIVE_ENERGY); DelayCommand(0.8, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oPC)); DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC)); } } }