Jump to content
itchboy

Patrolling Vehicles Stoplight Fix

Recommended Posts

While doing work for Montana mod, I accidentally found the fix for patrolling units not obeying stoplights. Due to my current internet situation, I do not have a video demonstration.

The value that made this work is

v.SetTerrain(TERRAIN_TRAFFIC);

And to reset it back to normal:

v.SetTerrain(TERRAIN_CAR);

These values can be implemented to ANY mod.

Here is an example of the code implemented into the LA mod patrol script. This example will only work in an unedited copy of the LA mod. This example will not function with other mods or submods.

Spoiler

 


//******************************************************************************************
// #Version 1.3#
//
// 		Includes: Patrol command for police vehicles.
//
//	- VcmdPatrol
//	- VcmdPatrolAmbulance
//	- DummyPatrol
//
//		Script by Hoppah
//		
//		Usage of this script in other mods is NOT allowed without permission of Hoppah
//		Traffic light fix by itchyboy
//******************************************************************************************

const char CMD_SIREN[]				= "VcmdSiren";
const char CMD_AUTOSIREN_OFF[]		= "VcmdAutoSirenOff";
const char CMD_WARNINGLIGHTS_OFF[] 		= "VcmdWarningLightsOff";
const char CMD_WARNINGLIGHTS_ON[] 		= "VcmdWarningLightsOn";
const char CMD_FLOODLIGHTS_OFF[] 		= "VcmdFloodLightsOff";
const char CMD_FLOODLIGHTS_ON[] 		= "VcmdFloodLightsOn";
const char CMD_STANDBY_ON[]			= "VcmdStandbyOn";
const char CMD_STANDBY_OFF[]			= "VcmdStandbyOff";
const char CMD_PATROL[] 			= "VcmdPatrol";
const char DUMMY_PATROL[] 			= "DummyPatrol";
const char DUMMY_DISABLE[] 			= "DummyDisableSiren";
const char DUMMY_HASSIREN[] 			= "DummyHasSiren";
const char PATH_PATROL01[] 			= "patrolpath01";
const char PATH_PATROL02[] 			= "patrolpath02";
const char PATH_PATROL03[] 			= "patrolpath03";

int DummyGroup = 31;

object VcmdPatrol : CommandScript
{
	VcmdPatrol()
	{
		SetCursor("patrol");
		SetIcon("patrol");
		SetGroupID(DummyGroup);
 		SetGroupLeader(true);
		SetRestrictions(RESTRICT_SELFEXECUTE);
	}

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

		if (!Game::IsFreeplay() && !Game::IsMultiplayer())
			return false;

		return true;
	}

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

		return true;
	}

	void PushActions(GameObject *Caller, Actor *Target, int ChildID)
	{
		Vehicle v(Caller);
		if (v.HasCommand("DummyFollow"))
			v.RemoveCommand("DummyFollow");
		if (v.HasCommand(CMD_STANDBY_OFF))
		{
			v.RemoveCommand(CMD_STANDBY_OFF);
			v.AssignCommand(CMD_STANDBY_ON);
		}
		if (v.HasCommand(CMD_WARNINGLIGHTS_OFF))
		{
			v.EnableBlinker(BLT_NONE);
			v.RemoveCommand(CMD_WARNINGLIGHTS_OFF);
			v.AssignCommand(CMD_WARNINGLIGHTS_ON);
		} 
		if (v.HasCommand(CMD_FLOODLIGHTS_OFF))
		{
			v.EnableSpecialLights(false);
			v.RemoveCommand(CMD_FLOODLIGHTS_OFF);
			v.AssignCommand(CMD_FLOODLIGHTS_ON);
		}
		if (v.HasCommand(DUMMY_HASSIREN) && v.HasCommand(CMD_AUTOSIREN_OFF))
			Game::ExecuteCommand(DUMMY_DISABLE, &v, &v);
		v.EnableBlueLights(false);
		
		if (v.IsCollidingWithVirtualObject("patrol01")) //Fix for ambulances getting stuck at hospital on the new freeplay map
		{
			ActorList l1 = Game::GetActors("patrol02");
			if(l1.GetNumActors() > 0)
			{
				Vector Move = l1.GetActor(0)->GetPosition();
				v.PushActionMove(ACTION_NEWLIST, Move);
				v.PushActionExecuteCommand(ACTION_APPEND, CMD_PATROL, Caller, 0, false);
				return;
			}		
		}

		v.SetSpeed(6.4f);
		v.SetTerrain(TERRAIN_TRAFFIC);
		
		PathList p1l(PATH_PATROL01);
		Path path1 = p1l.GetPath(0);

		PathList p2l(PATH_PATROL02);
		Path path2 = p2l.GetPath(0);

		PathList p3l(PATH_PATROL03);
		Path path3 = p3l.GetPath(0);

		int index1 = path1.GetNearestPointIndex(v.GetPosition());
		Vector pt1 = path1.GetPoint(index1);

		int index2 = path2.GetNearestPointIndex(v.GetPosition());
		Vector pt2 = path2.GetPoint(index2);

		int index3 = path3.GetNearestPointIndex(v.GetPosition());
		Vector pt3 = path3.GetPoint(index3);

		int random = rand()%2;
		Vector target;
		if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y))
		{
			if (Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL03, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL03, 6.4f, false);
				target = pt3;
			} else
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL02, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL02, 6.4f, false);
				target = pt2;
			}
		} else
		{
			if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL03, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL03, 6.4f, false);
				target = pt3;
			} else
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL01, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL01, 6.4f, false);
				target = pt1;
			}
		}

		Path path = v.GetObjectPath();
		v.AssignCommand(DUMMY_PATROL);
		v.PushActionMove(ACTION_NEWLIST, target);
		v.PushActionUsePath(ACTION_APPEND, &path, true, 6.5f);
	}
};

