Jump to content
C.F.D

LASiren Script

Recommended Posts

Hey guys, 

I am experiencing a weird bug in-game, but it could be because of my limited knowledge on scripting. I wanted to assign multiple siren traits to a unit instead of default 2 siren traits; I added 4. I tested this out in-game, and when I press the siren command, it executed multiple siren tones at once, and if I shut the siren off, it still plays. Weird part is, when I move the unit out of the spot, further down the road, the siren still plays in the original spot. What did I mess up on here ? 

 

            int soundID;
            Vector CarPos = v.GetPosition();
             if (StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE01) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE02) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE03) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE04) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE05) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_USAR) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_TILLER) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_CRASHTENDER) == 0)
             {
                int random = Math::rand()%2;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren07.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren08.wav", CarPos, true);
                }
             }

 

LASiren.script

Link to comment
Share on other sites

I'm assuming you are attempting to have 1 of 4 possible sirens play when the siren is activated, which is selected at random?

Get Ready! Super long answer that's designed to teach instead of just giving you an answer. I have a soft spot for people actively attempting to learn to script.

Lets focus on the siren selection first, then we'll worry about the sound not following the vehicle problem later. Deal?

Lets start with this part of the code first:

                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren07.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren08.wav", CarPos, true);
              }

I'm sure you may be aware, but for the sake of others, let me explain something. If-Else statements work by evaluating the condition statement in between the first set of parentheses as either true or false.

if ( CONDITION TRUE ) 
    Do something
else
   Do something else

If the statement next to "if" is true, then the code block (designated between an opening "{" and closing "}" set of curly braces) immediately following it is executed. Any subsequent "else" statements are ignored and skipped. If the "if" statement is false, then the preceding code block is ignored and instead the "else" code block (again, designated as being between an opening "{" and closed "}" set of curly braces) is executed. 

As a rule, every "if" statement may only have one else statement ("else if" statements don't count). Having more than one pure "else" statement leads to unpredictable behavior, or usually, an error.

What you have in your code is an if statement with multiple "else" statements following it. In most programming languages this is not allowed and would result in an error. EM4, on the other hand, seems to have forgiven you for this and just executed all the else statements as if they were one giant code block.

So we need to fix that...later...because we have another problem on our hands...the way you are generating your random selection between the 4 sirens.

int random = Math::rand()%2;

This is self explanatory. You're generating a random number and assigning it to a variable. This is correct. What you may not realize is that you are only generating 2 possible random numbers: 0 or 1.

Math::rand() is a built in function that will generate a random number between 0 and some very large number. In your case, you only need to pick between 4 different numbers (1 number for each siren option). To do that we use math. The "%" is a mathematical operator called modulus. It gives you the remainder of a division. 

Division
int a = 9 / 3; //This equals 3. ( 9 divided by 3 equals 3 )
int b = 10 / 3; //This actually equals 3. The decimal is dropped since its being assigned to an integer variable (which only stores whole numbers). 3 goes into 10 3 times with a remainder.

Modulus
int a = 9 % 3; //This equals 0, since 3 divides into 9 evenly and thus has no remainder.
int b = 10 % 3; //This equals 2 since 3 goes into 10 3 times, but has a remainder of 2.

Back to your problem:

int random = Math::random() % 2;
random will equal the remainder of whatever random number is generated divided by 2. This means that your options will only ever be 1 (if an odd number) or 0 (if an even number).
You need to change this. Instead, you want to randomly select between 4 options so lets change it to:

 int random = Math::random() % 4;

Now, no matter what number is generated, you'll only have 4 possible options: 0 (if the number is evenly divisible by 4), 1, 2, 3.

Now that we have the script picking a siren sound, we need to fix our broken if-else statement so the proper one plays.

Back to the if-else

So we have a random number selected (0, 1, 2, or 3) and we want to play a different siren for each selection. Lets update our if-else statement to be correct:

int random = Math::rand() % 4;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else if (random == 1)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else if(random == 2)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren07.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren08.wav", CarPos, true);
              }

