Sign in to follow this  
CapitaineSpoque

Help Scripting K1 Explosive (FIXED)

Recommended Posts

Hi there,

I pulled out a script to get an explosive effect/damage similar to grenades. My goal is to have some destructible placeables that does this upon being destroyed.

It works pretty fine, however there is a problem related to factions. Here is my script

int GetReflexSavingThrow(object oTarget);
void main ()
{
int nDamage;
int nDC;
int nDCCheck;
object oTarget;
int nVFX;
{
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(1044), GetLocation(OBJECT_SELF));
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(3003), GetLocation(OBJECT_SELF));
        nDamage = 60;
        nDC = 15;
effect ePush = EffectForcePushTargeted(GetSpellTargetLocation());

        oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 4.0, GetLocation(OBJECT_SELF));
        while(GetIsObjectValid(oTarget))
            {
 if(!GetIsFriend(oTarget)||!GetIsNeutral(oTarget)||!GetIsEnemy(oTarget))
{
                nDCCheck = nDC;
                nDCCheck -= GetReflexSavingThrow(oTarget);
                if(!ReflexSave(oTarget, nDCCheck, SAVING_THROW_TYPE_NONE))
                {
                    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage, DAMAGE_TYPE_PIERCING), oTarget);
                }
                else
                {
                    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage/2, DAMAGE_TYPE_PIERCING), oTarget);
                }
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, ePush, oTarget, 0.1);
            }
            oTarget = GetNextObjectInShape(SHAPE_SPHERE, 4.0, GetLocation(OBJECT_SELF));
        }
    }
}

If i clear the "If(GetIsNeutral)" from the basic script, the damages loop infinitely. With my actual script, it does deal damages to any factions, but the damages can bounce back to a different faction each time, so it can bounce back infinitely until 1 target from a different faction is down. 

I don't really know what is wrong here, i just wish to apply the damages once to every type of factions.

Ty,

Share this post


Link to post
Share on other sites
3 hours ago, CapitaineSpoque said:

I don't really know what is wrong here

Well for starters, your script formatting is completely broken. I'm not even sure how it compiles. Second, your current check is pointless because it will always evaluate true for one of the conditions (not a friend OR not neutral OR not an enemy).

What exactly are you trying to do?

Share this post


Link to post
Share on other sites

"Well for starters, your script formatting is completely broken."

Ho well, i copied most of the code from the K_sup_grenade.nss (or K_inc i dont remember). 

"What exactly are you trying to do?"

I want a placeable (lets say, a Malfunctionning Mine, as there is a trap model) which explodes (deals damage once to any target in the area, whatever the faction, just like a grenade) upon being destroye (bashed). 

Here is a showcase from my current script so you can better understand : https://www.youtube.com/watch?v=R48vxlVrjkE

Edited by CapitaineSpoque

Share this post


Link to post
Share on other sites
16 minutes ago, CapitaineSpoque said:

whatever the faction

In that case you don't need any check at all, besides whichever objects are standing inside the blast radius.

void main () {
	
	int nDamage = 60;
	int nDCCheck = 15;
	object oTarget;
	location lSelf = GetLocation(OBJECT_SELF);
	
	ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(1044), lSelf); // VFX_IMP_SCORCH_MARK
	ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_GRENADE_FRAGMENTATION), lSelf);
	
	oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 4.0, lSelf);
	
	while (GetIsObjectValid(oTarget))
		{
			nDCCheck -= GetReflexSavingThrow(oTarget);
			
			if (!ReflexSave(oTarget, nDCCheck, SAVING_THROW_TYPE_NONE))
				{
					ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage, DAMAGE_TYPE_PIERCING), oTarget);
				}
				else
					{
						ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage/2, DAMAGE_TYPE_PIERCING), oTarget);
					}
			
			ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectForcePushTargeted(GetLocation(oTarget)), oTarget, 0.1);
			
			oTarget = GetNextObjectInShape(SHAPE_SPHERE, 4.0, lSelf);
		}
}

Who is the script owner, i.e. the one running the script? The placeable?

Share this post


Link to post
Share on other sites

Indeed, it will fire "OnDeath" basically.

I will try your version of the script. As i said, when i previously removed the !GetIsNeutral from the basic script, the damages looped infinitely until the first target is down (even if i have 10k Health Points). 

Edited by CapitaineSpoque

Share this post


Link to post
Share on other sites
51 minutes ago, CapitaineSpoque said:

Indeed, it will fire "OnDeath" basically.

A script will terminate when its owner dies. You'll probably need to farm it out to an invisible placeable spawned on top of the actual placeable.

53 minutes ago, CapitaineSpoque said:

the damages looped infinitely

That shouldn't be how the loop works. In theory at least.

Share this post


Link to post
Share on other sites

So i tested your version of the script, it works flawlessly.

It might be because of how i formated, or because of the conditional i couldnt get around with. 

Anyway thank you very much for your fast insights, im gonna do more extensive testing + compare the different codes and try to figure this out by myself. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this