object VcmdPatrolAmbulance : CommandScript
{
	VcmdPatrolAmbulance()
	{
		SetCursor("patrol");
		SetIcon("patrol2");
		SetGroupID(DummyGroup);
 		SetGroupLeader(true);
		SetRestrictions(RESTRICT_SELFEXECUTE);
	}

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

		if (!Game::IsFreeplay() && !Game::IsMultiplayer())
			return false;

		return true;
	}

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

		return true;
	}

	void PushActions(GameObject *Caller, Actor *Target, int ChildID)
	{
		Vehicle v(Caller);
		if (v.HasCommand(CMD_STANDBY_OFF))
		{
			v.RemoveCommand(CMD_STANDBY_OFF);
			v.AssignCommand(CMD_STANDBY_ON);
		}
		if (v.HasCommand(CMD_WARNINGLIGHTS_OFF))
		{
			v.EnableBlinker(BLT_NONE);
			v.RemoveCommand(CMD_WARNINGLIGHTS_OFF);
			v.AssignCommand(CMD_WARNINGLIGHTS_ON);
		} 
		if (v.HasCommand(CMD_FLOODLIGHTS_OFF))
		{
			v.EnableSpecialLights(false);
			v.RemoveCommand(CMD_FLOODLIGHTS_OFF);
			v.AssignCommand(CMD_FLOODLIGHTS_ON);
		}
		if (v.HasCommand(DUMMY_HASSIREN) && v.HasCommand(CMD_AUTOSIREN_OFF))
			Game::ExecuteCommand(DUMMY_DISABLE, &v, &v);
		v.EnableBlueLights(false);
		v.SetSpeed(6.4f);
		v.SetTerrain(TERRAIN_TRAFFIC);

		PathList p1l(PATH_PATROL01);
		Path path1 = p1l.GetPath(0);

		PathList p2l(PATH_PATROL02);
		Path path2 = p2l.GetPath(0);

		PathList p3l(PATH_PATROL03);
		Path path3 = p3l.GetPath(0);

		int index1 = path1.GetNearestPointIndex(v.GetPosition());
		Vector pt1 = path1.GetPoint(index1);

		int index2 = path2.GetNearestPointIndex(v.GetPosition());
		Vector pt2 = path2.GetPoint(index2);

		int index3 = path3.GetNearestPointIndex(v.GetPosition());
		Vector pt3 = path3.GetPoint(index3);

		int random = rand()%2;
		Vector target;
		if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y))
		{
			if (Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL03, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL03, 6.4f, false);
				target = pt3;
			} else
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL02, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL02, 6.4f, false);
				target = pt2;
			}
		} else
		{
			if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL03, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL03, 6.4f, false);
				target = pt3;
			} else
			{
				if (random == 0)
					v.SetObjectPath(PATH_PATROL01, 6.4f, true);
				else
					v.SetObjectPath(PATH_PATROL01, 6.4f, false);
				target = pt1;
			}
		}

		Path path = v.GetObjectPath();
		v.AssignCommand(DUMMY_PATROL);
		v.PushActionMove(ACTION_NEWLIST, target);
		v.PushActionUsePath(ACTION_APPEND, &path, true, 6.5f);
	}
};

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

 	bool CheckGroupVisibility(GameObject *Caller)
 	{
 		return false;
 	}

	void PushActions(GameObject *Caller, Actor *Target, int childID)
	{
		Vehicle v(Caller);
		v.RemoveObjectPath();
		if (v.HasCommand(DUMMY_PATROL))
			v.RemoveCommand(DUMMY_PATROL);
		v.SetTerrain(TERRAIN_CAR);
		if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_lapd.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_lapd_slicktop.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_lasd.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_umpc.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_chp.e4p") == 0)
		{
			v.SetSpeed(12.0f);
		}
		else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/01 LA Ambulance/cv_ems.e4p") == 0)
		{
			v.SetSpeed(12.0f);
		}
		else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/hummerh2_lasd.e4p") == 0)
		{
			v.SetTerrain(TERRAIN_OFFROAD);
			v.SetSpeed(10.0f);
		}
		else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_laap.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/cv_lapp.e4p") == 0)
		{
			v.SetSpeed(12.0f);
		}
		else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/suv_lapd.e4p") == 0)
		{
			v.SetTerrain(TERRAIN_OFFROAD);
			v.SetSpeed(12.0f);
		}
		else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/motorcycle_lapd.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/dodge_charger_lapd.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/dodge_charger_chp.e4p") == 0)
		{
			v.SetTerrain(TERRAIN_OFFROAD);
			v.SetSpeed(14.0f);
		}
		else if(v.GetVehicleType() == VT_AMBULANCE_RTW) 
		{
			v.SetSpeed(12.0f);
		} else
		{
			v.SetSpeed(12.0f);
			System::Log("Vehicle on patrol not identified!");
		}
	}	
};

 

 

 

 

  • Like 3