- The first "if" statement asks: Is my random number 0? If so, play siren01. Otherwise, proceed to the "else" statement.
- The first "else" says: Ok, the random number wasn't 0. Is the random number 1? If so, play siren02. If not, proceed to the next "else" statement.
- The second "else" says: Fine, is the random number a 2? If so, play siren07. If not, proceed down to the next "else".
- The third "else" doesn't ask a question (no "if" statement). It just says: I don't care what the value of the random number is. It's not what the above statements were looking for so I'll just play siren08.
In this case, if the random number was 3, it would execute the final "else" statement since it is not 0, 1, or 2 which are being looked for in the preceding "if" and "else-if" statements.

So after all that, it should make a proper selection. Try this and fix your script, then report back what else needs fixing.

This was long winded! I apologize! I want to help you and others learn the basics of scripting. It is NOT an easy skill to learn or develop without some sort of programming background. I admire your effort to do something yourself instead of just asking for help making something without actually putting in the effort to figure it out. Scripting is probably among the rarest skills in the community, and perhaps one of the most sorely needed, so anything I can do to help develop a new scripter is a good thing IMO.

  • Like 2
  • Upvote 1
Link to comment
Share on other sites

Keep your questions public, if you can.

1. In order help anyone else that might be having similar  issues, and so that others may learn from these problems as well.

2. So that others can help you and you’re not just waiting on me.

Link to comment
Share on other sites

@Chris07 I am having a problem with the same script and also the exact same problem with another script.

Error:

Spoiler

?(_RiversideSirenb0228c): Limitation: Statement too long
?(_RiversideSirenb0228c):  FILE:mod:/scripts/game/command/RiversideSiren.scriptb0228c LINE:138
?(_RiversideSirenb0228c): cint: Security mode 0x7:0x2 
?(_RiversideSirenb0228c): !!!Fatal error. Sorry, terminate cint session!!!

 

Script:

Spoiler


const char CMD_AUTOSIREN_OFF[]        = "VcmdAutoSirenOff";
const char EACTION_FINDPATH[]         = "EActionFindPath";
const char EACTION_EXTINGUISH[]     = "EActionExtinguish";
const char DUMMY_HASSIREN[]         = "DummyHasSiren";
const char DUMMY_UPDATEPOS[]         = "DummyUpdatePos";
const char DUMMY_FINDPATH[]         = "DummyFindPath";
const char DUMMY_HOSESON[]         = "DummyHosesAreOn";
const char NAME_DUMMYOBJECT[]         = "HelpingObjekt_Hoppah";
const char DUMMY_GETTIL[]         = "DummyGetTiller";
const char DUMMY_LIGHTS_ENABLE[]    = "DummyEnableLights";
const char DUMMY_LIGHTS_DISABLE[]    = "DummyDisableLights";
const char DUMMY_HASLIGHTS[]        = "DummyHasLights";

const char PROTO_ENGINE1[]       = "mod:Prototypes/Vehicles/02 LA Fire Department/Engine 1.e4p";
const char PROTO_ENGINE2[]       = "mod:Prototypes/Vehicles/02 LA Fire Department/Engine 2.e4p";
const char PROTO_TANKER1[]      = "mod:Prototypes/Vehicles/02 LA Fire Department/Tanker 1.e4p";
const char PROTO_TANKER2[]      = "mod:Prototypes/Vehicles/02 LA Fire Department/Tanker 2.e4p";
const char PROTO_LADDER1[]       = "mod:Prototypes/Vehicles/02 LA Fire Department/Ladder 1.e4p";
const char PROTO_HAZMAT1[]      = "mod:Prototypes/Vehicles/02 LA Fire Department/HazMat 1.e4p";
const char PROTO_BATT1[]          = "mod:Prototypes/Vehicles/02 LA Fire Department/Battalion 1.e4p";

