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

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  02:29:15  29 January 2013
profilee-mailreply Message URLTo the Top
FatalFunnel
(Senior)
 
On forum: 11/07/2011
 

Message edited by:
FatalFunnel
01/29/2013 2:30:27
Messages: 133
Scripting question.

So right now I'm trying to come up with a modification of the existing medical system, what I'm trying to do, and to some extent what this script does accomplish is spawn items in the actors inventory when medkits are used.

The basic script that I started with looks like this.


function spawn_medical_set()
   local obj
   if db.actor:object("medkit") then 
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
   end
   if db.actor:object("medkit_army") then 
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
	  amk.spawn_item_in_inv("saline")
	  amk.spawn_item_in_inv("painkiller")
	  amk.spawn_item_in_inv("zeolite")
	  amk.spawn_item_in_inv("steroid")
   end
   if db.actor:object("medkit_scientic") then
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
	  amk.spawn_item_in_inv("saline")
	  amk.spawn_item_in_inv("painkiller")
	  amk.spawn_item_in_inv("p-iodine")
	  amk.spawn_item_in_inv("cblb502")
   end
end



It's very simple, but I'm encountering two main problems with it. one is that even the orange medkits will spawn the items of the blue ones, and the other bug I've encountered with it is that the items spawned from medkits will duplicate each other when used.

So with all that said, I'm trying to re-structure the script, by:

