Welcome, Guest. Please login or register. Did you miss your activation email?

* TUTORIAL SECTION RULES

This section is for SMOD TUTORIALS & GUIDES ONLY.
You may create a new topic in the appropriate area to share your tutorial. If you post anything off-topic here you will be temp-banned. This is so we don't hassle the moderators too much, they are volunteers.

If you need help with a tutorial, post a reply in its thread . Do not start a new topic for help here!

Author Topic: [SMOD] NPC Weapon Randomize Tut  (Read 3820 times)

0 Members and 1 Guest are viewing this topic.

Offline BIZ

  • 32-Bit Hobo
  • *
  • *
  • +0% chance to make useful post
  • BIZ hides in shadows.
    • BSNOOCH.COM
[SMOD] NPC Weapon Randomize Tut
« on: November 03, 2009, 01:55:30 AM »
NPC WEAPON RANDOMIZE!!!



Sorry if any of the wording is confusing....


For the use of randomizing the weapon that each and every NPC carries in a map. This can help to keep a map from playing the same way twice.

For this feature to work, you need to have valid entries in you scripts/npc_weapon_randomize.txt file and you also need to have the ConVar npc_randomize_weapon set to 1.


I. INCLUDED EXAMPLE

This is the example script that the_author included with SMOD. This is the basic foundation for weapon randomization.

Code: [Select]
WeaponRandomizeData
{
"default_map" {
"default_npc" {
"weapon_pistol" "10"
"weapon_smg1" "10"
"weapon_shotgun" "10"
"weapon_ar2" "10"
"weapon_lasergun" "10"
"weapon_ak47" "10"
"weapon_kar98" "10"
"weapon_grease" "10"
"weapon_mp5" "10"
"weapon_svd" "10"
"weapon_rpg" "10"
}
}
}


One thing to note here is that the "WeaponRandomizeData" array needs to be the first entry in your script no matter what. Also make sure that it always has an opening and closing brace. Everything else in the script will go inside this array.


II. DEFAULT_MAP & DEFAULT_PLAYER

**IMPORTANT NOTE** - If you do not include the "default_map" array, SMOD will crash!

The first entry the_author included is the "default_map" and "default_npc" array. This is basically how the script works. We define a map name, then we define which NPCs we want to spawn with randomized weapons, and lastly we define the weapons we want the NPC's to be able to have and at what percentage they should randomly be equipped with one.

The "default_map" is a special array. All this basically does is tell SMOD that on any map we load into the game we want these to be our randomized weapon settings, UNLESS we specifically set otherwise (by overriding with a mapname, explained later).

So lets say that on any given map I load, I want the combine soldiers to either be carrying a Shotgun or an AR2, and for every other NPC, I want them to either have a SMG1, a MP5, or a Grease Gun. Here is how my script should look:

Code: [Select]
WeaponRandomizeData
{
"default_map" {
"npc_combine_s" {
"weapon_shotgun" "10"
"weapon_ar2" "10"
}
"default_npc" {
//"weapon_name" "random_chance"
"weapon_smg1" "10"
"weapon_mp5" "10"
"weapon_grease" "10"
}
}
}

So now you can see that we will have npc_combine_s (soldiers) getting a random chance to spawn with either an AR2 or Shotgun and all other NPCs not defined will randomly spawn with either a MP5, Grease Gun, or SMG1.



III. DEFINING FOR CERTAIN MAPS

Ok, now lets just assume that our settings from above are not what we want on every map. Let us say that on the map d1_eli_01, we don't want Mossman or Eli spawning with a weapon. Let us also say that we only want the citizen NPC's to spawn with SMG1's and MP5's (no Grease Guns).

To do this we will need to open a new array in the WeaponRandomizeData section. This entry name needs to match the name of the map you want it to correspond to. For example:

Code: [Select]
WeaponRandomizeData
{
"default_map" {
"npc_combine_s" {
"weapon_shotgun" "10"
"weapon_ar2" "10"
}
"default_npc" {
//"weapon_name" "random_chance"
"weapon_smg1" "10"
"weapon_mp5" "10"
"weapon_grease" "10"
}
}
"d1_eli_01" {

}
}

Always make sure that you are not putting this new entry inside another map name array. Now it is time to add in the NPC's. When a map name array is defined, SMOD will always take the settings from there first, then it will check for settings from the "default_map" and "default_npc" array (if defined). So for this map, any npc that you do not define, will spawn with a weapon from the "default_npc" entry. To avoid this, we want to give NPC's that we want to spawn with NO WEAPON a value of 0. This is the proper way to do it. Here is my completed script:

Code: [Select]
WeaponRandomizeData
{
"default_map" {
"npc_combine_s" {
"weapon_shotgun" "10"
"weapon_ar2" "10"
}
"default_npc" {
//"weapon_name" "random_chance"
"weapon_smg1" "10"
"weapon_mp5" "10"
"weapon_grease" "10"
}
}
"d1_eli_01" {
"npc_citizen" {
"weapon_smg1" "10"
"weapon_mp5" "10"
}
"npc_eli" {
"0" "10"
}
"npc_mossman" {
"0" "10"
}
}
}

So now when we load up d1_eli_01, any citizens will spawn with either a SMG1 or a MP5. When Eli or Mossman are spawned it will see that we are giving them a weapon called "0" and it will spawn them with no weapon. If you try to spawn an undefined NPC like a combine_s or combine_e on this map, the engine will check first for an entry for their classname, since there isn't one defined it will then check for the "default_npc" keyvalue and will pull data from there.
« Last Edit: July 21, 2011, 12:48:58 AM by BIZ »