View difference between Paste ID: wjFS2CjU and YhRGnJE1
SHOW: | | - or go back to the newest paste.
1
using GTA;
2
using GTA.Math;
3
using GTA.Native;
4
using System;
5-
using System.Collections.Generic;
5+
6
using System.Windows.Forms;
7
8-
using System.Xml;
8+
9
10
public class KERS : Script
11
{
12
    string ScriptName = "KERS for all cars";
13
    string ScriptVer = "1.0";
14
    float KERSEnergy;
15
    int GameTimeRef = Game.GameTime;
16
    bool BoostActive=false;
17-
    List<Model> Cars = new List<Model>();
17+
18
    public KERS()
19
    {
20
        Tick += OnTick;
21
22
    }
23
    public static float ForwardSpeed(Entity ent)
24
    {
25
        return Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, ent, true).Y;
26-
        string ConfigFile = @"scripts\\Kersconfig.xml";
26+
27
    void OnTick(object sender, EventArgs e)
28-
        XmlDocument document = new XmlDocument();
28+
29-
        document.Load(ConfigFile);
29+
30-
        int pat = 0;
30+
31-
        while (document == null && pat < 500)
31+
32
            if (BoostActive)
33-
            document.Load(ConfigFile);
33+
34-
            Script.Wait(0);
34+
35
                if (KERSEnergy>0)
36
                {
37-
        if (document == null)
37+
38
                }
39-
            UI.Notify("~o~KERS couldn't find the xml file.");
39+
40
                {
41-
            return;
41+
42
                    BoostActive = false;
43
                }
44-
        XmlElement root = document.DocumentElement;
44+
45
            if (veh.GetMod(VehicleMod.Engine) > 2)
46-
        foreach (XmlElement e in root.SelectNodes("//model"))
46+
47
                if (!KERSNotified)
48-
            Model car = e.InnerText;
48+
49-
            if(car.IsValid && car.IsVehicle)
49+
50
                    KERSNotified = true;
51-
                Cars.Add(car);
51+
52-
                //UI.Notify("[KERS] Added "+car.ToString());
52+
53
                if (Game.IsControlPressed(2,GTA.Control.VehicleBrake) && !Game.IsControlPressed(2,GTA.Control.VehicleAccelerate) && veh.IsOnAllWheels && ForwardSpeed(veh)>5)
54
                {
55
                    if(KERSEnergy<100) KERSEnergy++;
56
                }
57
                if(Game.IsControlJustReleased(2,GTA.Control.VehicleBrake))
58
                {
59
                    if(KERSEnergy<100) DisplayHelpTextThisFrame("~b~KERS~w~ charged [" + Math.Round(KERSEnergy, 0).ToString() + "%].");
60
                    else DisplayHelpTextThisFrame("~b~KERS~w~ charged [~g~" + Math.Round(KERSEnergy, 0).ToString() + "%~w~].~n~Press ~INPUT_CONTEXT~ to release it.");
61
                    
62
                }
63-
        if (GameTimeRef < Game.GameTime)
63+
64
                {
65-
            GameTimeRef = Game.GameTime + 100;
65+
66
                    BoostActive = true;
67
                }
68-
                if (KERSEnergy > 0)
68+
69
        }
70
        else
71
        {
72
            if (KERSNotified) KERSNotified = false;
73
            if (KERSEnergy!=0) KERSEnergy = 0;
74
            if (BoostActive) BoostActive = false;
75
        }
76
    }   
77
    bool CanWeUse(Entity entity)
78
    {
79
        return entity != null && entity.Exists();
80
    }
81
82
    void DisplayHelpTextThisFrame(string text)
83
    {
84
        Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
85
        Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
86
        Function.Call(Hash._DISPLAY_HELP_TEXT_FROM_STRING_LABEL, 0, false, true, -1);
87
    }
88-
            if (Cars.Contains(veh.Model))
88+