const char PROTO_MEDIC1[]       = "mod:Prototypes/Vehicles/01 LA Ambulance/Medic 1.e4p";
const char PROTO_MEDIC2[]        = "mod:Prototypes/Vehicles/01 LA Ambulance/Medic 2.e4p";
const char PROTO_MEDIC3[]        = "mod:Prototypes/Vehicles/01 LA Ambulance/Medic 3.e4p";

const char PROTO_MARY1[]       = "mod:Prototypes/Vehicles/03 LA Police/Mary 1.e4p";

const char PROTO_BRUSH9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Brush 9.e4p";
const char PROTO_CHIEF4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 4.e4p";
const char PROTO_CHIEF5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 5.e4p";
const char PROTO_CHIEF6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 6.e4p";
const char PROTO_CHIEF7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 7.e4p";
const char PROTO_CHIEF8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 8.e4p";
const char PROTO_CHIEF9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 9.e4p";
const char PROTO_ENGINE4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 4.e4p";
const char PROTO_ENGINE5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 5.e4p";
const char PROTO_ENGINE51[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 5_1.e4p";
const char PROTO_ENGINE6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 6.e4p";
const char PROTO_ENGINE7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 7.e4p";
const char PROTO_ENGINE71[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 7_1.e4p";
const char PROTO_ENGINE8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 8.e4p";
const char PROTO_ENGINE9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 9.e4p";
const char PROTO_QUINT4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Quint 4.e4p";
const char PROTO_TRUCK5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Truck 5.e4p";
const char PROTO_TRUCK7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Truck 7.e4p";
const char PROTO_TRUCK8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Truck 8.e4p";
const char PROTO_RESCUE4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Rescue 4.e4p";
const char PROTO_RESCUE5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Rescue 5.e4p";
const char PROTO_RESCUE6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Rescue 6.e4p";
const char PROTO_SPECOPS6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Special Operations 6.e4p";
const char PROTO_TANKER4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 4.e4p";
const char PROTO_TANKER5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 5.e4p";
const char PROTO_TANKER51[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 5_1.e4p";
const char PROTO_TANKER6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 6.e4p";
const char PROTO_TANKER7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 7.e4p";
const char PROTO_TANKER8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 8.e4p";
const char PROTO_TANKER9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 9.e4p";
const char PROTO_UTILITY51[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Utility 5_1.e4p";


int DummyGroup = 23;

object VcmdSiren : CommandScript
{
    VcmdSiren()
    {
        SetIcon("sirenson");
        SetCursor("sirens");
        SetRestrictions(RESTRICT_SELFEXECUTE);
        SetPossibleCallers(ACTOR_VEHICLE);
         SetGroupID(DummyGroup);
         SetGroupLeader(true);
    }

    bool CheckPossible(GameObject *Caller)
    {
        if (!Caller->IsValid())
            return false;

        if (Caller->HasCommand(DUMMY_HASSIREN))
            SetIcon("sirensoff");
        else
            SetIcon("sirenson");

        if(Caller->HasCommand(DUMMY_HOSESON))
            return false;    

        return true;
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
        if (!Target->IsValid() || Target->GetID() != Caller->GetID())
            return false;

        return true;
    }

    void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Caller);
        if (!v.HasCommand(DUMMY_HASSIREN))
        {
            if (!v.HasCommand(DUMMY_HASLIGHTS))
            {
                Game::ExecuteCommand(DUMMY_LIGHTS_ENABLE, &v, &v);
            }


            int soundID;
            Vector CarPos = v.GetPosition();
             if (StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE1) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE2) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_TANKER1) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_TANKER2) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_LADDER1) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_HAZMAT1) == 0)        
            {
                int random = Math::rand()%3;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren10.wav", CarPos, true);
                }
             }
            else if (StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE4) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE5) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE51) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE6) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE7) == 0 ||    
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE71) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE8) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE9) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_QUINT4) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_TRUCK5) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TRUCK7) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TRUCK8) == 0 ||    
             StrCompare(v.GetPrototypeFileName(), PROTO_SPECOPS6) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_RESCUE4) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_RESCUE5) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_RESCUE6) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER4) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER5) == 0 ||                 
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER51) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER6) == 0 ||                
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER7) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER8) == 0 ||                
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER9) == 0)            
            {
                int random = Math::rand()%3;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren10.wav", CarPos, true);
                }
            }
             else if (StrCompare(v.GetPrototypeFileName(), PROTO_MEDIC1) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_MEDIC2) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_MEDIC3) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_BRUSH9) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF4) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF5) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF6) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF7) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF8) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF9) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_UTILITY51) == 0)
            {
                int random = Math::rand()%2;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren03.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren04.wav", CarPos, true);
                }
             }
             else if (StrCompare(v.GetPrototypeFileName(), PROTO_MARY1) == 0)
             {
                int random = Math::rand()%2;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren05.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren06.wav", CarPos, true);
                }
            }
            int CarID = v.GetID();
            GameObject mDummy =  Game::CreateObject("mod:Prototypes/Objects/Misc/empty.e4p", NAME_DUMMYOBJECT);
            v.AssignCommand(DUMMY_HASSIREN);
            v.SetUserData(soundID);
            mDummy.Hide();
            //mDummy.SetUserData(v.GetID());
            mDummy.SetUserData(soundID);
            mDummy.AttachSound(soundID);
            mDummy.PushActionExecuteCommand(ACTION_NEWLIST, DUMMY_UPDATEPOS, &v, 0, false);
            return;
        }

        if (v.HasCommand(DUMMY_HASSIREN))
        {
            System::Log("Stop sample via VcmdSiren");
            if (childID == 1)
            {
                Game::ExecuteCommand(DUMMY_LIGHTS_DISABLE, &v, &v);
            }
            int CarID = v.GetUserData();
            int ref = v.GetUserData();
            v.UnattachSound(ref);
            Audio::StopSample(ref);
            int mSirTest;
            GameObjectList list = Game::GetGameObjects(NAME_DUMMYOBJECT);
            for(int i=0; i<list.GetNumObjects(); i++)
            {
                GameObject *obj = list.GetObject(i);
                if (obj->GetUserData() == CarID)
                {
                    mSirTest = i;
                }
            }

            GameObject *obj = list.GetObject(mSirTest);
            obj->PushActionDeleteOwner(ACTION_NEWLIST);

            if (v.HasCommand(DUMMY_HASSIREN))
                v.RemoveCommand(DUMMY_HASSIREN);

            return;
        }
    }
};