Link to comment
Share on other sites

6 hours ago, itchboy said:

Can I see the rest of the script?

Yep, here it go. I deleted those 3 lines this afternoon, but where in the exact same position as yours.

Spoiler

//******************************************************************************************
// #Version 1.3#
//
//         Includes: Patrol command for police vehicles.
//
//    - VcmdPatrol
//    - VcmdPatrolAmbulance
//    - DummyPatrol
//
//        Script by Hoppah
//        
//        Usage of this script in other mods is NOT allowed without permission of Hoppah
//
//******************************************************************************************

const char CMD_SIREN[]                = "VcmdSiren";
const char CMD_AUTOSIREN_OFF[]        = "VcmdAutoSirenOff";
const char CMD_WARNINGLIGHTS_OFF[]         = "VcmdWarningLightsOff";
const char CMD_WARNINGLIGHTS_ON[]         = "VcmdWarningLightsOn";
const char CMD_FLOODLIGHTS_OFF[]         = "VcmdFloodLightsOff";
const char CMD_FLOODLIGHTS_ON[]         = "VcmdFloodLightsOn";
const char CMD_STANDBY_ON[]            = "VcmdStandbyOn";
const char CMD_STANDBY_OFF[]            = "VcmdStandbyOff";
const char CMD_PATROL[]             = "VcmdPatrol";
const char DUMMY_PATROL[]             = "DummyPatrol";
const char DUMMY_DISABLE[]             = "DummyDisableSiren";
const char DUMMY_HASSIREN[]             = "DummyHasSiren";
const char PATH_PATROL01[]             = "patrolpath01";
const char PATH_PATROL02[]             = "patrolpath02";
const char PATH_PATROL03[]             = "patrolpath03";

int DummyGroup = 31;

object VcmdPatrol : CommandScript
{
    VcmdPatrol()
    {
        SetCursor("patrol");
        SetIcon("patrol");
        SetGroupID(DummyGroup);
         SetGroupLeader(true);
        SetRestrictions(RESTRICT_SELFEXECUTE);
    }

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

        if (!Game::IsFreeplay() && !Game::IsMultiplayer())
            return false;

