Creating items and NPCs using scripts

From Mod Wiki

Jump to: navigation, search

Origin : [1]

This information was taken from the link above - all credit goes to Insanelazarez. The original question was to place replace dead ecologist NPCs but the exact template serves as a good starter for anything.


You need:

1 - To take the coordinates of the new location, (in game) open the console and type "rs_stats 1". After that you should see several things. The important part is the "camera position:". Take a screenshot (in FIRST person view), of the new location. If you already have the screenshot, it's time to "quit to windows". Look to your screenshot. See the numbers in the "camera position"? That's the new location. An easy way to do this is the "escape_dialog.script". You need the file, of course. In this file search for this:

function give_weapon_to_actor (trader, actor)

several items here, right? Now, after the...
dialogs.relocate_item_section(trader, "wpn_knife", "in")

Try to add this line:

local spawn_position = vector():set( -209.84, -18.83, -147.56 )
alife():create("yan_ecolog_respawn_1", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )

Remember, the "-209.84, -18.83, -147.56" part it's a real location close to campfire. But you can change it to the values of your screenshot, right?

Let's imagine you want 2 ecologists instead of 1. After the new line... repeat it again.

It will be something like this:

local spawn_position = vector():set( -209.84, -18.83, -147.56 )
alife():create("yan_ecolog_respawn_1", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
local spawn_position = vector():set( -209.84, -18.83, -147.56 )
alife():create("yan_ecolog_respawn_1", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )

The best way to spawn the 2 "ecologs" (in the same location, of course) is this:

for i = 1, 2 do
local spawn_position = vector():set( -209.84, -18.83, -147.56 )
alife():create("yan_ecolog_respawn_1", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
end

You see? it's the same. Use the same code to spawn other items. Look to the ".ltx" files. In folders like... config\misc

  • unique_items.ltx
  • items.ltx

Or config\weapons (just an example) "w_gauss.ltx" open that file. In the top you can see this:

[wpn_gauss]:identity_immunities

Yes... "wpn_gauss" is the code for the "gauss rifle". Now try this with the code i told you:

2 scientists 2 gauss 2 gauss ammo

The six items will spawn on the ground in the same place (only when wolf gives you the knife, etc). So the code will be this:

for i = 1, 2 do
local spawn_position = vector():set( -209.84, -18.83, -147.56 )
alife():create("yan_ecolog_respawn_1", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
alife():create("wpn_gauss", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
alife():create("ammo_gauss", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
end

That's it. After the dialog with wolf... kazammm... you see them? Sometimes the npcs will take the weapons real fast, sometimes not. It's not that bad, you can take the weapons to the trader, right? Now if you ask me, how do i know the "yan_ecolog_respawn_1" part? Good question, but that's easy. In "config\creatures" folder, open the "spawn_sections.ltx". You see it? It's all there, it's easy. Now this is important. In several locations, you will have problems for some "spawn_sections", That's the way it is. It is related with "smart terrain" values. And for obvious reasons, you can NOT use the same script to spawn something... in the garbage level, of course. But there's a huge number of scripts in the game. Just take one, like "bar_dialogs.script" (just an example):

if has_alife_info("bar_arena_fight_1_reward") then
m = 1000
for i = 1, 7 do
local spawn_position = vector():set( 167.57, 1.56, 52.46 )
alife():create("val_bandit_respawn_4", spawn_position, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
end

This will spawn seven bandits, close to the "get out of here, stalker" guy, after the first arena reward. You can change the reward too. The "m = 1000"... is your reward. Change it for the value you want. Btw, remember the "rs_stats 1" in the console? Before "exit to windows"... turn it off. Like this... "rs_stats 0". That's it, i'm tired. I hope you understand my english is not good, but the code works.

"That's it... This chat is over!!!"

Insanelazarez.

Personal tools