A. splitting the functions for each different medkit. (Let me know if this is an inefficient way of doing this.
B. Having a header part of the script that calls these functions, (and is the portion called in bind_stalker.script under function actor_binder:use_object(obj))

So, my current script looks like this, the header is commented out since it presently doesn't work, but what its supposed to do is call the specific names of the items, then refer to its respective script function.



--function spawn_medical_supplies(obj)
--   local obj_section = obj:section()
--   end
--   if obj_section == "medkit" then
--      zoa_medkit.spawn_medical_set1()
--   elseif obj_section == "medkit_army" then
--      zoa_medkit.spawn_medical_set2()
--   elseif obj_section == "medkit_scientic" then
--      zoa_medkit.spawn_medical_set3()
--   end
--end


function spawn_medical_set1()
   local obj
   if db.actor:object("medkit") then 
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
   end
end

function spawn_medical_set2()
   local obj
   if db.actor:object("medkit_army") then 
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
	  amk.spawn_item_in_inv("saline")
	  amk.spawn_item_in_inv("painkiller")
	  amk.spawn_item_in_inv("zeolite")
	  amk.spawn_item_in_inv("steroid")
   end
end

function spawn_medical_set3()
   local obj
   if db.actor:object("medkit_scientic") then
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
	  amk.spawn_item_in_inv("saline")
	  amk.spawn_item_in_inv("painkiller")
	  amk.spawn_item_in_inv("p-iodine")
	  amk.spawn_item_in_inv("cblb502")
   end
end




I guess what I'm trying to do here is ask for pointers regarding LUA syntax for how the first part should be written.
  09:34:01  29 January 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
01/29/2013 9:34:42
Messages: 685
When searching actors inventory I would suggest to use this function db.actor:inventory_for_each(...).

db.actor:inventory_for_each(
	function (item)
		if item:section() == search_item then 
			obj = item 
		end
	end
)


Where 'search_item' is the item you are searching for in actor's inventory:
  20:20:09  29 January 2013
profilee-mailreply Message URLTo the Top
FatalFunnel
(Senior)
 
On forum: 11/07/2011
Messages: 133

---QUOTATION---
When searching actors inventory I would suggest to use this function db.actor:inventory_for_each(...).

db.actor:inventory_for_each(
	function (item)
		if item:section() == search_item then 
			obj = item 
		end
	end
)


Where 'search_item' is the item you are searching for in actor's inventory:
---END QUOTATION---



Thanks, but I got this working, I eliminated the db.actor portion entirely, it now looks like this:


function spawn_medical_supplies(obj)
   if obj:section()=="medkit" then --plain medkit
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
   elseif obj:section()=="medkit_scientic" then --scientific medkit
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
	  amk.spawn_item_in_inv("saline")
	  amk.spawn_item_in_inv("painkiller")
	  amk.spawn_item_in_inv("p-iodine")
	  amk.spawn_item_in_inv("cblb502")
   elseif obj:section()=="medkit_army" then --army medkit
	  amk.spawn_item_in_inv("hemostat")
	  amk.spawn_item_in_inv("antiseptic")
	  amk.spawn_item_in_inv("gauze")
	  amk.spawn_item_in_inv("sutures")
	  amk.spawn_item_in_inv("saline")
	  amk.spawn_item_in_inv("painkiller")
	  amk.spawn_item_in_inv("zeolite")
	  amk.spawn_item_in_inv("steroid")
   end 
   return true 
end 



By the way, do you know of a vanilla spawn in inventory function?

I'd like to make a port of this medical system to vanilla.


The way it works is that each type of medkit now spawns different medical items, these items are the components of the medkit itself, which now has no properties, other than spawning the contents within.

The medkits themselves are not hotkey-able, but the items they spawn are. This requires the actor to prepare medkits before battle in order to heal himself. It also allows for them to be used as storage, or to be left unused in the inventory if the component items are used.
  20:54:38  29 January 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
I made something similar for the Redux2 mod. You have a food package and when opening several food items appear in actors inventory.

This the function to spawn items into actor's inventory.
alife():create(item,db.actor osition(),db.actor:level_vertex_id(),db.actor:game_vertex_id(),db.actor:id())
Or did I get you wrong?
  21:36:41  29 January 2013
profilee-mailreply Message URLTo the Top
FatalFunnel
(Senior)
 
On forum: 11/07/2011
Messages: 133

---QUOTATION---
I made something similar for the Redux2 mod. You have a food package and when opening several food items appear in actors inventory.

This the function to spawn items into actor's inventory.
alife():create(item,db.actor osition(),db.actor:level_vertex_id(),db.actor:game_vertex_id(),db.actor:id())
Or did I get you wrong?
---END QUOTATION---



Nice, I'll put this info somewhere for when I work on a standalone variant.

That food package idea sounds pretty good, I'm glad that someone has come up with the same principle based on similar mechanics.
  05:01:36  21 February 2013
profilee-mailreply Message URLTo the Top
FatalFunnel
(Senior)
 
On forum: 11/07/2011
Messages: 133
This system is all fine and dandy but I've got one problem with it, aside from task-specific instances like saving Tolik with a medkit, I can't seem to be able to heal NPCs with medkits when they ask for one.

I suppose this has to do with the medkits now having no beneficial properties, and merely used to spawn items into the actor's inventory.

Does anyone know what script looks for what medkits the NPCs need?

I am guessing it is xr_wounded, and is there any way I can make it so that the actor giving them his medkits will exchange them for a second type of medkit to heal the NPCs? Which would basically be a copy with the original configs that only NPCs use and can't trade.

Something with logic like:

NPC needs medkit, looks to see if actor has medkit, spawn second type of medkit, heal NPC with it, destroy actor's original medkit, done.
  08:06:07  5 March 2013
profilee-mailreply Message URLTo the Top
NatVac
Senior Resident
 

 
On forum: 06/15/2007
Messages: 4286
Yes, Cwound_manager:eat_medkit() in xr_wounded.script has the info you need, FatalFunnel. In addition to eating (and thus destroying) the medkit, you can spawn and have them eat the right stuff. You could have *_npc versions that simply override the corresponding lack of healing with the original values:

At the bottom of misc\items.ltx:

[medkit_npc]:medkit
eat_health			= 0.6
wounds_heal_perc	= 0.3

[medkit_army_npc]:medkit_army
eat_health			= 1.0
wounds_heal_perc	= 1.0

[medkit_scientic_npc]:medkit_scientic
eat_health			= 1.0
wounds_heal_perc	= 0.3


... plus whatever else you changed.

You might have to jump through a couple hoops if the spawned medkit_npc is not immediately available for invoking the eat() function on it.
 
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.