Scripting Basics (Newbie Tutorial)

Demon
Server Admin
Posts: 3161
Joined: Tue Nov 15, 2011 6:30 am

Scripting Basics (Newbie Tutorial)

Post by Demon » Thu Sep 13, 2012 5:30 pm

Scripting
---Warning! This topic is still under construction please be patient!---

Welcome. In this tutorial you will learn the basics of what you need to know to script in HL2:DM.
Valve Developer site is best for scripting. If you have an entity in mind that you want to work with just take a look at the link below for all the entities and their values.


https://developer.valvesoftware.com/wik ... f_entities

You can write your scripts in any word/text editor, I suggest you to use notepad or notepad++ which is ideal for scripts.
All scripts must be saved in the directory below and as a ".cfg" format.
"Steam\steamapps\YOUR USER NAME\half-life 2 deathmatch\hl2mp\cfg"
"Name_of_script.cfg"

All your scripts can be executed by using the command below in the HL2:DM Console.
exec Name_of_script
You do not need to put in the extension. ".cfg"

To open up your console watch the tutorial down below.


http://www.youtube.com/watch?v=rJdd1SLz3_Y
Check out Nick's Script Builder which will help you make scripts.

http://www.area51cheatserver.com/scriptbuilder.html
Binding Scripts
You can use the command in the HL2:DM console to execute scripts faster by binding them to a key and then pressing it.
Anything with <...> must be filled in.
bind <Key> "exec <Name_of_script>"


Scripting Syntax's
Spoiler
Show
Anything with <...> must be filled in.

Entities
ent_create <entity name>

Keyvalues
ent_fire <name> addoutput "<keyvalue> <value>"

Inputs
ent_fire <name> <input> <value>

Outputs
ent_fire <name> addoutput "<output> <name>,<input>,<value>" OR
ent_fire <name> addoutput "<output> <name>,addoutput,<keyvalue> <value>"


Waits
wait 100;ent_fire <name>
Commands/Targets
Spoiler
Show
Ent_create <Name of entity> - A command which creates an entity to where ever you are pointing to with your crosshair.
Ent_setname <Name> - A command which sets an entities name.
Ent_fire - A command which can allow you to give/change entities properties.
Npc_create <Name of entity> - A command which creates an NPC to where ever you are pointing to with your crosshair.
Give <Name of entity> - A command which creates an entity right under neath your feet.
Wait <Amount>; - Wait commmand allows to make something happen after a certain time. (100 = 1 sec)
Kill - Delete's the entity.