        return true;
    }

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

        return true;
    }

    void PushActions(GameObject *Caller, Actor *Target, int ChildID)
    {
        Vehicle v(Caller);
        if (v.HasCommand("DummyFollow"))
            v.RemoveCommand("DummyFollow");
        if (v.HasCommand(CMD_STANDBY_OFF))
        {
            v.RemoveCommand(CMD_STANDBY_OFF);
            v.AssignCommand(CMD_STANDBY_ON);
        }
        if (v.HasCommand(CMD_WARNINGLIGHTS_OFF))
        {
            v.EnableBlinker(BLT_NONE);
            v.RemoveCommand(CMD_WARNINGLIGHTS_OFF);
            v.AssignCommand(CMD_WARNINGLIGHTS_ON);
        } 
        if (v.HasCommand(CMD_FLOODLIGHTS_OFF))
        {
            v.EnableSpecialLights(false);
            v.RemoveCommand(CMD_FLOODLIGHTS_OFF);
            v.AssignCommand(CMD_FLOODLIGHTS_ON);
        }
        if (v.HasCommand(DUMMY_HASSIREN) && v.HasCommand(CMD_AUTOSIREN_OFF))
            Game::ExecuteCommand(DUMMY_DISABLE, &v, &v);
        v.EnableBlueLights(false);
        
        if (v.IsCollidingWithVirtualObject("patrol01")) //Fix for ambulances getting stuck at hospital on the new freeplay map
        {
            ActorList l1 = Game::GetActors("patrol02");
            if(l1.GetNumActors() > 0)
            {
                Vector Move = l1.GetActor(0)->GetPosition();
                v.PushActionMove(ACTION_NEWLIST, Move);
                v.PushActionExecuteCommand(ACTION_APPEND, CMD_PATROL, Caller, 0, false);
                return;
            }        
        }

        v.SetSpeed(6.4f);
        
        PathList p1l(PATH_PATROL01);
        Path path1 = p1l.GetPath(0);

        PathList p2l(PATH_PATROL02);
        Path path2 = p2l.GetPath(0);

        PathList p3l(PATH_PATROL03);
        Path path3 = p3l.GetPath(0);

        int index1 = path1.GetNearestPointIndex(v.GetPosition());
        Vector pt1 = path1.GetPoint(index1);

        int index2 = path2.GetNearestPointIndex(v.GetPosition());
        Vector pt2 = path2.GetPoint(index2);

        int index3 = path3.GetNearestPointIndex(v.GetPosition());
        Vector pt3 = path3.GetPoint(index3);

        int random = rand()%2;
        Vector target;
        if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y))
        {
            if (Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL03, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL03, 6.4f, false);
                target = pt3;
            } else
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL02, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL02, 6.4f, false);
                target = pt2;
            }
        } else
        {
            if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL03, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL03, 6.4f, false);
                target = pt3;
            } else
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL01, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL01, 6.4f, false);
                target = pt1;
            }
        }

        Path path = v.GetObjectPath();
        v.AssignCommand(DUMMY_PATROL);
        v.PushActionMove(ACTION_NEWLIST, target);
        v.PushActionUsePath(ACTION_APPEND, &path, true, 6.5f);
    }
};

object VcmdPatrolAmbulance : CommandScript
{
    VcmdPatrolAmbulance()
    {
        SetCursor("patrol");
        SetIcon("patrol2");
        SetGroupID(DummyGroup);
         SetGroupLeader(true);
        SetRestrictions(RESTRICT_SELFEXECUTE);
    }

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

        if (!Game::IsFreeplay() && !Game::IsMultiplayer())
            return false;