object DummyUpdatePos : CommandScript
{
    DummyUpdatePos()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Target);
        GameObject mDummy(Caller);

        if (v.IsDestroyed() || !v.IsValid())
        {
            int ref = mDummy.GetUserData();
            mDummy.UnattachSound(ref);
            Audio::StopSample(ref);

            if (v.HasCommand(DUMMY_HASSIREN))
                v.RemoveCommand(DUMMY_HASSIREN);

            mDummy.PushActionDeleteOwner(ACTION_NEWLIST);
        } else
          {
            if (v.IsCurrentAction(EACTION_FINDPATH))
            {
                if (!v.HasCommand(DUMMY_FINDPATH))
                {
                    v.AssignCommand(DUMMY_FINDPATH);
                }
            }
            Vector vPos = v.GetPosition();
            mDummy.SetPosition(vPos);
            mDummy.PushActionExecuteCommand(ACTION_NEWLIST, DUMMY_UPDATEPOS, Target, childID, false);
          }

        if (v.HasCommand(DUMMY_FINDPATH))
        {
            if (!v.IsCurrentAction(EACTION_FINDPATH) && v.HasCommand(CMD_AUTOSIREN_OFF) && (v.GetNumActions() == 0 || v.IsCurrentAction(EACTION_EXTINGUISH)))
            {
                if (v.HasCommand(DUMMY_HASSIREN))
                    v.RemoveCommand(DUMMY_HASSIREN);

                if (v.HasCommand(DUMMY_FINDPATH))
                    v.RemoveCommand(DUMMY_FINDPATH);

                int CarID = v.GetUserData();
                int ref = v.GetUserData();
                v.UnattachSound(ref);
                Audio::StopSample(ref);

                GameObjectList list = Game::GetGameObjects(NAME_DUMMYOBJECT);
                for(int i = 0; i < list.GetNumObjects(); i++)
                {
                    int mSirTest;
                    GameObject *obj = list.GetObject(i);
                    if (obj->GetUserData() == CarID)
                    {
                        mSirTest = i;
                        GameObject *obj = list.GetObject(mSirTest);
                        obj->PushActionDeleteOwner(ACTION_NEWLIST);
                        if (v.HasCommand(DUMMY_HASSIREN))
                            v.RemoveCommand(DUMMY_HASSIREN);
                        if (v.HasCommand(DUMMY_FINDPATH))
                            v.RemoveCommand(DUMMY_FINDPATH);
                    }
                }
            }
        }
    }
};

