Aller au contenu

Photo

The Magic Flute


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

#1
Llionei

Llionei
  • Members
  • 14 messages
I have always problem with getting a good script that will effect on many objects so I need your help, guys. I was planning to do a magic flute that will effect rats - make them friendly for a certain time and fallow PC, but now it's only affects one of them and I don't know how to make to skip the whole thing onto other rats.

void main()
{
object oPC = GetItemActivator();
object oObject = GetNearestCreature(CREATURE_TYPE_RACIAL_TYPE, RACIAL_TYPE_ANIMAL, oPC);
location lPC = GetLocation(oPC);
location lObject = GetLocation(oObject);
effect eVisual = EffectVisualEffect(VFX_FNF_HOWL_MIND);
string sObject = GetTag(oObject);
float fDistance = GetDistanceBetweenLocations(lObject, lPC);


        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVisual, lPC);
        PlaySound("as_pl_whistle2");
        if(fDistance < 8.0)
        {
                if(sObject == "5_ratA" || sObject == "5_ratB" || sObject == "5_ratC" || sObject == "5_ratD" || sObject == "5_ratE" || sObject == "5_ratF")
                {
                SetIsTemporaryFriend(oPC, oObject, TRUE, 10.0);
                AssignCommand(oObject, ClearAllActions());
                AssignCommand(oObject, ActionForceFollowObject(oPC, 2.0));
                oObject = GetNextFactionMember(oObject);
                }
        }
}


#2
WhiZard

WhiZard
  • Members
  • 1 204 messages

Llionei wrote...

I have always problem with getting a good script that will effect on many objects so I need your help, guys. I was planning to do a magic flute that will effect rats - make them friendly for a certain time and fallow PC, but now it's only affects one of them and I don't know how to make to skip the whole thing onto other rats.

void main()
{
object oPC = GetItemActivator();
object oObject = GetNearestCreature(CREATURE_TYPE_RACIAL_TYPE, RACIAL_TYPE_ANIMAL, oPC);
location lPC = GetLocation(oPC);
location lObject = GetLocation(oObject);
effect eVisual = EffectVisualEffect(VFX_FNF_HOWL_MIND);
string sObject = GetTag(oObject);
float fDistance = GetDistanceBetweenLocations(lObject, lPC);


        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVisual, lPC);
        PlaySound("as_pl_whistle2");
        if(fDistance < 8.0)
        {
                if(sObject == "5_ratA" || sObject == "5_ratB" || sObject == "5_ratC" || sObject == "5_ratD" || sObject == "5_ratE" || sObject == "5_ratF")
                {
                SetIsTemporaryFriend(oPC, oObject, TRUE, 10.0);
                AssignCommand(oObject, ClearAllActions());
                AssignCommand(oObject, ActionForceFollowObject(oPC, 2.0));
                oObject = GetNextFactionMember(oObject);
                }
        }
}


Is ratA, ratB, etc. corresponding to separate rat factions?  If it is put a
while(oObject != OBJECT_INVALID){} nested inside your tag check if clause.

If these rats are simply of the hostile faction then you will need to check tags for each rat.

#3
Peepsy

Peepsy
  • Members
  • 28 messages
I had to read over it a few times to make sure, but you don't seem to have a loop! You get the next object, but never initiate a while.

#4
Peepsy

Peepsy
  • Members
  • 28 messages
Sorry mate, but this is the best I can do n my iPad. I don't know if it will compile or not. If you don't have it by the time i get home tonight, I'll hook you up proper.

void main()
{
object oPC = GetItemActivator();
object oObject = GetNearestCreature(CREATURE_TYPE_RACIAL_TYPE, RACIAL_TYPE_ANIMAL, oPC);
location lPC = GetLocation(oPC);
location lObject = GetLocation(oObject);
effect eVisual = EffectVisualEffect(VFX_FNF_HOWL_MIND);
string sObject = GetTag(oObject);
float fDistance = GetDistanceBetweenLocations(lObject, lPC);


        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVisual, lPC);
        PlaySound("as_pl_whistle2");
        if(fDistance < 8.0)
        {
while(GetIsObjectValid(oObject)) {
                    if(sObject == "5_ratA" || sObject == "5_ratB" || sObject == "5_ratC" || sObject == "5_ratD" || sObject == "5_ratE" || sObject == "5_ratF")
                {
                SetIsTemporaryFriend(oPC, oObject, TRUE, 10.0);
                AssignCommand(oObject, ClearAllActions());
                AssignCommand(oObject, ActionForceFollowObject(oPC, 2.0));
                oObject = GetNextFactionMember(oObject);
              }
  }
        }
}

#5
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Just a suggestion if you wanted to do it a little different. Instead of having the script loop through all of the creatures, have it send out a singnal to the rats using TALKVOLUME_SILENT_TALK as in an argument in SpeakString. Then Give the rats a custon OnConversation script to react to the silent talk. This way you will not have to loop through the rats and only rats in hearing distance with the custom OnConversation script will react to it.

#6
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
@peepsy, Your fix also has problems.
oObject = GetNextFactionMember(oObject); I am not sure about using the Argument for the function as the Assignment, Might create an endless loop, Not sure I have not tested that. the biggest thing is that it gets all of the faction members in the module and your only distance check is outside the loop against the nearest object. so you will most likely end up with every rat in the game migrating twoards the PC.

#7
Peepsy

Peepsy
  • Members
  • 28 messages
I didn't think that was the proper function.

#8
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
I just did this up quickly, using a shape instead of GetNearest...  I changed it around a little from your original script, but kept as much of the structure of the original as I could still.  Hopefully it would do the trick for you.

void main()
{
 object oPC = GetItemActivator();
 object oObject;
 string sObject;
 effect eVisual = EffectVisualEffect(VFX_FNF_HOWL_MIND);
 location lPC = GetLocation (oPC);
 // Set friendly durations here, in seconds.
 float fDuration = 10.0;
 // Set area of effect distance here, in meters.
 float fDistance = 8.0;

 ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVisual, lPC);
 PlaySound("as_pl_whistle2");
 oObject = GetFirstObjectInShape (SHAPE_SPHERE, fDistance, lPC);
 while (GetIsObjectValid (oObject))
    {
     sObject = GetTag(oObject);
     // if all rats starting with "5_rat" can be affected, the commented out line is better.
     // if (GetStringLeft (sObject, 5) == "5_rat")
     if(sObject == "5_ratA" || sObject == "5_ratB" || sObject == "5_ratC" || sObject == "5_ratD" || sObject == "5_ratE" || sObject == "5_ratF")
        {
         SetIsTemporaryFriend(oPC, oObject, TRUE, fDuration);
         AssignCommand(oObject, ClearAllActions());
         AssignCommand(oObject, ActionForceFollowObject(oPC, 2.0));
        }
     oObject = GetNextObjectInShape (SHAPE_SPHERE, fDistance, lPC);
    }
}


Edit:  Just noticed the "D" in duration was missing, which is odd since I compiled it before copy/pasting.

Modifié par Failed.Bard, 04 novembre 2011 - 02:37 .


#9
Llionei

Llionei
  • Members
  • 14 messages
Ok, thanks guys. You helped me again. I will have to learn those loops someday. :)

#10
SHOVA

SHOVA
  • Members
  • 522 messages
wouldn't you need to have the rats be a custom faction, to keep the flute from working on other animals?

Modifié par SHOVA, 04 novembre 2011 - 01:24 .


#11
Llionei

Llionei
  • Members
  • 14 messages
It doesn't work on other animals due to the '5_rat' tag which only those rats have.