        return true;
    }

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

        return true;
    }

    void PushActions(GameObject *Caller, Actor *Target, int ChildID)
    {
        Vehicle v(Caller);
        if (v.HasCommand(CMD_STANDBY_OFF))
        {
            v.RemoveCommand(CMD_STANDBY_OFF);
            v.AssignCommand(CMD_STANDBY_ON);
        }
        if (v.HasCommand(CMD_WARNINGLIGHTS_OFF))
        {
            v.EnableBlinker(BLT_NONE);
            v.RemoveCommand(CMD_WARNINGLIGHTS_OFF);
            v.AssignCommand(CMD_WARNINGLIGHTS_ON);
        } 
        if (v.HasCommand(CMD_FLOODLIGHTS_OFF))
        {
            v.EnableSpecialLights(false);
            v.RemoveCommand(CMD_FLOODLIGHTS_OFF);
            v.AssignCommand(CMD_FLOODLIGHTS_ON);
        }
        if (v.HasCommand(DUMMY_HASSIREN) && v.HasCommand(CMD_AUTOSIREN_OFF))
            Game::ExecuteCommand(DUMMY_DISABLE, &v, &v);
        v.EnableBlueLights(false);
        v.SetSpeed(6.4f);
        
        PathList p1l(PATH_PATROL01);
        Path path1 = p1l.GetPath(0);

        PathList p2l(PATH_PATROL02);
        Path path2 = p2l.GetPath(0);

        PathList p3l(PATH_PATROL03);
        Path path3 = p3l.GetPath(0);

        int index1 = path1.GetNearestPointIndex(v.GetPosition());
        Vector pt1 = path1.GetPoint(index1);

        int index2 = path2.GetNearestPointIndex(v.GetPosition());
        Vector pt2 = path2.GetPoint(index2);

        int index3 = path3.GetNearestPointIndex(v.GetPosition());
        Vector pt3 = path3.GetPoint(index3);

        int random = rand()%2;
        Vector target;
        if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y))
        {
            if (Math::dist(pt2.x, pt2.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL03, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL03, 6.4f, false);
                target = pt3;
            } else
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL02, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL02, 6.4f, false);
                target = pt2;
            }
        } else
        {
            if (Math::dist(pt1.x, pt1.y, v.GetPosition().x, v.GetPosition().y) > Math::dist(pt3.x, pt3.y, v.GetPosition().x, v.GetPosition().y))
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL03, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL03, 6.4f, false);
                target = pt3;
            } else
            {
                if (random == 0)
                    v.SetObjectPath(PATH_PATROL01, 6.4f, true);
                else
                    v.SetObjectPath(PATH_PATROL01, 6.4f, false);
                target = pt1;
            }
        }

        Path path = v.GetObjectPath();
        v.AssignCommand(DUMMY_PATROL);
        v.PushActionMove(ACTION_NEWLIST, target);
        v.PushActionUsePath(ACTION_APPEND, &path, true, 6.5f);
    }
};

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

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

    void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
        Vehicle v(Caller);
        v.RemoveObjectPath();
        if (v.HasCommand(DUMMY_PATROL))
            v.RemoveCommand(DUMMY_PATROL);
                if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/C-4_CNP2.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/C-4_CNP.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Picasso_V65.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/V64.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Picasso01.e4p") == 0)
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Altea_CNP.e4p") == 0)
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Scudo_CNP.e4p") == 0)
                         {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Police/Atestats.e4p") == 0)
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/4G8-CNP.e4p") == 0)
                          {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/MaxiZ_N66.e4p") == 0)
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Pathfinder PLG.e4p") == 0)
                         {
            v.SetSpeed(10.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Expert_UPR.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Xsara_CNP.e4p") == 0)
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Primastar-PLG.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/PLG-2.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/PLG-3.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/PLG-1.e4p") == 0)
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/swat_truck.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/Patrol_PLG.e4p") == 0 || StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/Police/SC07.e4p") == 0)
        {
            v.SetSpeed(14.0f);
        }
        else if(v.GetVehicleType() == VT_AMBULANCE_RTW) 
        {
            v.SetSpeed(12.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/camaro_chp.e4p") == 0)
        {
            v.SetSpeed(13.0f);
        }
        else if(StrCompare(v.GetPrototypeFileName(), "mod:Prototypes/Vehicles/03 LA Police/bpat_dodge_charger.e4p") == 0)
        {
            v.SetSpeed(14.0f);
        } else
        {
            v.SetSpeed(12.0f);
            System::Log("Vehicle on patrol not identified!");
        }
    }    
};

 

Link to comment
Share on other sites

14 hours ago, itchboy said:

Can I see what it looked like when you implemented it?

The error you showed me is unusual. I don't recognize the corrupted symbols after the "TERRAIN_TRAFFIC" line.

Well, now it's fixed. I edited the file with wordpad this time and no issues by now, patrol cars respect traffic lights.

Idk if is something related to Notepad++ or I should have copied the code direct from your spoiler the first time, but now it works.

Thank you anyways!

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