!activator - The one that activate it.
!self - Yourself.
!picker - Where you are looking. (Doesn't work in Multiplayer.)
!player - Player entity. (Doesn't work in Multiplayer.)
!caller - Object itself.
Target Names/Class Names
Spoiler
Show
Targetname - is a key value to change an entities name.
Classname - is a key value to change an entities class name so other players cannot change or delete your entities. This makes your entity unique and none of other players can change the entities properties by using "ent_fire" to change any key values. Unless they know your targetname and classname.
Key Values
Spoiler
Show
A Key value is an instruction used to modify the variables in entities.
Keep in mind that different entities have different key values and may not be exactly the same and you cannot make up your own.
If you have an entity in mind that you want to work with just take a look at the link below for all the entities and their values.

https://developer.valvesoftware.com/wik ... f_entities

The syntax for key values.
ent_fire <name> addoutput "<keyvalue> <value>"
Let's start of with a simple key value.
ent_fire npc adddoutput "rendercolor 255 0 0"
The key value is "rendercolor 255 0 0"
That example will make any entity named "npc" change it's color to red.
When ever you want to add a key value to an entity always type in "addoutput" after "ent_fire <name>" this adds an output and will let you manipulate with the entity to your preferable settings by using key values.

Spawning Objects/NPC's
Spoiler
Show
You must know your syntax's of creation.

Ent_create <Name of entity> - A command which creates an entity to where ever you are pointing to with your crosshair.
Npc_create <Name of entity> - A command which creates an NPC to where ever you are pointing to with your crosshair.
Give <Name of entity> - A command which creates an entity right under neath your feet.
prop_dynamic_create <Root of model/object> - A command which allows you to create a dynamic object.
prop_physics_create <Root of model/object> - A command which allows you to create a physical object.

npc_create uses a very simple syntax, and is simply "npc_create npc_name". An example of this.
npc_create npc_gman
This spawns a Gman to where ever you are pointing to with your crosshair.

Let's make a object now, what you will need to know is the syntax of creating the object and the root of the object.

prop_dynamic_create <Root/object> - A command which allows you to create a dynamic object.
prop_physics_create <Root/object> - A command which allows you to create a physical object.

When you type in "prop_physics_create" you are already in the models folder so the only thing you need to do is to give the root of the model you want to spawn.
We will now spawn a blastdoor because it is one of the most used and popular props to build any sorts of buildings. The root and the name of the object is down below.
props_lab/blastdoor001c.mdl - Folder_in_models_folder/Another_folder/model.mdl
You can also bind the syntax of making the blastdoor to a key so it's faster to build a building.
bind <key> "prop_physics_create props_lab/blastdoor001c.mdl"
Color System
Spoiler
Show
We can also change the color of the Gman.
npc_create npc_gman - Creates NPC Gman.
ent_setname gman - Names the entity "gman" (Must be looking at the Gman to setname it.)
ent_fire gman addoutput "rendercolor 255 0 0" - Changes the color of the entity to "red 255 0 0".
The link below is a good place to find your colors that you are looking for. Remember that when ever you want to set a color to something use the RGB rule.

http://www.generateit.net/color-schemes/

For example
ent_fire <name> addoutput "rendercolor RED GREEN BLUE"
ent_fire <name> color "RED GREEN BLUE"


If you ever want to set the color of your self then use the syntax down below.

Code: Select all

ent_fire !self addoutput "rendercolor R G B"
You can also download the RGB Slider which is helpful in choosing colors.
http://www.mediafire.com/?k6m1gp6drv3r5mw
[/b]
Wait System
Spoiler
Show
The wait system is really useful, it let's you make things happen after a certain amount of time.
The command is.
wait <Amount>;
For example.
wait 100;ent_fire !self addoutput "rendercolor 255 0 0" - After 1 second your color will change to red.
wait 200;ent_fire !self addoutput "rendercolor 0 255 0" - After 2 seconds your color will change to green.
wait 300;ent_fire !self addoutput "rendercolor 0 0 255" - After 3 seconds your color will change to blue.

Explosion Script
Spoiler
Show
I will not give you a ready made explosion script to copy and pate but I can give you the key values and the information you need to know to be able to make one.
First you need to know the Syntax's of making a explosion script.


ent_create <entity name>
ent_fire <name> addoutput "<keyvalue> <value>"
ent_fire <name> <input> <value>
wait 100;ent_fire <name>

The syntax's above is now your structure to make a explosion script.
First what you need to know is the entity name to make a explosion which is "env_explosion"

Anything with <...> must be filled in.

ent_create env_explosion

Now we will need to name and class name it. Make sure the targetname and classname are the same, it will just be easier to keep the same.

ent_fire env_explosion addoutput "targetname <name>"
ent_fire <name> addoutput "classname <name>"

Once we done that now we can add key values and inputs.
Here is the list of key values and inputs you will need to use in order to make a successful explosion script.
The key values and inputs should be used like this.

ent_fire <name> addoutput "<Keyvalue> <value>"
ent_fire <name> <input>

iMagnitude - Key value, The amount of damage done by the explosion.
iRadiusOverride - Key value, The radius in which the explosion damages entities.
explode - Input, triggers the entity to explode.

Once you done the key values and inputs, you now must delete the explosion by using this simple syntax with a wait command so it doesn't delete the explosion straight away otherwise there will be no explosion.

wait 100;ent_fire <name> kill

Congratulations you just made your first script, your script should look something like this.

ent_create env_explosion
ent_fire env_explosion addoutput "targetname <name>"
ent_fire <name> addoutput "classname <name>"
ent_fire <name> addoutput "<Key value> <Value>"
ent_fire <name> addoutput "<Key value> <Value>"
ent_fire <name> explode
wait 100;ent_fire <name> kill
To download trusted scripts made by the Area 51 Owners just click on the link down below.
Ant_8490
Nick_6893
http://www.area51cheatserver.com/data/scripts.php
Learning from scripts is a good idea too if you know what you are doing.
Thank you for reading. Hope this tutorial helped on how to script.
If I have made a mistake somewhere please write down what's wrong.
Last edited by Demon on Sat Sep 15, 2012 8:10 am, edited 27 times in total.

User avatar
Bob1337
Server Admin
Posts: 542
Joined: Fri Apr 09, 2010 10:02 pm

Re: Scripting Basics

Post by Bob1337 » Thu Sep 13, 2012 6:23 pm

Please dont ask me how to script.
Instead, click this.
Btw; I'm an asshole to idiots.
Bob1337 wrote:Explosive buddha killers. That shit is gay.

User avatar
shadowslayer
1000+ Posts
1000+ Posts
Posts: 1280
Joined: Fri Sep 03, 2010 8:51 pm

Re: Scripting Basics

Post by shadowslayer » Thu Sep 13, 2012 6:28 pm

Definitely more effective, but why is demon making another scripting tutorial? Isn't there already several on this forum alone?
Spoiler
Show
Saying "Your lucky i'm peaceful" is pretty much like saying "when i grow up i wanna be an arms race!"-HL2shadowslayer, Area 51 Minecraft
Imagethe only reason you shouldnt mess with me

Anonymous

Re: Scripting Basics

Post by Anonymous » Fri Sep 14, 2012 2:18 am

Because he's an attention seeking whore.

Nicdel
Server Admin
Posts: 2417
Joined: Sun Apr 11, 2010 4:50 am

Re: Scripting Basics

Post by Nicdel » Fri Sep 14, 2012 4:00 am

First part was good, except for Addoutput being a command, it's not. But I really don't see why you'd teach anyone how to make explosions.
Ingame: -[SaD]- Nico

Image

Demon
Server Admin
Posts: 3161
Joined: Tue Nov 15, 2011 6:30 am

Re: Scripting Basics

Post by Demon » Fri Sep 14, 2012 12:54 pm

Nicdel wrote:First part was good, except for Addoutput being a command, it's not. But I really don't see why you'd teach anyone how to make explosions.
OKi, deleted that addouput is a command, Idk I guess I was bored, if you see any other problems just tell me. :P

Ryan
Former Server Admin
Posts: 1163
Joined: Fri Apr 23, 2010 2:56 am
Location: United Kingdom

Re: Scripting Basics

Post by Ryan » Fri Sep 14, 2012 1:36 pm

There are plenty of tutorials already scattered across this forum as it is. Hardly anyone wants to learn to script, and for those that do, let them use an existing tutorial. I'm sure you've already made a topic about this?

Demon
Server Admin
Posts: 3161
Joined: Tue Nov 15, 2011 6:30 am

Re: Scripting Basics

Post by Demon » Fri Sep 14, 2012 2:38 pm

Ryan wrote:There are plenty of tutorials already scattered across this forum as it is. Hardly anyone wants to learn to script, and for those that do, let them use an existing tutorial. I'm sure you've already made a topic about this?
Yes I did but it was shit. I decided to make a new one and im still making it now.

User avatar
po0ka
Former Server Admin
Posts: 713
Joined: Fri Oct 29, 2010 7:40 pm

Re: Scripting Basics

Post by po0ka » Fri Sep 14, 2012 4:03 pm

just to say, some use the "color" input to color.
You seem to use the addoutput "rendercolor x x x"
I use the input color "x x x"
Maybe you can insert it as example too.

Btw, it is better having someone asking to know how, and sending him to an underused website rather than posting it on active cummunity, just to be sure no bad persons end to use this as trolling method or world domination. When i see a good person asking how that got a good grammar, i send them to my scripting website.
But your is way more easy to understand, mine has more talking and explanation in it :P

You should add the binding, but try to change the explosion for a trail, for example.
I didn't see alot of people spamming trails as of yet.
Keep in mind that what i say is not static, it is dynamic.
Years, months, weeks, and days after i say something, i can say the opposite.

Demon
Server Admin
Posts: 3161
Joined: Tue Nov 15, 2011 6:30 am

Re: Scripting Basics

Post by Demon » Fri Sep 14, 2012 4:09 pm

po0ka wrote:just to say, some use the "color" input to color.
You seem to use the addoutput "rendercolor x x x"
I use the input color "x x x"
Maybe you can insert it as example too.

Btw, it is better having someone asking to know how, and sending him to an underused website rather than posting it on active cummunity, just to be sure no bad persons end to use this as trolling method or world domination. When i see a good person asking how that got a good grammar, i send them to my scripting website.
But your is way more easy to understand, mine has more talking and explanation in it :P

You should add the binding, but try to change the explosion for a trail, for example.
I didn't see alot of people spamming trails as of yet.
Oki I will add that as an example too, thx, and oki. I will replace the explosion into a trail.

Btw is it....

ent_fire test color "x x x" ????

Demon
Server Admin
Posts: 3161
Joined: Tue Nov 15, 2011 6:30 am

Re: Scripting Basics

Post by Demon » Fri Sep 14, 2012 4:26 pm

Unlike yours mine is formal which is always a good way of showing people that you have spent some time doing the tutorial.

User avatar
Bob1337
Server Admin
Posts: 542
Joined: Fri Apr 09, 2010 10:02 pm

Re: Scripting Basics

Post by Bob1337 » Fri Sep 14, 2012 10:42 pm

Demon wrote:
Unlike yours mine is formal which is always a good way of showing people that you have spent some time doing the tutorial.
Not to get into a "Mine is better than yours" argument but... My tutorial is in-depth and explains the basics of scripting and honestly doesn't look half bad. It's taken me hours to write and has examples that are thoroughly explained. Yours doesn't explain what ent_fire is, what keyvalues are, or anything of the sort. Not only that, your tutorial has no sense of direction. You open a spoiler and random unknown information is thrown in your face. So yeah.
Please dont ask me how to script.
Instead, click this.
Btw; I'm an asshole to idiots.
Bob1337 wrote:Explosive buddha killers. That shit is gay.

Demon
Server Admin
Posts: 3161
Joined: Tue Nov 15, 2011 6:30 am

Re: Scripting Basics (Newbie Tutorial)

Post by Demon » Sat Sep 15, 2012 5:06 am

Not to get into a "Mine is better than yours" argument but... My tutorial is in-depth and explains the basics of scripting and honestly doesn't look half bad. It's taken me hours to write and has examples that are thoroughly explained. Yours doesn't explain what ent_fire is, what keyvalues are, or anything of the sort. Not only that, your tutorial has no sense of direction. You open a spoiler and random unknown information is thrown in your face. So yeah.
My tutorial only explains the things they need to know for basic scripting. My has example's too and it's explained. My does say what ent_fire is, open the spoiler under the title Commands. Keyvalues are next on the list so I will be adding them sooner or later. Maybe you didn't notice but it says. "Warning! This topic is still under construction please be patient!"
No, each spoiler is titled, for example it says "Color System" and when they open the spoiler up it shows them nearly everything they need to know about the colors.

[GR]doodleninja
1000+ Posts
1000+ Posts
Posts: 1086
Joined: Mon Feb 27, 2012 11:08 am

Re: Scripting Basics (Newbie Tutorial)

Post by [GR]doodleninja » Sat Sep 15, 2012 6:13 am

I suggest Bob to expand and complete his tutorial

User avatar
Xseba360
Server Admin
Posts: 1663
Joined: Sun Apr 11, 2010 12:26 pm
Location: Poland

Re: Scripting Basics (Newbie Tutorial)

Post by Xseba360 » Sat Sep 15, 2012 7:17 pm

[GR]doodleninja wrote:I suggest Bob to expand and complete his tutorial
and then post it here so ant can remove demon's tut. :troll: