ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Smart terrain tutorial

« Previous 10 events | 1 2 3 4 5 | All Messages
Posted by/on
Question/AnswerMake Oldest Up Sort by Ascending
  13:16:14  30 May 2008
profilee-mailreply Message URLTo the Top
Don Reba
Bishop and Councilor of War
(Moderator)

 

 
On forum: 12/04/2002
Messages: 11661
I just find it strange that no one adds articles to the wiki, no matter what. Even Barin's post, on a topic not covered in it and apparently good enough to be a sticky. As if it was a boycott.
  13:02:08  30 May 2008
profilee-mailreply Message URLTo the Top
Steelhawk92
Average Joe - Used to be Jamie1992
(Resident)

 

 
On forum: 03/16/2008
Messages: 5051
I dont know smart terrains like barin does althought i did make a thread yesterday and it told you how to make new factions taht bit was a edited version from the wiki and and also a long section on making new npc's which i made myself.

https://www.gsc-game.com/main.php?t=community&s=forums&s_game_type=xr&thm_page=1&thm_id=14721&sec_id=16

Thats my thread.
  12:58:29  30 May 2008
profilee-mailreply Message URLTo the Top
Don Reba
Bishop and Councilor of War
(Moderator)

 

 
On forum: 12/04/2002
Messages: 11661

---QUOTATION---
Yeah but i cant see anything about smart terrains in the wiki.
Indeed.
---END QUOTATION---


Weird. You still chose not to add it.
  12:37:19  29 May 2008
profilee-mailreply Message URLTo the Top
Claysoft'65
Modding ?... Why not !?
(Resident)

 

 
On forum: 01/31/2008
Messages: 369
Thx very much, Barin
  11:48:04  29 May 2008
profilee-mailreply Message URLTo the Top
FreeKiller
Senior Resident
 

 
On forum: 10/24/2007
Messages: 613
Thanks Barin,this is perfect
  18:46:25  28 May 2008
profilee-mailreply Message URLTo the Top
Don Reba
Bishop and Councilor of War
(Moderator)

 

 
On forum: 12/04/2002
Messages: 11661

---QUOTATION---
Yeah but i cant see anything about smart terrains in the wiki.
---END QUOTATION---


Indeed.
  18:33:45  28 May 2008
profilee-mailreply Message URLTo the Top
Steelhawk92
Average Joe - Used to be Jamie1992
(Resident)

 

 
On forum: 03/16/2008
Messages: 5051
Yeah but i cant see anything about smart terrains in the wiki.
  18:29:37  28 May 2008
profilee-mailreply Message URLTo the Top
Don Reba
Bishop and Councilor of War
(Moderator)

 

 
On forum: 12/04/2002
Messages: 11661

---QUOTATION---
I think a sticky is in order
---END QUOTATION---


It is better to keep the wiki on the top, than attach every tutorial.
  18:27:06  28 May 2008
profilee-mailreply Message URLTo the Top
Steelhawk92
Average Joe - Used to be Jamie1992
(Resident)

 

 
On forum: 03/16/2008
 

Message edited by:
Steelhawk92
05/28/2008 18:28:06
Messages: 5051
Wow barin this is just what i was after thanks alot man.

I think a sticky is in order
  18:22:15  28 May 2008
profilee-mailreply Message URLTo the Top
barin
scripter
(Resident)

 

 
On forum: 09/12/2007
Messages: 702
Smart terrain tutorial

Lately some people asked me how to create and script smart terrains. To avoid responding for each single email i decided to create this little tutorial. Before i start i would like to tell you that i'm not an expert in this kind of stuff and some things are still not clear for me so i might not be able to explain it properly.
My english isn't perfect so please bear with me. Also i will use ST as Smart Terrain abbreviation. This tutorial treats about npc's STs but for mutants it's almost the same. I assume you are familiar with:

- lua programming
- all.spawn editing
- waypoints (patrols)
- ai schemes

First you have to think about your ST, where to spawn it, how many npcs/mutants will "work" for your ST, when ST should be activated/terminated, how many states your ST will have and so on. I guess the best way would be to show you how to get it working by an example. So let's say we want to spawn ST in Cordon for 3 bandits.

1. Spawning ST:


[2515]
; cse_abstract properties
section_name = smart_terrain
name = esc_bandits_smart_terrain
position = 131.02030944824,0.065616846084595,-248.9094543457
direction = 0,0,0

; cse_alife_object properties
game_vertex_id = 635
distance = 9.09999942779541
level_vertex_id = 363757
object_flags = 0xffffff3e
custom_data = <<END
[smart_terrain]
type = esc_bandits_smart_terrain
cond = {-infoportion}
capacity = 3
squad = 1
groups = 5
respawn = esc_respawn_inventory_box_0002
END

; cse_shape properties
shapes = shape0
shape0:type = sphere
shape0:offset = 0,0,0
shape0:radius = 20.55957102775574

; cse_alife_space_restrictor properties
restrictor_type = 3

; se_smart_terrain properties



this is actually the most important stuff:


type = esc_bandits_smart_terrain
cond = {-infoportion}
capacity = 3
squad = 1
groups = 5
respawn = esc_respawn_inventory_box_0002



type is a name of our new ST (required)
cond describes conditions which have to be met (optional)
capacity ST npcs/mutants quantity i.e. how many npcs/mutants our ST can handle (required)
squad, groups no idea what they are used for, maybe they are not used at all but i might be wrong (both are optional)
respawn name of the stash (blue box) where items will be spawn when ST respawn will be called (optional)

2. Spawning npcs/mutants and assigning (binding) them to our ST: in this case for each mutant/npc we have to add to its logic:


custom_data = <<END
[b][smart_terrains]
esc_bandits_smart_terrain = true[/b]
END



3. Adding job (logic) for each npc/mutant from our ST (for each state). Let's say our ST have two states: state 0 (describes what npcs/mutants are doing during day) and state 1 (during night). We have 3 bandits, so say:

- bandit1: walker (state 0) and kamp (state 1)
- bandit2: guard (state 0) and sleeper (state 1)
- bandit3: walker (state 0 and 1 <= he's doing the same at day and night)

There are at least 3 ways to add logic (job) for each npc/mutant, we will use the most common one, i.e. we will add logic to config\misc\gulag_escape.ltx file. It may looks like this:

;-- bandit1 (walker -> state 0, i.e. during day)
[logic@esc_bandits_smart_terrain_bandit1_walker]
active = walker@esc_bandits_smart_terrain_bandit1

[walker@esc_bandits_smart_terrain_bandit1]
path_walk = bandit1_walk
danger = danger_condition@esc_bandits_smart_terrain
def_state_moving1 = patrol
def_state_moving2 = patrol
def_state_moving3 = patrol
meet = no_meet

;-- bandit1 (kamp -> state 1, i.e. during night)
[logic@esc_bandits_smart_terrain_bandit1_kamp]
active = kamp@esc_bandits_smart_terrain_bandit1

[kamp@esc_bandits_smart_terrain_bandit1]
center_point = bandit_kamp
path_walk = bandit_kamp_task

;-- bandit2 (guard -> state 0, i.e. during day)
[logic@esc_bandits_smart_terrain_bandit2_walker]
active = walker@esc_bandits_smart_terrain_bandit2

[walker@esc_bandits_smart_terrain_bandit2]
path_walk = bandit2_walk
path_look = bandit2_look
danger = danger_condition@esc_bandits_smart_terrain

;-- bandit2 (sleeper -> state 1, i.e. during night)
[logic@esc_bandits_smart_terrain_bandit2_sleeper]
active = sleeper@esc_bandits_smart_terrain_bandit2

[sleeper@esc_bandits_smart_terrain_bandit2]
path_main = bandit2_sleep
wakeable = false

;-- bandit3 (guard -> state 0 and 1, i.e. during day/night)
[logic@esc_bandits_smart_terrain_bandit3_walker]
active = walker@esc_bandits_smart_terrain_bandit3

[walker@esc_bandits_smart_terrain_bandit3]
path_walk = bandit3_walk
path_look = bandit3_look

[danger_condition@esc_bandits_smart_terrain]
ignore_distance_corpse = 0
ignore_distance = 0

4. Now we have to script our ST. In this case we will add our code to scripts\gulag_escape.script file. There are several things we need to do here (each of this steps is required):

- load logic (jobs) for each npc/mutant, for each state -> function load_job(...)


if type == "esc_bandits_smart_terrain" then
t = {}
;-- section is a "link" to logic defined in ltx file
t.section = "logic@esc_bandits_smart_terrain_bandit1_walker"
;-- no idea, probably describes after what time
;-- npc will use this job again (?)
t.idle = 0
;-- no idea but i guess it's optional
t.timeout = 0
;-- priority
t.prior = 100
;-- npc will use this logic if ST switched to this state
;-- in this case - state 0 (day)
t.state = {0}
;-- no idea about squad and group
t.squad = squad
t.group = groups[1]
;-- no idea what means position_threshold
t.position_threshold = 100
;-- describes whether npc in this state is online or offline
;-- online = true by default
t.online = true
;-- describes restrictors (where npc can/can't go)
t.in_rest = ""
t.out_rest = ""
;-- because of the way how jobs are assigning by
;-- smart_terrain.script you never know which job
;-- will be used by which npc; if you want to ensure
;-- that certain job is used by certain npc then
;-- you have to use predicate function; in this case
;-- we want this job to be used by expert (master) bandit
t.predicate = function(obj_info) return obj_info.rank >= 900 end
table.insert(sj, t)

t = {section = "logic@esc_bandits_smart_terrain_bandit1_kamp",
idle = 0, timeout = 0, prior = 100, state = {1},squad = squad,
group = groups[1], position_threshold = 100, online = true, in_rest = "",
out_rest = "", predicate = function(obj_info) return obj_info.rank >= 900 end}
table.insert(sj, t)

;-- bandit2 -> state 0 (day)
t = {section = "logic@esc_bandits_smart_terrain_bandit2_walker",
idle = 0, prior = 5, state = {0}, squad = squad, group = groups[1],
in_rest = "", out_rest = ""}
table.insert(sj, t)

;-- bandit2 -> state 1 (night)
t = {section = "logic@esc_bandits_smart_terrain_bandit2_sleeper",
idle = 0, prior = 5, state = {1}, squad = squad, group = groups[1],
in_rest = "", out_rest = ""}
table.insert(sj, t)

;-- bandit3 -> state 0 (day) and state 1 (night)
t = {section = "logic@esc_bandits_smart_terrain_bandit3_walker",
idle = 0, prior = 5, state = {0, 1}, squad = squad, group = groups[1],
in_rest = "", out_rest = ""}
table.insert(sj, t)

end



One more thing about ST states, it's up to you how many states your ST have. The important thing is to add logic for each state. For instance your ST can have those states:

0 - npcs are offline
1 - npcs are online (day)
2 - npcs are online (night)
3 - npcs are online, they decided to assault other ST
4 - npcs are online and actor attacks them

And another thing, i'm sick when i have to fill so many tables, so i usually use this function:


[b]function[/b] fill_tbl(section, idle, prior, states, squad, group, in_rest, out_rest, online, gulag_name)
  [b]local[/b] tbl = {}
	
  tbl.section = "logic@" .. gulag_name .. "_" .. section
  tbl.idle = idle
  tbl.prior = prior	
  tbl.state = {}

  [b]for[/b] index = 1, #states [b]do[/b]
    table.insert(tbl.state, states[index])
  [b]end[/b]

  tbl.squad = squad
  tbl.group = group
  tbl.in_rest = in_rest
  tbl.out_rest = out_rest
  tbl.online = online
  [b]return[/b] tbl
[b]end[/b]



So using above function, we can load logic like this:


if type == "esc_bandits_smart_terrain" then
local t = table.insert(sj, fill_tbl("bandit1_walker", 0, 100, {0}, squad, groups[1], "", "", true, type))
t.timeout = 0
t.position_threshold = 100
t.predicate = function(obj_info) return obj_info.rank >= 900 end
table.insert(sj, t)


t = table.insert(sj, fill_tbl("bandit1_kamp", 0, 100, {1}, squad, groups[1], "", "", true, type))
t.timeout = 0
t.position_threshold = 100
t.predicate = function(obj_info) return obj_info.rank >= 900 end
table.insert(sj, t)

table.insert(sj, fill_tbl("bandit2_walker", 0, 5, {0}, squad, groups[1], "", "", true, type))
table.insert(sj, fill_tbl("bandit2_sleeper", 0, 5, {1}, squad, groups[1], "", "", true, type))
table.insert(sj, fill_tbl("bandit3_walker", 0, 5, {0, 1}, squad, groups[1], "", "", true, type))
end



- automatically change job for each npc/mutant -> function load_states(...)


[b]if type[/b] == "esc_bandits_smart_terrain" [b]then
  return function[/b](gulag)
    [b]if not[/b] db.actor [b]then
      return[/b] gulag.state
    [b]end
    if[/b] level.get_time_hours() >= 5 [b]and[/b] level.get_time_hours() <= 22 [b]then
      return[/b] 0  -- switch all mutants/npc to daily job
    [b]else
      return[/b] 1  -- switch all mutants/npc to nightly job
    [b]end
  end
end[/b]



- ensure that our ST will be used only by bandits -> function checkStalker(...)


[b]if[/b] gulag_type == "esc_bandits_smart_terrain" [b]then
  return[/b] npc_community == "bandit"
[b]end[/b]

 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2020 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.