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

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  03:11:56  21 April 2021
profilee-mailreply Message URLTo the Top
notanumber
mod abuser & exploiter
(Resident)

 

 
On forum: 03/22/2008
Messages: 2832
Detection of hostile NPCs

Is there any way to check a server object if it is an NPC that is hostile to the player and mark it on both the level map and the minimap?

By "hostile" I mean: Will attack the player on sight.

Bonus question: Is there a way to do the same in Call of Pripyat? (I tried asking in CoP section but got no response).
  04:30:57  21 April 2021
profilee-mailreply Message URLTo the Top
notanumber
mod abuser & exploiter
(Resident)

 

 
On forum: 03/22/2008
 

Message edited by:
notanumber
04/21/2021 4:38:33
Messages: 2832
I currently use the following code which only works partially and is not very pretty:
-- Dictionary with each faction's attitude (a number between -1000 and 1000) towards the player.
local actor_relations = {} 

-- Populates actor_relations[] with current faction attitudes. Called on game load.
function init()
    ocal comm_index = {}
    local comm_relations = {}
    local value = system_ini():r_string("game_relations", "communities")
    for id in string.gmatch(value, "([%w_-]+),%s*%d+") do
        table.insert(comm_index, id)
    end
    local n = system_ini():line_count("communities_relations")
    for i = 0, n - 1 do
        local reltbl = {}
        local idx = 0
        local result, id, value = system_ini():r_line("communities_relations", i, "", "") 
        for num in string.gmatch(value, "[%d-]+") do
            idx = idx + 1
            reltbl[comm_index[idx]] = tonumber(num)
        end
        if idx > 0 then
            comm_relations[id] = reltbl
        end
    end
    local actor_community = db.actor:character_community()
    for k, v in pairs(comm_relations) do
        actor_relations[k] = comm_relations[k][db.actor:character_community()]
                           + relation_registry.community_goodwill(k, db.actor:id())
    end
end

. . .

-- Returns true if obj is hostile.
-- Parameter obj must be a stalker.
local function is_enemy(obj)
    local lobj = level.object_by_id(obj.id)
    if lobj then
        return lobj:relation(db.actor) == game_object.enemy
    end
    return obj.community and actor_relations[obj:community()] <= -500
end



Then I use the following code to mark it on the map and minimap for the object:
level.map_add_object_spot(obj.id, "notanumber_red_dot", obj:section_name())



The XML that I added in map_spots.xml
<notanumber_red_dot>
    <level_map spot="notanumber_red_dot_spot"/>
    <mini_map spot="notanumber_red_dot_spot"/>
</notanumber_red_dot>
<notanumber_red_dot_spot x="0" y="0" width="3" height="3" scale="1" stretch = "1" alignment="c">
    <texture r="255" g="0" b="0">ui_minimap_point</texture>
</notanumber_red_dot_spot>

 
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-2021 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.