[C#][Tutorial] Basics of creating a script PART 4
Hello guys, part 4 of my series to create a script.
In this tutorial, we will see how to use onTick and how to set its Interval and more stuff.
As I explained in the last tutorial, onTick runs every frame, or if you want you can make it run every other second too. Lets say, for example, every 20 seconds, your car, (if you are in one) gets repaired and cleaned. First, we need to set the Interval of the onTick event. As I said before, you can make it run every frame by not editing the Interval, but if you want it to run every 20, 30, 40, whatever, seconds, follow this. Also note, that Interval is in milliseconds, so if you want it to run every 20 seconds, use 20000, like this:
So now, onTick will run every 20 seconds. Let's code our script now!
Ped.IsInVehicle is a method that does what it says, and returns a boolean if the ped(in our case Game.Player.Character) is in a vehicle. If he is, only then will we continue.
Over here, we declare a new Vehicle variable, which is called currentVehicle. Its value is the player's current vehicle. Afterwards, you can see I call two public methods, Repair() and Wash(). Let's also notify the player using the UI class that their car is getting cleaned:
Voila! Our code is done! Let's go over what our script can do now: if we press a specified key in an ini, we either clear our wanted level, or a subtitle comes up. If we press another key, a car spawns infront of us. And now, our car repairs and washes itself after every 20 seconds! Now, you should have a good idea of SHVDN. Seriously, the key to success here, is put a dot (.) after everything and explore the endless possibilities of SHVDN. If you have any questions, put them down below, and I'll try to answer them. Til then, bye!
(I know this was a short tutorial, but i wanted to cover the basics of SHVDN)
@GTAVModder4Life @TobsiCred Me as a ScriptLegend <- solved it! Now you can Open and Close with 1 Key