Jump to content

Home

force power scripting help


moda

Recommended Posts

am having some trouble thinking of the script to do the following

 

i need to get a random attribute(WIS,CHA etc) for a script effect. so i more or less need to pick one random attribute then it will be subtracted by one for an overall effect.

 

this simple function is likely to become a staying point for a mod project im thinking of doing which will add a total of 4 new forces powers to tsl, to add a more roleplaying feel to the game

 

 

i have tried the following, but it doesnt seem to work properly

 

int rand = Random( 6 );

int rand2 = Random( 6 );

 

if (rand = 1){ AdjustCreatureAttributes(oPC, ABILITY_STRENGTH, -1);}

else

if (rand = 2){ AdjustCreatureAttributes(oPC, ABILITY_DEXTERITY, -1);}

else

if (rand = 3){ AdjustCreatureAttributes(oPC, ABILITY_CONSTITUTION, -1);}

else

if (rand = 4){ AdjustCreatureAttributes(oPC, ABILITY_INTELLIGENCE, -1);}

else

if (rand = 5){ AdjustCreatureAttributes(oPC, ABILITY_WISDOM, -1);}

else

if (rand = 6){ AdjustCreatureAttributes(oPC, ABILITY_CHARISMA, -1);}

else

if (rand2 = 1){ AdjustCreatureAttributes(oPC, ABILITY_STRENGTH, -1);}

else

if (rand2 = 2){ AdjustCreatureAttributes(oPC, ABILITY_DEXTERITY, -1);}

else

if (rand2 = 3){ AdjustCreatureAttributes(oPC, ABILITY_CONSTITUTION, -1);}

else

if (rand2 = 4){ AdjustCreatureAttributes(oPC, ABILITY_INTELLIGENCE, -1);}

else

if (rand2 = 5){ AdjustCreatureAttributes(oPC, ABILITY_WISDOM, -1);}

else

if (rand2 = 6){ AdjustCreatureAttributes(oPC, ABILITY_CHARISMA, -1);}

Link to comment
Share on other sites

The Random() function returns a value from 0 to 1 less than the number you provide. So by passing in 6, the function will return a number from 0 to 5, not 1 to 6. To fix this, either change your script to check numbers from 0 to 5, or use the d6() function instead. Also, you might want to use a switch statement instead of multiple if-else statements. Here is an example of what I mean.

 

void main() {
  object oPC = GetFirstPC();
  int nSubtract = -1;
  int nRand = d6( 1 );
  switch( nRand ) {
     case 1:
     AdjustCreatureAttributes( oPC, ABILITY_STRENGTH, nSubtract );
	 break;
     case 2:
        AdjustCreatureAttributes( oPC, ABILITY_DEXTERITY, nSubtract );
	 break;
  case 3:
     AdjustCreatureAttributes( oPC, ABILITY_CONSTITUTION, nSubtract );
	 break;
  case 4:
     AdjustCreatureAttributes( oPC, ABILITY_INTELLIGENCE, nSubtract );
	 break;
  case 5:
     AdjustCreatureAttributes( oPC, ABILITY_WISDOM, nSubtract );
	 break;
  case 6:
     AdjustCreatureAttributes( oPC, ABILITY_CHARISMA, nSubtract );
	 break;
}
}

 

Hope that helps. :)

 

- Star Admiral

Link to comment
Share on other sites

Here is an example of what I mean.

void main() {
  object oPC = GetFirstPC();
  int nSubtract = -1;
  int nRand = d6( 1 );
  switch( nRand ) {
     case 1:
     AdjustCreatureAttributes( oPC, ABILITY_STRENGTH, nSubtract );
	 break;
     case 2:
        AdjustCreatureAttributes( oPC, ABILITY_DEXTERITY, nSubtract );
	 break;
  case 3:
     AdjustCreatureAttributes( oPC, ABILITY_CONSTITUTION, nSubtract );
	 break;
  case 4:
     AdjustCreatureAttributes( oPC, ABILITY_INTELLIGENCE, nSubtract );
	 break;
  case 5:
     AdjustCreatureAttributes( oPC, ABILITY_WISDOM, nSubtract );
	 break;
  case 6:
     AdjustCreatureAttributes( oPC, ABILITY_CHARISMA, nSubtract );
	 break;
}
}

l

 

Or you could just do:

void main() {
   AdjustCreatureAttributes(GetFirstPC(), Random(6), -1);
}

 

...which would have the same result. :p

Link to comment
Share on other sites

I realise this is a double post but as this is a different issue i thought it would be acceptable. the below code doesnt seem to want to trigger, what it is supposed to do, is do damage to a target, if it kills the target it is then supposed to increase the casters force points, and add to a random attribute before moving onto another target. it is also only supposed to work when the caster has a alignment value of 10 or less.

 

at the moment it does nothing.

 

 

#include "st_inc_force"
void main()

