Abnormal202 Scripting Tutorial 5: Script-Radiant Relation

broken avatar :(
Created 450 days ago
by qwerty195
0 Members and 1 Guest are viewing this topic.
329 views
broken avatar :(
×
broken avatar :(
Location: usU.S.A! U.S.A!
Date Registered: 10 June 2015
Last active: 212 days ago
Posts
86
Respect
Forum Rank
Rotting Walker
Primary Group
Community Mapper
My Groups
More
My Contact & Social Links
More
Personal Quote
Abnormal202
Signature
-Abnormal202
×
qwerty195's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
ABNORMAL202 SCRIPTING TUTORIAL 5: SCRIPT-RADIANT RELATION
See ALL Tutorials

DESCRIPTION

We've done a lot of talking about script theory, but how can we actually apply this to our maps? There are a lot of cool tricks as well as simple essentials to know about how we can use radiant and our GSC together.


KVPS

You've no doubt heard of or used KVPs before, for example for making zombie_door's or setting up your zones. A KVP is a very simple but very powerful tool. It's simply two peices of data paired together: a key and a value.

These can be set in radiant on pretty much everything. You can access an entity's KVPs by pressing "n" while having it selected. 

It should be noted that if you want to use a model in script, in radiant it should be a script_model, and if you want to use a brushmodel in script, in radiant it should be a script_brushmodel.

When you make something a script_model or script_brushmodel, you'll notice it already starts out with some KVPs:



We can access these KVP's in script. But first we must grab the entity in script.

The most common way to grab an entity in script is to give it a custom value for the targetname (in radiant) and then use GetEnt() (in script):


function joseph()
{
   my_main_man = GetEnt("joseph","targetname");
}
there are other keys that also work with GetEnt, such as script_noteworthy, target, classname, or script_string. Not all keys work with GetEnt() however. But that doesn't mean we can't use our custom keys in script.

PROPERTIES

When we get an entity from radiant in script, it stores all the values on that entity into properties based on the keys of the KVPs it has. For example, if I set a custom KVP in radiant such as:

the value is stored just like this, automatically in script:
my_main_man.gender = male;
this is great for If Statements. We could use it like this:
my_main_man = GetEnt("joseph","targetname");
if(my_main_man.gender == "male")
{
   IPrintLnBold("Joseph... is a man");
}
or another common usage, storing vectors:

my_main_man = GetEnt("joseph","targetname");
my_main_man MoveTo( my_main_man.origin + my_main_man.script_vector, 5);

ORIGINS/ANGLES

All entities start out with an origin key and angles key. While they aren't particularly special, they are used quite a lot so I wanted to make a quick section about them.
The origin is the XYZ coordinates of where the entity's origin is located in the map. You'll notice as you move the object in radiant, the value for origin changes automatically in the KVPs.
it's important to note it is specifically the entity's origin. You can see each entity's origin as a hollow blue cube in the 3D view:

For the most part, the origin is located somewhere in the middle of the object, or where it would touch the ground.
The angles are the Roll, Pitch, and Yaw rotation of the entity that will change as you rotate the entity.
the roll changes as you rotate around the X-Axis, the pitch if you rotate around the Y-Axis, and the Yaw if you rotate around the Z-Axis.
Knowing the object's angles/origin is often important for using functions such as:
moveto(,,[acceleration time],[deceleration time]);
rotateto(,,[acceleration time],[deceleration time]);
which are very commonly used.

RADIANT'S AUTO-TARGETING SYSTEM

You may have noticed in making zombie_doors that you can have certain entities "target" other entities, by giving the targeting entity the key "target" with the value of that key being the targetname of the entity being targeted.


As you can see, when an entity is targeting another, a red line appears between the two with the arrow pointing towards the entity being targeted.
this makes accessing the targeted entity simple in script if you already have the targeting entity:
headless_soldier = GetEnt("dead_soldier","targetname");
joseph = GetEnt(headless_soldier.target,"targetname");
notice I only typed in one actual targetname, "dead_soldier". The other targetname was gathered through using the target of the other entity.
This brings me to Radiant's automatic targeting system. If you select two entities then press "w" it will make the first entity target the second, assigning an auto-targetname for the targeted entity that looks like this:

the number will change each time you do it, so no two entities using the auto-target system share the same targetname.
Other things to note:
  • you can chain targets: an entity can target another entity which targets another entity and so on
  • an entity can target multiple entities if they all share the same targetname
  • multiple entities can target the same entity if they share the same target

TRIGGERS

Triggers are very useful in script, and I will go into more detail on them later. Triggers can be placed in radiant and there are several different types of triggers.
Here are some of the most common ones I use:
  • trigger_use : You can give it a hintstring. Is "triggered" when a player presses their interact button while looking at it.
  • trigger_multiple : "triggered" by a player touching the trigger_multiple. Also useful to use the IsTouching() function with.
  • trigger_damage : "triggered" by something dealing damage inside it.
  • trigger_hurt : hurts players while they are touching it.
  • trigger_radius : creates a perfect sphere around it, that is "triggered" when a player enters it. Also useful to use the IsTouching() function with.
When a trigger is "triggered", it passes the "trigger" notify on itself in script. Meaning if we use a waittill, we can make the code effectively wait until the trigger is triggered, before doing something:
trig = GetEnt("my_trigger","targetname");
trig waittill("trigger");
IPrintLnBold("TRIGGERD");
See ALL Tutorials


 

Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Twitch
Loading ...