Hammer Vscript Tutorial: Basic True/False Statement


Hello, fellow coders! This is the worded version of my tutorial from my other video:
CHECK IT OUT!  :P


Goal after this tutorial: The ability to know how to add your very own vscript to create more functions or better ways to get around your map depending on the type of map you are creating.

LET'S START!

 1. Step 1 - Creating the vscript file
Creating the vscript file is quite simple. There is no compiler needed, so there is no waiting at all.
There is many ways to create this file, either using windows default note editor or what I use "Notepad++"

I would prefer to you guys to use Notepad++. If you do, load it up! Then go to:
Language >> L >> Lua
I know this is not the correct language we are using (Which is squirrel) but it is basically using the same structure, also structures are highlighted in blue which is amazing!)

Then save the empty file - or wait till you got all the code pasted into it - then "save as" highlight the Save as type option then scroll to the top and select "All types *.*" and save it as a ".nut" file.

NOTE: Do NOT save it anywhere else, sadly csgo and hammer hates this. Instead save to:
YOUR STEAM DIR:\Steam\SteamApps\common\Counter-Strike Global Offensive\csgo\scripts\vscripts

TA-DA, YOU MADE YOUR FILE!

2. Step 2 - Creating the functions! 
Okie Dokie, You made your custom csgo map script but it feels empty. Hmm, lets do something about that shall we!

 In coding, we call functions based on modules. In visual basic, it will be generated for you once you click on the form. Form1_Load is the module it creates for you which launches the code once you "Load" it.

In Vscript (Or Squirrel) it gets called from what we call "functions" Functions are what makes the code instead that code activate or trigger. So lets create our first function for your map!

Here is an example of one: [You can call your func. anything you want it to be!]

function HelloWorld()


   Seems empty here

}

here, we see our first code. The Function is named HelloWorld. Unlike Visual basic where it ends in End Sub and Class, you have to use it like C#/++/Java with curly brackets!

Okay, it's boring I know but you'll get the hang of it!

3. Step 3 - The Coding
Since there is a video on it, go and watch it. You'll learn about everything you need to know. So I'll just cover what you can do.

Assigning an number - I used "musicallowed" to be assigned to null (Which basically means 0, you can try zero but it's safe to stick to the technical term "null" :P )

Here's how it should be used:

            Your entity/data name your going to assign to <- null;

What I done here, was I am assigning the named entity (I like to call it that) to nothing. <- part is needed to assign it. NOTE: ALWAYS remember to put ; at the end of every code there is if possible.

If statement
If you know programming, then great! But depending on what code your fantastic act, you may see some things you need to know about how this is sorted:

Starting of with If (musicallowed == 1) will activate if musicallowed is 1. In this case, Yes. Also note that to use 1 equals sign to assign the new data to the entity and to use double equals sign "==" for statements.

You may use multiple if statements in your code as you wish, but if you want it cleaner and looking more neat and professional, try Else.


function HelloWorld-Again?!() "Yes, I know there is a gap, deal with it."




    Is e7 mad? = 1
    if (Is e7 mad? == 1) "Note that no ; or then is needed for this part."
    {
        launch_atmoicbomb_tohim.deploy() "Yeah, I need help now I guess..."
    }
else
   {
       delete_steam_account = True
   }

}

EntFire
You must know this one, it comes handy or triggers. In this case, it helped me to enable or disable the music.

EntFire("your_entity_target","input_of_entity", 0, 0);

The best way to learn this one is to remember the inputs of the entity. If extra data or information is enquired, then replace the 0,0 bit with Parameter override and the last zero with delay (I think, but check incase not!)

Well, I hope you learned something new today. Don't give up and keep Coding and Creating.

- James (TheE7Player)

Popular posts from this blog

C# Object Oriented Programming

C# Memory - Tutorial