object DummyDisableSiren : CommandScript
{
    DummyDisableSiren()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Caller);
        if (childID == 1)
        {
            v.EnableBlueLights(false);
        }

        //int CarID = v.GetID();
        int CarID = v.GetUserData();
        int ref = v.GetUserData();
        v.UnattachSound(ref);
        Audio::StopSample(ref);

        GameObjectList list = Game::GetGameObjects(NAME_DUMMYOBJECT);
        for(int i = 0; i < list.GetNumObjects(); i++)
        {
            GameObject *obj = list.GetObject(i);
            if (obj->GetUserData() == CarID)
            {
                int mSirTest = i;

                GameObject *obj = list.GetObject(mSirTest);
                obj->PushActionDeleteOwner(ACTION_NEWLIST);

                if (v.HasCommand(DUMMY_HASSIREN))
                    v.RemoveCommand(DUMMY_HASSIREN);
                if (v.HasCommand(DUMMY_FINDPATH))
                    v.RemoveCommand(DUMMY_FINDPATH);
                if (v.HasCommand(DUMMY_GETTIL))
                    v.SetUserData(v.GetID());
            }
        }
    }
};

object DummyFindPath : CommandScript
{
    DummyFindPath()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
        return false;
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
    }
};

object DummyHasSiren : CommandScript
{
    DummyHasSiren()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
        return false;
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
    }
};
 

 

Link to comment
Share on other sites

2 hours ago, TTBL225 said:

@Chris07 I am having a problem with the same script and also the exact same problem with another script.

Error:

  Reveal hidden contents

?(_RiversideSirenb0228c): Limitation: Statement too long
?(_RiversideSirenb0228c):  FILE:mod:/scripts/game/command/RiversideSiren.scriptb0228c LINE:138
?(_RiversideSirenb0228c): cint: Security mode 0x7:0x2 
?(_RiversideSirenb0228c): !!!Fatal error. Sorry, terminate cint session!!!

 

Script:

  Reveal hidden contents


const char CMD_AUTOSIREN_OFF[]        = "VcmdAutoSirenOff";
const char EACTION_FINDPATH[]         = "EActionFindPath";
const char EACTION_EXTINGUISH[]     = "EActionExtinguish";
const char DUMMY_HASSIREN[]         = "DummyHasSiren";
const char DUMMY_UPDATEPOS[]         = "DummyUpdatePos";
const char DUMMY_FINDPATH[]         = "DummyFindPath";
const char DUMMY_HOSESON[]         = "DummyHosesAreOn";
const char NAME_DUMMYOBJECT[]         = "HelpingObjekt_Hoppah";
const char DUMMY_GETTIL[]         = "DummyGetTiller";
const char DUMMY_LIGHTS_ENABLE[]    = "DummyEnableLights";
const char DUMMY_LIGHTS_DISABLE[]    = "DummyDisableLights";
const char DUMMY_HASLIGHTS[]        = "DummyHasLights";

