Log in to reply
 

[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:
    alt text
    So now, onTick will run every 20 seconds. Let's code our script now!
    alt text
    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.
    alt text
    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:
    alt text
    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 thank you so much for your tutorials. as you can see, eugenius and me can do a lil script now. thanks for teaching. very good tutorials! finally the doors open and close :joy: but one little question, we use at the moment 2 keys to activate the action. one key for v.OpenDoor and one for CloseDoor. i`ve tried "shut door" instead or a "if" if open.door false close door true and so. but then they dont open or close. do you have a hint to open/close with one key?



  • @GTAVModder4Life @TobsiCred Me as a ScriptLegend <- :D solved it! Now you can Open and Close with 1 Key :)



  • @Eugenius MasterOfDesaster, my scriptlegend :handshake: youve made it :thumbsup:


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.