PDA

View Full Version : Noob scripting question


Zgred_2
07-04-2007, 02:14 PM
Hey there, noob at scripting here :D I'm trying to make a new force power but I've managed to make it so that it works only on my main char, and I want it to work on the rest of my party, just like Master Valor does (it's an upgraded version). Here's the code:


#include "k_inc_force"

int FORCE_POWER_ENHANCEMENT = 132;

void main()
{

object oTarget = GetSpellTargetObject();

effect eTargetVisual;

effect eBuff;

SWFP_HARMFUL = FALSE;
if(GetHasSpellEffect(FORCE_POWER_ENHANCEMENT))
{
Sp_RemoveSpellEffectsGeneral(FORCE_POWER_ENHANCEME NT , oTarget);
}

SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, GetSpellId(), SWFP_HARMFUL));


eBuff = SetEffectIcon(eBuff, 5);

eTargetVisual = EffectVisualEffect(VFX_IMP_MIND_MASTERY);

eTargetVisual = EffectLinkEffects(eTargetVisual, EffectVisualEffect(VFX_IMP_MIND_MASTERY));




eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_STRENGTH, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_DEXTERITY, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_CONSTITUTION, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_INTELLIGENCE, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_WISDOM, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_CHARISMA, 7));
eBuff = EffectLinkEffects(eBuff, EffectSavingThrowIncrease(SAVING_THROW_TYPE_ALL, 7));



ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eTargetVisual, oTarget, 5.0);

ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBuff, oTarget, 40.0);
}

Also, how would I delay the visual effect of the power, to make it hit with a delay like Valor does. This activate immediately.

glovemaster
07-04-2007, 02:42 PM
I've had a look at your script and this is what i think you are after:
#include "k_inc_force"

int FORCE_POWER_ENHANCEMENT = 132;
void main()
{
object oTarget = GetSpellTargetObject();
effect eTargetVisual;
effect eBuff;

SWFP_HARMFUL = FALSE;
if(GetHasSpellEffect(FORCE_POWER_ENHANCEMENT)){
RemoveEffectByID(oTarget, FORCE_POWER_ENHANCEMENT);
}

SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, GetSpellId(), SWFP_HARMFUL));

eBuff = SetEffectIcon(eBuff, 5);
eTargetVisual = EffectVisualEffect(VFX_IMP_MIND_MASTERY);
eTargetVisual = EffectLinkEffects(eTargetVisual, EffectVisualEffect(VFX_IMP_MIND_MASTERY));

eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_STRENGTH, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_DEXTERITY, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_CONSTITUTION, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_INTELLIGENCE, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_WISDOM, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_CHARISMA, 7));
eBuff = EffectLinkEffects(eBuff, EffectSavingThrowIncrease(SAVING_THROW_TYPE_ALL, 7));

DelayCommand(n, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eTargetVisual, oTarget, 5.0));
DelayCommand(n, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBuff, oTarget, 40.0));
}
First i have layed it out a bit better, using tab and keeping it neat. :lol:
i have changed
Sp_RemoveSpellEffectsGeneral(FORCE_POWER_ENHANCEME NT , oTarget);To...
RemoveEffectByID(oTarget, FORCE_POWER_ENHANCEMENT);I am pretty sure this is what your after as you have set FORCE_POWER_ENHANCEMENT as 132 but im not entirly sure that the RemoveEffectByID function will work for what you are trying to do. I have also changed Sp_RemoveSpellEffectsGeneral becuase that is not a valid function, it is proberly a separate "sub" command that can be called. There would have been:
void Sp_RemoveSpellEffectsGeneral( (maybe a string variable) , int variable){
//code to remove the general effects
}.. Some where in the script out of the void main() part of the script.
Also i have added a DelayCommand function to the Apply effects which will cause the delay that you want, you will need to change n to the "n" amount of time you want a delay.
You can have different Delays for the visuals and the effects.

