Author Topic: The Magic Flute  (Read 455 times)

Legacy_Llionei

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
The Magic Flute
« on: November 03, 2011, 10:08:36 pm »


               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);
                }
        }
}

               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
The Magic Flute
« Reply #1 on: November 04, 2011, 01:34:52 am »


               

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.
               
               

               
            

Legacy_Peepsy

  • Jr. Member
  • **
  • Posts: 55
  • Karma: +0/-0
The Magic Flute
« Reply #2 on: November 04, 2011, 01:52:31 am »


               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.
               
               

               
            

Legacy_Peepsy

  • Jr. Member
  • **
  • Posts: 55
  • Karma: +0/-0
The Magic Flute
« Reply #3 on: November 04, 2011, 02:03:30 am »


               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);
              }
  }
        }
}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
The Magic Flute
« Reply #4 on: November 04, 2011, 02:11:11 am »


               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.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
The Magic Flute
« Reply #5 on: November 04, 2011, 02:17:58 am »


               @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.
               
               

               
            

Legacy_Peepsy

  • Jr. Member
  • **
  • Posts: 55
  • Karma: +0/-0
The Magic Flute
« Reply #6 on: November 04, 2011, 02:30:11 am »


               I didn't think that was the proper function.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
The Magic Flute
« Reply #7 on: November 04, 2011, 05:19:10 am »


               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 .
                     
                  


            

Legacy_Llionei

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
The Magic Flute
« Reply #8 on: November 04, 2011, 11:08:52 am »


               Ok, thanks guys. You helped me again. I will have to learn those loops someday. '<img'>
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
The Magic Flute
« Reply #9 on: November 04, 2011, 01:23:56 pm »


               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 .
                     
                  


            

Legacy_Llionei

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
The Magic Flute
« Reply #10 on: November 04, 2011, 02:28:53 pm »


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