ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Reading a gulag name from npc logic... to console

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  16:01:52  24 June 2018
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1071
Reading a gulag name from npc logic... to console

Hello stalkers.

I wonder how you guys are going.

I am creating new smart terrains, and everything is working good but i have one issue.
The idea is to force a npc from his logic (misc folder, ltx file), to tell the game console 2 things:

1- His npc name
2- The name of his smart terrain.

So for now i have this in logic file:


---QUOTATION---

; blablabla
on_info3 = {=see_actor} %+esc_peace_patrol_start%
on_info4 = %=identify%

---END QUOTATION---



In xr_effects.script:


---QUOTATION---

function identify(actor, npc)
if npc then
local identify_npc_name = npc:name()
local identify_npc_id = npc:id()

local strn_id = identify_npc_id:smart_terrain_id()

get_console():execute("StartLog"
get_console():execute("identify_npc_name:"..tostring(identify_npc_name))
get_console():execute("identify_npc_id:"..tostring(identify_npc_id))
--get_console():execute("ThisWillBeTheSmartName:"..tostring(strn_id))
get_console():execute("EndLog"
end
end

---END QUOTATION---




I got a error like "attempt to index local 'identify_npc_id' (a number value)"

Any idea? Thanks in advanced.
  17:53:22  24 June 2018
profilee-mailreply Message URLTo the Top
Decane
Senior Resident
 

 
On forum: 04/04/2007
 

Message edited by:
Decane
06/24/2018 17:58:55
Messages: 1690
You are trying to call a method (smart_terrain_id) on a number (identify_npc_id):

local strn_id = identify_npc_id:smart_terrain_id()

That won't work - methods need to be called on objects. In Lua, numbers are not objects. Furthermore, in Lua,

obj:method_name(...)

is just syntactic sugar for

obj.method_name(obj, ...)

Hence your error message telling you that you are trying to index (implicitly, using the "." operator; explicitly, using the ":" operator) a number value.

If you search lua_help.script, you can see which classes of object have method smart_terrain_id defined. You'll find cse_alife_human_stalker is one of them. Incidentally, that's the human server entity class, instances of which are returned by

alife():object(some_id)

So, you'll need code similar to the following to achieve what you want:

local strn_id = alife():object(identify_npc_id):smart_terrain_id()

  18:39:02  24 June 2018
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1071
Well Decane, thanks for the help. But the game is giving me a number instead of the smart name itself. And i need the smart terrain name. Any ideas?

Thanks Decane.
  22:31:28  24 June 2018
profilee-mailreply Message URLTo the Top
Decane
Senior Resident
 

 
On forum: 04/04/2007
Messages: 1690
If you look in smart_terrain.script, you can see that smart terrains just extend class cse_alife_smart_zone. Hence they inherit any methods defined in lua_help.script for that class. One such method is the name method - that sounds like what you want here.

The code I posted previously would get you the integer ID of the smart terrain. What you want is the server entity corresponding to that smart terrain ID, so that you can apply the name method to it. That will probably just get you the section name, though. To get a name converted to a natural language, like English, you can use the game.translate_string function on the returned name, like so:

local sim = alife()
local strn_name = game.translate_string(sim:object(sim:object(identify_npc_id):smart_terrain_id()):name())

Beware: You may need to add some sanity checks to this code.
  23:58:26  24 June 2018
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1071
[link]https://www.youtube.com/watch?v=R7bKLkB5Ffk&t=[/link]

It works decane, thanks man. Video is still processing, but somehow i think i messed up my settings.


Well, thanks again Decane.
 
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-2019 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.