{


object oCaster = OBJECT_SELF;

object oTarget = GetFirstObjectInArea(GetArea(OBJECT_SELF));
   while (GetIsObjectValid(oTarget)) {
       if (!GetIsDead(oTarget) 
           && GetIsEnemy(oTarget) 
           && (GetCurrentHitPoints(oTarget) > 0)
           && GetGoodEvilValue(oCaster) < 11)
       {
  int nForce=GetCurrentForcePoints(oCaster)*4;
  int nFP=GetCurrentForcePoints(oTarget)/20;
  int nHP=GetCurrentHitPoints(oTarget);

    effect FPd=EffectDamageForcePoints(nForce);
    effect FPdamage=EffectDamageForcePoints(nForce);
    effect HPdamage=EffectDamage(nForce, DAMAGE_TYPE_DARK_SIDE);

    effect eBeam = EffectBeam(VFX_BEAM_DEATH_FIELD_TENTACLE, OBJECT_SELF, BODY_NODE_HEAD);
    effect eVFX = EffectVisualEffect(VFX_PRO_DEATH_FIELD);

ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oTarget, 1.0f);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVFX, oTarget, 1.0f);

ApplyEffectToObject(DURATION_TYPE_INSTANT, FPdamage, oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, HPdamage, oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, FPd, oCaster);

if (GetIsDead(oTarget)){  
AdjustCreatureAttributes(oCaster, Random(6), 1);
AddBonusForcePoints(oCaster, nFP);}


       }
       oTarget = GetNextObjectInArea(GetArea(OBJECT_SELF));
   }

  int nHP=GetCurrentHitPoints(oTarget);

effect HPheal=EffectHeal(nHP);

ApplyEffectToObject(DURATION_TYPE_INSTANT, HPheal, oCaster);


}

Link to comment
Share on other sites

Okay, several comments to make on improving your code. First, I assume this code is for TSL, since you used stoffe's function include file, which is for TSL only. That being said, don't bother including functions that you don't plan to use. Everything in here can be done without that include file.

 

Second, since your power was intended to work only if the caster has an alignment of 10 or lower, it would be best to put that check first. If the caster has a higher alignment, then there is no point to even start looping through all the creatures in the area.

 

Third, declaring variables inside the loop is a bad idea, because every time the script loops, it will redeclare all the variables; not very useful, and may introduce bugs. Notice how I put all the variable declarations before the loop to avoid that issue. In addition, I also set the eBeam and eVFX effects first, since those effects will not change depending on the hit points or Force points of the target or the caster.

 

Fourth, there is no need to do a GetCurrentHitPoints( oTarget ) > 0 check. You already established that oTarget is not dead or dying by use of the GetIsDead( oTarget ) check. If the target isn't dead or dying, he must have at least 1 hit point.

 

Fifth, I noticed that you had the FPd and FPdamage effects both set to the same effect. Unless you intend to change that to two different effects, it would be best to simply use one effect. Also, while you don't *have* to follow the naming convention, prefixing all effect variables with an "e" is probably an easy way to keep track of all the variables.

 

Lastly, I put the nHP and EffectHeal( nHP ) functions inside the loop, as I suspected that was what you intended. Putting them outside the loop has no effect, since by the time the loop exits, oTarget is equal to OBJECT_INVALID, which means that it won't have any hit points and the healing effect will never work.

 

Here is the revised version of the script that you made.

 

void main() {

  object oCaster = OBJECT_SELF;

  if( GetGoodEvilValue( oCaster ) < 11 ) {
     int nForce, nFP, nHP;
  effect eHPHeal, eFPDamage, eHPDamage;
     effect eBeam = EffectBeam( VFX_BEAM_DEATH_FIELD_TENTACLE, OBJECT_SELF, BODY_NODE_HEAD );
     effect eVFX = EffectVisualEffect( VFX_PRO_DEATH_FIELD );
     object oTarget = GetFirstObjectInArea();
     while( GetIsObjectValid( oTarget ) ) {
        if( !GetIsDead(oTarget) && GetIsEnemy(oTarget) ) {
           nForce = GetCurrentForcePoints( oCaster ) * 4;
           nFP = GetCurrentForcePoints( oTarget ) / 20;
           nHP = GetCurrentHitPoints( oTarget );
		eHPHeal = EffectHeal( nHP );
           eFPDamage = EffectDamageForcePoints( nForce );
           eHPDamage = EffectDamage( nForce, DAMAGE_TYPE_DARK_SIDE );
           ApplyEffectToObject( DURATION_TYPE_TEMPORARY, eBeam, oTarget, 1.00 );
           ApplyEffectToObject( DURATION_TYPE_TEMPORARY, eVFX, oTarget, 1.00 );
           ApplyEffectToObject( DURATION_TYPE_INSTANT, eFPDamage, oTarget );
           ApplyEffectToObject( DURATION_TYPE_INSTANT, eHPDamage, oTarget );
           ApplyEffectToObject( DURATION_TYPE_INSTANT, eFPDamage, oCaster );
		ApplyEffectToObject( DURATION_TYPE_INSTANT, eHPHeal, oCaster );
           if( GetIsDead( oTarget ) ) {  
              AdjustCreatureAttributes( oCaster, Random(6), 1 );
              AddBonusForcePoints( oCaster, nFP );
		}
       }
       oTarget = GetNextObjectInArea();
     }
  }

}

 

One last thing. I assume that you have already set up a row in the spells.2da file to reference your new power. Otherwise it will not trigger. Hope this helps. :)

 

- Star Admiral

Link to comment
Share on other sites

thanks very much. by changing GetFirstObjectInArea to a getfirstobjectinshape i can change the maximum radius of the spell and make it work like death field in most regards correct.

 

i was using stoffe's include file as i had a custom setup of the force forms boosting the power of force abilities i.e. in the case of force potency it boosts the offensive power of this spell by a factor of four.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...