Example #1
0
        /// <summary>
        /// Hook vehicle events.
        /// </summary>
        void HookEvents()
        {
            // Engine states
            string[] ignitionStateNames = { "Wait button", "Motor starting", "Motor OFF", "Test", "Shut off", "ACC on", "ACC on 2" };

            foreach (string name in ignitionStateNames)
            {
                EventHook.AddWithSync(ignitionFsm, name);
            }


            // Dashboard states
            string[] dashboardStateNames = { "ACC on", "Test", "ACC on 2", "Motor starting", "Shut off", "Motor OFF", "Wait button", "Wait player" };

            foreach (string name in dashboardStateNames)
            {
                EventHook.Add(dashboardFsm, name, new Func <bool>(() => {
                    return(false);
                }));
            }

            // Vehicle switches

            // Range
            if (hasRange)
            {
                if (isTruck)
                {
                    EventHook.AddWithSync(rangeFsm, "Switch");
                }
                else if (isTractor)
                {
                    EventHook.AddWithSync(rangeFsm, "Flip");
                }
            }

            // Push parking brake
            if (hasPushParkingBrake)
            {
                EventHook.Add(handbrakeFsm, "DECREASE", new Func <bool>(() => {
                    Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.HandbrakePull, false, this.handbrakeFsm.Fsm.GetFsmFloat("KnobPos").Value);
                    return(false);
                }), actionOnExit: true);
                EventHook.Add(handbrakeFsm, "INCREASE", new Func <bool>(() => {
                    Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.HandbrakePull, false, this.handbrakeFsm.Fsm.GetFsmFloat("KnobPos").Value);
                    return(false);
                }), actionOnExit: true);
            }

            // Truck parking brake
            if (hasLeverParkingBrake)
            {
                EventHook.Add(handbrakeFsm, "Flip", new Func <bool>(() => {
                    Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.HandbrakeLever, !this.handbrakeFsm.Fsm.GetFsmBool("Brake").Value, -1);
                    return(false);
                }));
            }

            // Fuel tap
            if (fuelTapFsm != null)
            {
                EventHook.Add(fuelTapFsm, "Test", new Func <bool>(() => {
                    Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.FuelTap, !this.fuelTapFsm.Fsm.GetFsmBool("FuelOn").Value, -1);
                    return(false);
                }));
            }

            // Lights
            if (lightsFsm != null)
            {
                EventHook.AddWithSync(lightsFsm, "Off");
                EventHook.AddWithSync(lightsFsm, "Shorts");
                EventHook.AddWithSync(lightsFsm, "Longs");
            }

            // Indicators
            if (indicatorsFsm != null)
            {
                EventHook.AddWithSync(indicatorsFsm, "Activate dash");
                EventHook.AddWithSync(indicatorsFsm, "Activate dash 2");
                EventHook.AddWithSync(indicatorsFsm, "On", action: new Func <bool>(() => {
                    if (this.DriverIsLocal == false)
                    {
                        return(true);
                    }
                    return(false);
                }));
                EventHook.AddWithSync(indicatorsFsm, "On 2", action: new Func <bool>(() => {
                    if (this.DriverIsLocal == false)
                    {
                        return(true);
                    }
                    return(false);
                }));
                EventHook.AddWithSync(indicatorsFsm, "Off", action: new Func <bool>(() => {
                    if (this.DriverIsLocal == false)
                    {
                        return(true);
                    }
                    return(false);
                }));
                EventHook.AddWithSync(indicatorsFsm, "Off 2", action: new Func <bool>(() => {
                    if (this.DriverIsLocal == false)
                    {
                        return(true);
                    }
                    return(false);
                }));

                EventHook.AddWithSync(indicatorsFsm, "State 3", action: new Func <bool>(() => {
                    if (this.DriverIsLocal == false)
                    {
                        Logger.Log("Turning off indicators!");
                        GameObject left;
                        GameObject right;
                        left  = this.gameObject.transform.FindChild("LOD/Electricity/PowerON/Blinkers/Left").gameObject;
                        right = this.gameObject.transform.FindChild("LOD/Electricity/PowerON/Blinkers/Right").gameObject;
                        // Ferndale has a different hierarchy. Why not, right?
                        if (left == null)
                        {
                            left  = this.gameObject.transform.FindChild("LOD/Electricity 1/PowerON/Blinkers/Left").gameObject;
                            right = this.gameObject.transform.FindChild("LOD/Electricity 1/PowerON/Blinkers/Right").gameObject;
                        }
                        left.SetActive(false);
                        right.SetActive(false);
                        if (left == null)
                        {
                            Logger.Log("Left indicator not found!");
                        }
                    }
                    return(false);
                }));
            }

            // Wipers
            if (wipersFsm != null)
            {
                EventHook.Add(wipersFsm, "Test 2", new Func <bool>(() => {
                    int selection = this.wipersFsm.Fsm.GetFsmInt("Selection").Value;
                    if (selection == 2)
                    {
                        selection = 0;
                    }
                    else
                    {
                        selection++;
                    }

                    Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.Wipers, false, selection);
                    return(false);
                }));
            }

            // Interior light
            if (lightsFsm != null)
            {
                if (isTruck)
                {
                    EventHook.Add(interiorLightFsm, "Switch", new Func <bool>(() => {
                        Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.InteriorLight, !this.interiorLightFsm.Fsm.GetFsmBool("On").Value, -1);
                        return(false);
                    }));
                }
                else
                {
                    EventHook.Add(interiorLightFsm, "Flip 2", new Func <bool>(() => {
                        Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.InteriorLight, !this.interiorLightFsm.Fsm.GetFsmBool("LightON").Value, -1);
                        return(false);
                    }));
                }
            }

            // Truck related events
            if (isTruck)
            {
                // Hydraulic pump
                EventHook.Add(hydraulicPumpFsm, "Test", new Func <bool>(() => {
                    if (this.hydraulicPumpFirstRun == false)
                    {
                        Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.HydraulicPump, !this.hydraulicPumpFsm.Fsm.GetFsmBool("On").Value, -1);
                    }
                    else
                    {
                        this.hydraulicPumpFirstRun = false;
                    }
                    return(false);
                }));

                // Spill valve
                EventHook.Add(spillValveFsm, "Switch", new Func <bool>(() => {
                    Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.SpillValve, !this.spillValveFsm.Fsm.GetFsmBool("Open").Value, -1);
                    return(false);
                }));

                // Axle lift
                EventHook.Add(axleLiftFsm, "Test", new Func <bool>(() => {
                    if (this.axleLiftFirstRun == false)
                    {
                        Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.AxleLift, !this.axleLiftFsm.Fsm.GetFsmBool("Up").Value, -1);
                    }
                    else
                    {
                        this.axleLiftFirstRun = false;
                    }
                    return(false);
                }));

                // Diff lock
                EventHook.Add(diffLockFsm, "Test", new Func <bool>(() => {
                    if (this.diffLockFirstRun == false)
                    {
                        Network.NetLocalPlayer.Instance.WriteVehicleSwitchMessage(syncComponent, SwitchIDs.DiffLock, !this.diffLockFsm.Fsm.GetFsmBool("Lock").Value, -1);
                    }
                    else
                    {
                        this.diffLockFirstRun = false;
                    }
                    return(false);
                }));

                // Beacon
                EventHook.AddWithSync(beaconFsm, "ON");
                EventHook.AddWithSync(beaconFsm, "OFF");
            }

            // Wasp nest
            if (waspNestFsm != null)
            {
                EventHook.AddWithSync(waspNestFsm, "State 2");
            }

            // Sync vehicle data with the host on spawn.
            if (Network.NetManager.Instance.IsOnline && !Network.NetManager.Instance.IsHost)
            {
                syncComponent.RequestObjectSync();
            }
        }
