ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Remove an object item in a task or dialogue script?

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  20:02:06  23 July 2019
profilee-mailreply Message URLTo the Top
soopytwist
Senior Resident
 

 
On forum: 03/30/2010
Messages: 447
Remove an object item in a task or dialogue script?

How do I remove an item from the player's inventory in a task or dialogue script but only if the player actually has the item?

I can remove an item in dialogue but if the player doesn't have it the game will crash.
  02:19:30  6 August 2019
profilee-mailreply Message URLTo the Top
NatVac
Senior Resident
 

 
On forum: 06/15/2007
 

Message edited by:
NatVac
08/07/2019 7:57:18
Messages: 4265
I take it you have an <action> element in your dialog's XML that removes an item. You need a <precondition> element that checks for the item. Something like <precondition>xr_conditions.has_my_custom_item</precondition> will work, when you add the support function has_my_custom_item() in xr_conditions.script that looks similar to this:

function has_ghost_pda ()
	return db.actor:object ("yantar_ghost_pda") ~= nil
end

Just use the same otherwise-unique function name in both places for has_ghost_pda, and replace yantar_ghost_pda with your item's section name.

Note that the <precondition> for the item will mean that if it is not there, you won't see the dialog option which, when clicked, would remove the item from the game. So keep your game from crashing by having other dialog elements for that particular dialog branch.

Study other dialogs where the game checks for items or info_portions with <precondition> checks, and observe how the game handles the situation regardless of the presence of the condition.

Update: That function is an example in the game, even though it is not used in vanilla.
  16:30:52  6 October 2019
profilee-mailreply Message URLTo the Top
soopytwist
Senior Resident
 

 
On forum: 03/30/2010
Messages: 447
My apologies, had to abandon this game to deal with some shit. Now I'm back modding.

Thanks NatVac, this works in dialogue but how do I get it to work for tasks? i.e my goal is to remove the bad_psy_helmet when the player takes the good_psy_helmet from the dead scientist under the waterdam (country). Otherwise the player is stuck carrying around the bad psy helmet for the rest of the game because it's a quest item.
  11:15:46  19 October 2019
profilee-mailreply Message URLTo the Top
NatVac
Senior Resident
 

 
On forum: 06/15/2007
Messages: 4265
You could add a check for the good_psy_helmet object in the bind_stalker.script's actor_binder:on_item_take() function. If you find one, then check for the bad_psy_helmet object. If there is one, remove it via alife():release(), similar to this:
__________
  if obj:section()=="good_psy_helmet" -- just picked up the good psi protection
    local bad_helmet = db.actor:object("bad_psy_helmet")
    if bad_helmet ~= nil then
      alife():release(alife():object(bad_helmet:id()), false)
    end
  end

__________

Note that on_item_take() calls level_tasks.proceed(), which can be used to complete a task on the level where you expect the task to be completed. Putting the code in the corresponding *_tasks.script would save some checking on other levels every time you transfer something to your inventory. Keep in mind that the code would need to change to use a different way to check the object, as it is not properly handled; bind_stalker's function passes the object parameter but the level_task function doesn't have it, so maybe you might be able to test for db.actor:object("good_psy_helmet") as well as the bad one in your *_tasks.script's proceed() function.
 
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.