We crown ourselves

Royal Para Regiment

Random Scripting Introduction

More
4 years 1 week ago - 4 years 1 week ago #1 by Stern
Random Scripting Introduction was created by Stern
Well then, I present some ideas and script examples about how to randomize mission.

First things first:
This is not scripting tutorial !
(It requires some basic knowledge of HD2 scripting language functionality)

I like to use Notepad++
This attachment is hidden for guests.
Please log in or register to see it.

(Use this for Notepad++ to support HD2 script (*SCR) added to C++ language.)

(All script examples presented here are already used in some missions, changed to fit this tutorial)
(Some parts of script examples might not be present, like object framing and variable declaration)

*
Scripting is the way to make mission function as a mission.
Almost everything that moves/acts or changes in running mission is scripted.

Randomness creates many useful variations to make mission act different each time you play it.
Mission with controlled variations will be interesting
and will not get boring when played many many times...

But time is money so I get right to the point then:
[hr]

Random spawn(activation) of enemy/ally.

There are mainly 2 ways to make enemy activation random.
1.
One script controls some or all enemy spawns.
This script might detect player with commands: "_PlayerInBox" or "_PlayerInRange"
Or it can be set at mission start or by other means.

Example (Random snipers)
Warning: Spoiler!


2.
Other way:
Every enemy has its own random spawn section in script.

Warning: Spoiler!



*Never use HUMAN_MoveRandomRadius() or any other time dependent command inside BLOCK{} when other command follows !
BLOCK{} does not wait command to run to the end.


*Rnd1 variable is re-used many times here, its fine unless the variable has to hold the value after next need for a variable.
Then sepatate varables must be used.

Disadvantage of this spawn method is that its not possible to check killed enemy directly.

One way to get around it is to kill "Not spawned" enemy.

NB_! Enemy should have weapon on shoulder at mission start, if not then weapon will drop on the ground near enemy position !
Can use this:
HUMAN_WeaponOnArm(0);
Before HUMAN_Kill(me);

For this use: GetMyFrame:
Frame me; FRM_GetMyFrame(me);
and use HUMAN_Kill(me); in "Not spawned" section:

Warning: Spoiler!


Now its possible to check killed enemy with command "(!_EnemyInRange())"



*One simple and short way to count killed enemy (uses only one variable S1):

Warning: Spoiler!


Make enemy movement ability random (OnAlarm):

Warning: Spoiler!


This requires that enemy is set to "HUMAN_SETAIMODE_Zombie();"
And can be set back to "HUMAN_SETAIMODE_Zombie();" in the "OnAlarmDone()" section.
This way the same enemy might be passive at next Alarmed state.

Random (selected) equipment:

Warning: Spoiler!


This is the equipment that Player can find in killed enemy inventory.

Random Ammoboxes

Ammo/equipment box should be set to be delivered by parachute.
And the location should have open sky above it.
Start position can be under the surface to hide the box.

Warning: Spoiler!



Random Objectives:
*Used in Libya1(PrisonBreak)

Warning: Spoiler!


Random objectives meaning will be lost in very small areas like Libya1.
Its much better to use it for large areas,
where Player can skip going to some areas
if objectives does not require to go there.


Walking guard
Needs some dummy objects in Actors.bin.

Warning: Spoiler!


"gosub" (procedure/function in prog. language)
is useful if this code (delay in this case) is used from other places in script,
then this code is present in only one place, and script can be directed to use it from any places.


Maybe this helps to get ideas or get start to manage some random acts in mission.

The one who hesitates is lost !
Last edit: 4 years 1 week ago by Stern.
The following user(s) said Thank You: snowman, Damni, WANGER

Please Log in or Create an account to join the conversation.

  • snowman
  • Offline
  • Your most dear friend.
More
4 years 1 week ago #2 by snowman
Replied by snowman on topic Random Scripting Introduction
This is excellent work, Stern. I feel this deserves it's own topic :cheer:

Very clearly explained :gj:

"Straight and narrow is the path."
The following user(s) said Thank You: Stern

Please Log in or Create an account to join the conversation.

  • Tecnom
  • Hellcat in 3 days
  • Winters in 4 days
  • Alexliberty in 5 days
  • Mizha in 9 days
  • British Bulldog in 10 days
Powered by Kunena Forum