stoffe
07-04-2007, 03:07 PM
Hey there, noob at scripting here :D I'm trying to make a new force power but I've managed to make it so that it works only on my main char, and I want it to work on the rest of my party, just like Master Valor does (it's an upgraded version).

To do that you'll usually want to loop through all the party members who are with the player and apply the buff effects to them as well. For the force power to work even if used by non-party NPCs you'll have to loop through all friendlies to the caster who are nearby and apply the buff effects to them if the caster is not in the party.

Here is a modified version of your script that does this:


#include "k_inc_force"

int FORCE_POWER_ENHANCEMENT = 132;

void main() {
location lLoc = GetLocation(GetSpellTargetObject());
int iID = GetSpellId();
effect eVisual = EffectVisualEffect( VFX_IMP_MIND_MASTERY );
effect eBuff;

eBuff = EffectSavingThrowIncrease(SAVING_THROW_TYPE_ALL, 7);
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_STRENGTH, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_DEXTERITY, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_CONSTITUTION, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_INTELLIGENCE, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_WISDOM, 7));
eBuff = EffectLinkEffects(eBuff, EffectAbilityIncrease(ABILITY_CHARISMA, 7));
eBuff = SetEffectIcon(eBuff, 5);

// ST: The caster is a party member, apply to all other party members
if (IsObjectPartyMember(OBJECT_SELF)) {
int iParty;
for (iParty = 0; iParty < GetPartyMemberCount(); iParty++) {
object oParty = GetPartyMemberByIndex(iParty);
float fD = GetDistanceBetweenLocations(lLoc, GetLocation(oParty)) / 10.0;

if(GetHasSpellEffect( FORCE_POWER_ENHANCEMENT, oParty )) {
Sp_RemoveSpellEffectsGeneral( FORCE_POWER_ENHANCEMENT, oParty );
}

SignalEvent(oParty, EventSpellCastAt(OBJECT_SELF, iID, FALSE));
DelayCommand(fD, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oParty));
DelayCommand(fD, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBuff, oParty, 40.0));
}
}
// ST: The caster is a non-party NPC, apply to all nearby faction members.
else {
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 10.0, lLoc, FALSE, OBJECT_TYPE_CREATURE);
while (GetIsObjectValid(oTarget)) {
if (GetIsFriend(oTarget) && !GetIsDead(oTarget)) {
if(GetHasSpellEffect( FORCE_POWER_ENHANCEMENT, oTarget )) {
Sp_RemoveSpellEffectsGeneral( FORCE_POWER_ENHANCEMENT, oTarget );
}

float fD = GetDistanceBetweenLocations(lLoc, GetLocation(oTarget)) / 10.0;

SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, iID, FALSE));
DelayCommand(fD, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oTarget));
DelayCommand(fD, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBuff, oTarget, 40.0));
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, 10.0, lLoc, FALSE, OBJECT_TYPE_CREATURE);
}
}
}



Also, how would I delay the visual effect of the power, to make it hit with a delay like Valor does. This activate immediately.

You could delay applying the effects depending on how far away from the force user the targets are. This has been done in the modified script above.


* * *


i have changed
Sp_RemoveSpellEffectsGeneral(FORCE_POWER_ENHANCEME NT , oTarget);To...
RemoveEffectByID(oTarget, FORCE_POWER_ENHANCEMENT);

This would not have the desired effect, the orignal code was already correct (though it needs to be done to each target and not just the caster in this case). The RemoveEffectByID() function is used for removing visual effects from the target, not status/scripted effects. In this case what should be done is remove all existing effects from this power and apply them again if the power is re-cast to effectively refresh the duration of the buff.


I have also changed Sp_RemoveSpellEffectsGeneral becuase that is not a valid function


It is a valid function, but not a standard one. It is declared in the k_inc_force include file that the script uses. It is used to remove all effects from the target that originates from the specified spell/force power.

Zgred_2
07-04-2007, 03:49 PM
Thank you both for the quick and great replies ;) I've only started doing this today and what you saw was actually a modified script from beancounters tutorial. Oh and sorry if the code was weird, it got messed up when i copy/pasted it from KT. Well, it's back to modding for me, thanks again.

Zgred_2
07-05-2007, 08:31 AM
Hey, I wanted to ask something, again Does "OnPlayerEquipItem" work in K1? Same question for GrantFeat and GrantSpell

Btw, Sorry for double post

stoffe
07-05-2007, 08:56 AM
Hey, I wanted to ask something, again Does "OnPlayerEquipItem" work in K1? Same question for GrantFeat and GrantSpell


Unfortunately not, both GrantSpell(), GrantFeat() and the functions for manipulating ability scores and skills were added in K2:TSL.

As for the OnPlayerEquipItem event I don't think that exists in either KOTOR 1 or KOTOR 2. If you want to check if the player had something equipped you can continually check for it via some other script (usually a heartbeat event script of some object, since those are run once per round automatically).