Example #2
0
        // Event hooks
        public void EventHooks()
        {
            // Generic vehicle FSMs.
            throttleFsm = Utils.GetPlaymakerScriptByName(parentGameObject, "Throttle");
            EventHook.SyncAllEvents(throttleFsm, new Func <bool>(() => {
                if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                {
                    return(true);
                }
                return(false);
            }));

            // Traffic FSMs.
            EventHook.AddWithSync(directionFsm, "CW", new Func <bool>(() => {
                isClockwise = 1;
                return(false);
            }));
            EventHook.AddWithSync(directionFsm, "CCW", new Func <bool>(() => {
                isClockwise = 0;
                return(false);
            }));

            // Bus specific FSMs.
            if (type == VehicleTypes.Bus)
            {
                PlayMakerFSM doorFsm  = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("Route").gameObject, "Door");
                PlayMakerFSM startFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("Route").gameObject, "Start");

                EventHook.SyncAllEvents(doorFsm, new Func <bool>(() => {
                    if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                    {
                        return(true);
                    }
                    return(false);
                }));

                EventHook.SyncAllEvents(startFsm, new Func <bool>(() => {
                    if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                    {
                        return(true);
                    }
                    return(false);
                }));
            }

            // None traffic cars specific FSMs.
            if (type == VehicleTypes.Amis || type == VehicleTypes.Fitan)
            {
                PlayMakerFSM crashFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("CrashEvent").gameObject, "Crash");

                EventHook.SyncAllEvents(crashFsm, new Func <bool>(() => {
                    if (syncComponent.Owner != steamID && syncComponent.Owner != 0 || syncComponent.Owner == 0 && !Network.NetManager.Instance.IsHost)
                    {
                        return(true);
                    }
                    return(false);
                }));
            }

            // Sync vehicle data with the host on spawn.
            if (Network.NetManager.Instance.IsOnline && !Network.NetManager.Instance.IsHost)
            {
                syncComponent.RequestObjectSync();
            }
        }