FANDOM


Tutorial by Seraskus:

If you are here you probably came here knowing that you surely need scripting to make your map working. Did you? Of course you didnt! So think once again... Thought? You surely want to learn it? Ok, so here we go!

What we needEdit

The first thing we will need is a program called "BehavEd". There is also one called "DEvaheb". Yes, it is "behaved" readed back. So, the first one is to complie scripts and the second- to read compiled ones! Just ask Uncle Google for it and he should provide you with both in his kindness :j

New Keys for entitiesEdit

Now, as we have the program (or we dont, because we were to lazy to ask the Uncle) we may seriously think about beggining. But wait! We need one more thing: How from GKTRadiant do we tell entities to start scripts?

usescriptEdit

We take a trigger multiple and give it a Key called usescript with the value of script name (without any extension!). Our script should be placed in gamedata/base/scripts. So if we have it in gamedata/base/scripts/mymapfolder/myscript.IBI
the key will look like: usescript and mymapfolder/myscript

The trigger when used will fire the script. Of course you can also put the "usescript" key in any other entity (doors for example). Than when they open they will use the script you tell them to.

target_scriptrunnerEdit

(Obviously it is entity not a key, but I'll mention it here for the clarity)

So, you will ask: What do we need the target_scriptrunner for? We use it when we want- for example- our doors to use script when they start moving down. So than we will just give our doors target2 pointing at the target_scriptrunner. Another usage is affecting the player or npc that triggered our script. Than we use target_scriptrunner with the useonactivator flag checked.

script_targetnameEdit

This one is tricky. You should always remember: When we tell the scrpt to use any entity it will use the entity with the given targetname. I will repeat: TARGETNAME! Not the SCRIPT_TARGETNAME!

So what we use script_targetname for? The script by default runs on the entity that fired(used) it. Or the one that used the one that used it. When we want the script to affect any other entity (so to heal an npc, set doors inactive, make target_usable visible or a button pressable) we need a scripting command affect. And this affect block is the one that needs the script_targetname key.

So let's repeat:
targetname - for using(firing) the entity from the script (or from any other entity in GTKradiant)
script_targetname - for "affecting" entity's keys and properties from the script

PARM'sEdit

Each entity has 8 free variables to use. They are so called PARM1, PARM2, PARM3 (and so on).

If we want to store some data in the entity we need to give it a key called PARM1(or PARM2,3,4,5,6...) with ANYniceVALUE. The value can be any text string or number. The script can read and modyfy this values and store some data in them, that's what we use them for.

Lets make a script!Edit

To begin with: I wont tell you how to use Behaved and Dehaveb. If you have slightly more inteligence than an ordinary vegetable you will learn it in 10s. If not- you had better not begin your advanture with scripting, as it ends here. The zip file with this programs should contain a .doc tutorial for them. Read it if you need. Also some GTKradiant versions have already this programs included (search in Radiant\tools folder).

UsingEdit

Ok, we want our script to use an entity. We drag "use <str>" command, click it twice and give the targetname of entity we gonna use. We compile the script, put it to gamedata/base/scripts ( the .IBI file is our script, the text one is just to look at the results easier) Than we make a trigger using this script and a map to play on :P. And it should work :j

(de)ActivatigEdit

Now, we want a script that will activate/ deactivate some trigger or whatever. Remember what I said? The script runs on the entity that used it! So to make any other entity active/inactive we need to AFFECT it! So let's give our entity (this second one that stays somewhere, not the one that uses the script) a script_targetname key (for example MyTrigger) and in our script let's drag the "affect" block. And tell it to affect the entity with the given script_targetname of course :P . It will look like

affect("MyTrigger", FLUSH)
{
*some code here*
}

FLUSH forces the "MyTrigger" to stop doing any script-defined actions it does and start doing what we want. INSERT would add our commands to the end of the queue (on our lever its totally meaningless to make any choice here as we dont make script spam yet... do we? )

Than in the {} brackets we put all the commands that will affect the trigger. For example we SET its activeness on and off, like:

set ( "SET_INACTIVE", "true" );

This will work as a target_deactivate and make the entity inactive. You may use "false" instead of "true" to switch the entity on again.

All in all the program after compiling will add some "comments" to it, like /*@AFFECT_TYPE*/. They change nothing at all, but help you to understand what each part does. The final script should look like this:

affect ( "MyTrigger", /*@AFFECT_TYPE*/ FLUSH )
{
set ( "SET_INACTIVE", "true" );
}

instruction "if", working on PARMsEdit

Setting PARMsEdit

Remember the PARM1, PARM2 and other PARMs I mentioned at the beggining? We may modyfy them from the affect block. Se use the set command again here. In the script we refer to parms not as "PARM1", "PARM2"; but as "SET_PARM1", "SET_PARM1" and so on. So to give our PARM new value we may use such script:

affect ( "MyTrigger", INSERT )
{
set ( "SET_PARM1", "0" );
}

Getting PARMsEdit

The most common way of using the parms is along with the "if" block. So for example "If the PARM1 is 1 activate the trigger and set PARM1 to 0. Else deactivate the trigger and set PARM1 to 1 "

To do such an instruction we need to get the PARM1 value. How?

get(type, value_holder);

So in script:

if ( $get( FLOAT, "SET_PARM1")$, $=$, $1$ )
{
Deactivate trigger
}
else
{
Activate trigger
}

[ATTENTION! Remember that: 1. Compiler adds $ chars. So dont write them in code bestly ;P.
2. If we want to check the PARM1 of the other entity than the one that activated that script than remember to use the affect block!]

Final PARM-editing scriptEdit

If the PARM1 is 1 set PARM1 to 0. Else set PARM1 to 1

if ( $get( FLOAT, "SET_PARM1")$, $=$, $1$ )
{
set ( "SET_PARM1", "0" );
}
else ( )
{
set ( "SET_PARM1", "1" );
}

Final script for the begginingEdit

This is the script I used in a tournay room. If the room is opened (PARM1 set to 1) it deactivates door triggers and activates forcefields to lock the room off. If the room is locked (PARM1 set to 0) it opens everything. To make sure my script works on the proper entities I added affect blocks even where they aren't really needed (it's a good habit, really). "script_trigger" is the trigger that uses the script. "forcefield" is func_usable forcefield and "door_triggers" are triggers opening doors to the room.

if ( $get( FLOAT, "SET_PARM1")$, $=$, $1$ )
{

affect ( "script_trigger", /*@AFFECT_TYPE*/ INSERT )
{
set ( "SET_PARM1", "0" );
}

use ( "forcefield" );

affect ( "door_triggers", /*@AFFECT_TYPE*/ FLUSH )
{
set ( "SET_INACTIVE", "true" );
}

}
else ( )
{
affect ( "script_trigger", /*@AFFECT_TYPE*/ INSERT )
{
set ( "SET_PARM1", "1" );
}
use ( "forcefield" );

affect ( "door_triggers", /*@AFFECT_TYPE*/ FLUSH )
{
set ( "SET_INACTIVE", "false" );
}

}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.