const char PROTO_ENGINE1[]       = "mod:Prototypes/Vehicles/02 LA Fire Department/Engine 1.e4p";
const char PROTO_ENGINE2[]       = "mod:Prototypes/Vehicles/02 LA Fire Department/Engine 2.e4p";
const char PROTO_TANKER1[]      = "mod:Prototypes/Vehicles/02 LA Fire Department/Tanker 1.e4p";
const char PROTO_TANKER2[]      = "mod:Prototypes/Vehicles/02 LA Fire Department/Tanker 2.e4p";
const char PROTO_LADDER1[]       = "mod:Prototypes/Vehicles/02 LA Fire Department/Ladder 1.e4p";
const char PROTO_HAZMAT1[]      = "mod:Prototypes/Vehicles/02 LA Fire Department/HazMat 1.e4p";
const char PROTO_BATT1[]          = "mod:Prototypes/Vehicles/02 LA Fire Department/Battalion 1.e4p";

const char PROTO_MEDIC1[]       = "mod:Prototypes/Vehicles/01 LA Ambulance/Medic 1.e4p";
const char PROTO_MEDIC2[]        = "mod:Prototypes/Vehicles/01 LA Ambulance/Medic 2.e4p";
const char PROTO_MEDIC3[]        = "mod:Prototypes/Vehicles/01 LA Ambulance/Medic 3.e4p";

const char PROTO_MARY1[]       = "mod:Prototypes/Vehicles/03 LA Police/Mary 1.e4p";

const char PROTO_BRUSH9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Brush 9.e4p";
const char PROTO_CHIEF4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 4.e4p";
const char PROTO_CHIEF5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 5.e4p";
const char PROTO_CHIEF6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 6.e4p";
const char PROTO_CHIEF7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 7.e4p";
const char PROTO_CHIEF8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 8.e4p";
const char PROTO_CHIEF9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Chief 9.e4p";
const char PROTO_ENGINE4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 4.e4p";
const char PROTO_ENGINE5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 5.e4p";
const char PROTO_ENGINE51[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 5_1.e4p";
const char PROTO_ENGINE6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 6.e4p";
const char PROTO_ENGINE7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 7.e4p";
const char PROTO_ENGINE71[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 7_1.e4p";
const char PROTO_ENGINE8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 8.e4p";
const char PROTO_ENGINE9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Engine 9.e4p";
const char PROTO_QUINT4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Quint 4.e4p";
const char PROTO_TRUCK5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Truck 5.e4p";
const char PROTO_TRUCK7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Truck 7.e4p";
const char PROTO_TRUCK8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Truck 8.e4p";
const char PROTO_RESCUE4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Rescue 4.e4p";
const char PROTO_RESCUE5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Rescue 5.e4p";
const char PROTO_RESCUE6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Rescue 6.e4p";
const char PROTO_SPECOPS6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Special Operations 6.e4p";
const char PROTO_TANKER4[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 4.e4p";
const char PROTO_TANKER5[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 5.e4p";
const char PROTO_TANKER51[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 5_1.e4p";
const char PROTO_TANKER6[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 6.e4p";
const char PROTO_TANKER7[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 7.e4p";
const char PROTO_TANKER8[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 8.e4p";
const char PROTO_TANKER9[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Tanker 9.e4p";
const char PROTO_UTILITY51[]       = "mod:Prototypes/Vehicles/02 Mutual Aid Fire/Utility 5_1.e4p";


int DummyGroup = 23;

object VcmdSiren : CommandScript
{
    VcmdSiren()
    {
        SetIcon("sirenson");
        SetCursor("sirens");
        SetRestrictions(RESTRICT_SELFEXECUTE);
        SetPossibleCallers(ACTOR_VEHICLE);
         SetGroupID(DummyGroup);
         SetGroupLeader(true);
    }

    bool CheckPossible(GameObject *Caller)
    {
        if (!Caller->IsValid())
            return false;

        if (Caller->HasCommand(DUMMY_HASSIREN))
            SetIcon("sirensoff");
        else
            SetIcon("sirenson");

        if(Caller->HasCommand(DUMMY_HOSESON))
            return false;    

        return true;
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
        if (!Target->IsValid() || Target->GetID() != Caller->GetID())
            return false;

        return true;
    }

    void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Caller);
        if (!v.HasCommand(DUMMY_HASSIREN))
        {
            if (!v.HasCommand(DUMMY_HASLIGHTS))
            {
                Game::ExecuteCommand(DUMMY_LIGHTS_ENABLE, &v, &v);
            }


            int soundID;
            Vector CarPos = v.GetPosition();
             if (StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE1) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE2) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_TANKER1) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_TANKER2) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_LADDER1) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_HAZMAT1) == 0)        
            {
                int random = Math::rand()%3;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren10.wav", CarPos, true);
                }
             }
            else if (StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE4) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE5) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE51) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE6) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE7) == 0 ||    
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE71) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE8) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_ENGINE9) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_QUINT4) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_TRUCK5) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TRUCK7) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TRUCK8) == 0 ||    
             StrCompare(v.GetPrototypeFileName(), PROTO_SPECOPS6) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_RESCUE4) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_RESCUE5) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_RESCUE6) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER4) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER5) == 0 ||                 
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER51) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER6) == 0 ||                
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER7) == 0 ||    
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER8) == 0 ||                
            StrCompare(v.GetPrototypeFileName(), PROTO_TANKER9) == 0)            
            {
                int random = Math::rand()%3;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren01.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren02.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren10.wav", CarPos, true);
                }
            }
             else if (StrCompare(v.GetPrototypeFileName(), PROTO_MEDIC1) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_MEDIC2) == 0 ||
             StrCompare(v.GetPrototypeFileName(), PROTO_MEDIC3) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_BRUSH9) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF4) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF5) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF6) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF7) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF8) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_CHIEF9) == 0 ||
            StrCompare(v.GetPrototypeFileName(), PROTO_UTILITY51) == 0)
            {
                int random = Math::rand()%2;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren03.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren04.wav", CarPos, true);
                }
             }
             else if (StrCompare(v.GetPrototypeFileName(), PROTO_MARY1) == 0)
             {
                int random = Math::rand()%2;
                if (random == 0)
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren05.wav", CarPos, true);
                } else
                {
                      soundID = Audio::PlaySample3D("mod:Audio/FX/Sirens/Siren06.wav", CarPos, true);
                }
            }
            int CarID = v.GetID();
            GameObject mDummy =  Game::CreateObject("mod:Prototypes/Objects/Misc/empty.e4p", NAME_DUMMYOBJECT);
            v.AssignCommand(DUMMY_HASSIREN);
            v.SetUserData(soundID);
            mDummy.Hide();
            //mDummy.SetUserData(v.GetID());
            mDummy.SetUserData(soundID);
            mDummy.AttachSound(soundID);
            mDummy.PushActionExecuteCommand(ACTION_NEWLIST, DUMMY_UPDATEPOS, &v, 0, false);
            return;
        }

        if (v.HasCommand(DUMMY_HASSIREN))
        {
            System::Log("Stop sample via VcmdSiren");
            if (childID == 1)
            {
                Game::ExecuteCommand(DUMMY_LIGHTS_DISABLE, &v, &v);
            }
            int CarID = v.GetUserData();
            int ref = v.GetUserData();
            v.UnattachSound(ref);
            Audio::StopSample(ref);
            int mSirTest;
            GameObjectList list = Game::GetGameObjects(NAME_DUMMYOBJECT);
            for(int i=0; i<list.GetNumObjects(); i++)
            {
                GameObject *obj = list.GetObject(i);
                if (obj->GetUserData() == CarID)
                {
                    mSirTest = i;
                }
            }

            GameObject *obj = list.GetObject(mSirTest);
            obj->PushActionDeleteOwner(ACTION_NEWLIST);

            if (v.HasCommand(DUMMY_HASSIREN))
                v.RemoveCommand(DUMMY_HASSIREN);

            return;
        }
    }
};

object DummyUpdatePos : CommandScript
{
    DummyUpdatePos()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Target);
        GameObject mDummy(Caller);

        if (v.IsDestroyed() || !v.IsValid())
        {
            int ref = mDummy.GetUserData();
            mDummy.UnattachSound(ref);
            Audio::StopSample(ref);

            if (v.HasCommand(DUMMY_HASSIREN))
                v.RemoveCommand(DUMMY_HASSIREN);

            mDummy.PushActionDeleteOwner(ACTION_NEWLIST);
        } else
          {
            if (v.IsCurrentAction(EACTION_FINDPATH))
            {
                if (!v.HasCommand(DUMMY_FINDPATH))
                {
                    v.AssignCommand(DUMMY_FINDPATH);
                }
            }
            Vector vPos = v.GetPosition();
            mDummy.SetPosition(vPos);
            mDummy.PushActionExecuteCommand(ACTION_NEWLIST, DUMMY_UPDATEPOS, Target, childID, false);
          }

        if (v.HasCommand(DUMMY_FINDPATH))
        {
            if (!v.IsCurrentAction(EACTION_FINDPATH) && v.HasCommand(CMD_AUTOSIREN_OFF) && (v.GetNumActions() == 0 || v.IsCurrentAction(EACTION_EXTINGUISH)))
            {
                if (v.HasCommand(DUMMY_HASSIREN))
                    v.RemoveCommand(DUMMY_HASSIREN);

                if (v.HasCommand(DUMMY_FINDPATH))
                    v.RemoveCommand(DUMMY_FINDPATH);

                int CarID = v.GetUserData();
                int ref = v.GetUserData();
                v.UnattachSound(ref);
                Audio::StopSample(ref);

                GameObjectList list = Game::GetGameObjects(NAME_DUMMYOBJECT);
                for(int i = 0; i < list.GetNumObjects(); i++)
                {
                    int mSirTest;
                    GameObject *obj = list.GetObject(i);
                    if (obj->GetUserData() == CarID)
                    {
                        mSirTest = i;
                        GameObject *obj = list.GetObject(mSirTest);
                        obj->PushActionDeleteOwner(ACTION_NEWLIST);
                        if (v.HasCommand(DUMMY_HASSIREN))
                            v.RemoveCommand(DUMMY_HASSIREN);
                        if (v.HasCommand(DUMMY_FINDPATH))
                            v.RemoveCommand(DUMMY_FINDPATH);
                    }
                }
            }
        }
    }
};

object DummyDisableSiren : CommandScript
{
    DummyDisableSiren()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Caller);
        if (childID == 1)
        {
            v.EnableBlueLights(false);
        }

        //int CarID = v.GetID();
        int CarID = v.GetUserData();
        int ref = v.GetUserData();
        v.UnattachSound(ref);
        Audio::StopSample(ref);

        GameObjectList list = Game::GetGameObjects(NAME_DUMMYOBJECT);
        for(int i = 0; i < list.GetNumObjects(); i++)
        {
            GameObject *obj = list.GetObject(i);
            if (obj->GetUserData() == CarID)
            {
                int mSirTest = i;

                GameObject *obj = list.GetObject(mSirTest);
                obj->PushActionDeleteOwner(ACTION_NEWLIST);

                if (v.HasCommand(DUMMY_HASSIREN))
                    v.RemoveCommand(DUMMY_HASSIREN);
                if (v.HasCommand(DUMMY_FINDPATH))
                    v.RemoveCommand(DUMMY_FINDPATH);
                if (v.HasCommand(DUMMY_GETTIL))
                    v.SetUserData(v.GetID());
            }
        }
    }
};

object DummyFindPath : CommandScript
{
    DummyFindPath()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
        return false;
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
    }
};

object DummyHasSiren : CommandScript
{
    DummyHasSiren()
    {
        SetGroupID(DummyGroup);
    }

    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    {
        return false;
    }

      void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
    }
};
 

 

Disregard. I was able to solve after finding this thread.

 

 

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.



×
×
  • Create New...