ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Modify fighting distance between actor and ennemies

1 2 3 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  20:17:19  28 January 2013
profilee-mailreply Message URLTo the Top
Belasco1968
(Novice)
 
On forum: 01/28/2013
 

Message edited by:
Belasco1968
01/28/2013 20:19:22
Messages: 13
Modify fighting distance between actor and ennemies

Hello everyone !

Since last year, I’m busy to modify the Complete 2009 mod to integrate the elements from other mods which interest me.

I’m a noob but I always try to understand the code of all these modders. So, I can modify existing code but not create a brand new one.

All is ok for my game: money and corpse looting, flamethrower, minigun, blowout, repair kit with limitation, hud for suits, free choice for the wishes, …

But I have a last problem…

I would like to modify the behavior of the npc’s according to the suit which the actor wears.

There is a special suit in the DMX mod (the meceniy outfit) and I integrated it in my mod.
But … it’s only a visual effect.

My wish is to modify the “distance to fight” for the npc’s when the actor wears this suit.
The player could approach the enemies within a certain distance (eg : 16 meters) without enemies detect him.
I wish only ‘play’ with the ‘see actor’ aspect and not with the ‘noise’ aspect. You can be ‘invisible’ but you make always so much noise.

So, my idea is doing a script file wich contains something like :

function name_function()

local actor = db.actor
local outfit_act = db.actor:item_in_slot(6)
If outfit_act:section()=="meceniy_outfit_new" then
If enemy: position():distance_to_sqr(npc: position()) >= 16
local enemy = db.storage[npc:id()].enemy
return enemy:id() == actor:id()
end
else
If enemy: position():distance_to_sqr(npc: position()) < 16
local enemy = db.storage[npc:id()].enemy
return enemy and enemy:id() ~= actor:id()
end
else

If outfit_act:section()== nil or outfit_act:section()~="meceniy_outfit_new" then
local enemy = db.storage[npc:id()].enemy
return enemy:id() == actor:id()
end

end

Can someone tell me if this function is correct?
Do I also add a call to this function in the “bind_stalker” script ?

Thanks to all for your advice and/or correction !
  20:50:07  28 January 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
01/28/2013 20:56:49
Messages: 685
I made something similar.

class "relations"
function relations:__init()
	self.actor_prev_suit = ""
end

function relations:update()
	local suit_name = get_suit_stats("name") or "no_suit"
	if self.actor_prev_suit ~= suit_name then
		db.actor:set_character_community(system_ini():r_string("suit_by_community", suit_name), db.actor:id(), 0)
		self.actor_prev_suit = suit_name
	end
end

function get_suit_stats(indx)
	local suit = db.actor:get_current_outfit()
	if suit ~= nil then 
		if indx == "name" then
			return suit:section()
		elseif indx == "condition" then
			return suit:condition()
		end
	end
end

function change_community()
        return relations:update()
end



Call from outside will be

local suit_comm = {script_name}.change_community()
if suit_comm == nil then printf("Naked actor detected.:-D") end --Just a joke



In the ltx file I have the suits listed.

;; relation settings for suit to community ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[suit_by_community]
novice_outfit			= actor
stalker_outfit			= actor
svoboda_light_outfit	= freedom
dolg_outfit				= dolg
scientific_outfit		= ecolog
cs_heavy_outfit			= freedom
svoboda_heavy_outfit	= freedom
specops_outfit			= military
military_outfit			= military
dolg_heavy_outfit		= dolg
exo_outfit				= stalker
no_suit					= actor

;SoC suits
bandit_outfit			= bandit
protection_outfit		= ecolog
dolg_scientific_outfit	= dolg
monolith_outfit			= monolith
killer_outfit			= killer
ecolog_outfit			= ecolog
military_stalker_outfit	= military
military_commander_outfit = military
soldier_outfit			= miltary

The entries in the LTX are "outfit" = "community".

It's working pretty good in my mod project.
The only hope I have, I didn't miss something as I was extracting this from my mod project.
  18:05:27  30 January 2013
profilee-mailreply Message URLTo the Top
Belasco1968
(Novice)
 
On forum: 01/28/2013
Messages: 13
Hello Mister Thunderfreak !

What a pleasure to read you

I used a mix of your hud.ltx en atmen.ltx for my game.
And it's great

I had the same idea than yours about the relation system between the suit player wears and the community 'of this suit'.

But, with this system, the reaction of the npc's isn't the one I want.
In this configuration, the player is neutral (or friend) with the faction.
So, the player can approach the 'enemies' and self talk to them.

In my idea, wearing a specific suit (so, only this suit) the player is not detectable by enemies (or neutral, friends) except on a certain distance (5 of 10 meters). Then, the npc's can interact again with the player (enemies attack, friends can talk, ...).

Can you say me what you think about my code.
I only know that he doesn't work
If I add a call to function 'name_of_my_ltxfile.name_function' in the bind_stalker.ltx under 'actor_binder:update(delta)', the game crash and the log talk about 'a nihil value'.
So, this is not a good way.

Would you be willing to send me by email a sample of your files about your system of relation between communities and suits ?

I'd like to try to make some changes. Maybe I'll get a result that satisfies me...

Thank for all !
I am very impressed by your job
  19:28:55  30 January 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
01/30/2013 19:50:04
Messages: 685
In my script for the relations, I make the actor member of this faction where the suit is from. This means that friends to this particular faction will be friends to the actor as well unless the actor is changing his suit then it can be that your "friends" now turn to "enemies" immediately.
This system is good for stealth and sneak tasks.

If you like I make a package with the suit relation scripts for you.

I am sorry to say but the function you put in your first post cannot work at all.

I try to get it running for you.

/EDIT:
Check this out.

function name_function(npc_id)
	local enemy = db.storage[npc_id].enemy
	if IsStalker(enemy) == false or npc_id == nil then return end
	local actor = db.actor
	local outfit_act = actor:get_current_outfit()
	if outfit_act:section() == "meceniy_outfit_new" then
		if distance_between(db.actor,enemy) >= 16 then
			return true					-- returns 'true' when distance is more or equal to 16
		end
	end
	return false						-- returns false when distance below 16
end

To call this function from bind_stalker.script file you have to put this line into the function actor_binder:update(delta) of the bind_stalker file.

name_function(self.object:id())

  20:31:25  30 January 2013
profilee-mailreply Message URLTo the Top
Belasco1968
(Novice)
 
On forum: 01/28/2013
 

Message edited by:
Belasco1968
01/30/2013 20:59:46
Messages: 13
Hello Thunderfreak !

Yes, sure !
I'm always interested to acquire new knowledges, so your files are welcome.
I think that the only way to acquire a little bit more experience is to analyze and understand the codes of good developers.
So, thank you in advance for your files.

For my idea of code, don't be sorry
It was just a little bit of this and that to show what I wish to make.
As I said in my post: I'm just a noob and ... a old man (45 years next month. Pfffff... Hey, but playing Stalker made younger!).

For my code, your help is also welcome !

Once I have finished the mod, I'll upload it with all explainations.
I am busy writing a sort of manual in French (currently 10 pages without screenshots) of all changes included in my version (based on Complete 2009 for the game in French).
As the players whose first language is French, can understand and reproduce much of the mechanics of the game and create their own version. Like this, everyone will have his pleasure.

Good evening


I just tested your code.

1 file (meceniy_work.ltx) with

function stealthy_approach(npc_id)

local enemy = db.storage[npc_id].enemy
if IsStalker(enemy) == false or npc_id == nil then return end
local actor = db.actor
local outfit_act = actor:get_current_outfit()
if outfit_act:section() == "meceniy_outfit_new" then
if distance_between(db.actor,enemy) >= 16 then
return true -- returns 'true' when distance is more or equal to 16
end
end
return false -- returns false when distance below 16
end

And, in de bind_stalker:

function actor_binder:update(delta)
object_binder.update(self, delta)

-- DEBUG slowdown
-- slowdown.update()
hud.checkmysuithud()
hud.atmen() You see ! I'm using your work
meceniy_work.stealthy_approach(self.object:id())
blowout.GetBlowout():Update()
local time = time_global()

game_stats.update (delta, self.object)

-- àïäåéò ïîãîäû
self.weather_manager:update()

-- àïäåéò ñõåìû äåòåêòîðà
self.actor_detector:update() ..................

When I load my seved game: crash

Error log:

Expression : fatal error
Function : CScriptEngine::lua_error
File : E:\stalker\sources\trunk\xr_3da\xrGame\script_engine.cpp
Line : 73
Description : <no expression>
Arguments : LUA error: ...ow of chernobyl\gamedata\scripts\bind_stalker.script:239: attempt to index global 'meceniy_work' (a nil value)

If I only write 'stealthy_approach(self.object:id())' in the bind_stalker, I got the same error log but with '....\bind_stalker.script:239: attempt to index global 'stealthy_approach' (a nil value).

Am I wrong ?

Also another question about your code:

Your code check only if ennemies are in certain distance (>= 16 m of < 16m). Ok, I understand.
But, there is no reference to a "see or not see the player" (and so, there will be no reaction from the npc's).
Is it right ?
  22:32:41  30 January 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
You are talking about old men at an age of 45? I am already 55.

Where did you put the function stealthy_approach()? Into the bind_stalker.script or referring to your post in the file meceniy_work.script?

And yes this function is checking only if enemies are in a certain distance like your code tried to do as well.

If this code is part of a bigger script then call for the script isn't in the right place. Then I need your scripts to give you the right position for the call.
  00:19:36  31 January 2013
profilee-mailreply Message URLTo the Top
Vintar
a bit of this and a lot of that
(Resident)

 

 
On forum: 08/08/2008
Messages: 6349
probably the problem is here

---QUOTATION---
1 file (meceniy_work.ltx) with
---END QUOTATION---

  06:51:29  31 January 2013
profilee-mailreply Message URLTo the Top
Belasco1968
(Novice)
 
On forum: 01/28/2013
Messages: 13
I simply create a scrip file (.ltx) in the folder 'gamedata->scripts'.
This file is called 'meceniy_work.ltx'.
This file contains the following code:
function stealthy_approach(npc_id)

local enemy = db.storage[npc_id].enemy
if IsStalker(enemy) == false or npc_id == nil then return end
local actor = db.actor
local outfit_act = actor:get_current_outfit()
if outfit_act:section() == "meceniy_outfit_new" then
if distance_between(db.actor,enemy) >= 16 then
return true -- returns 'true' when distance is more or equal to 16
end
end
return false -- returns false when distance below 16
end

I also add a call to this function in the file 'bind_stalker', just under function actor_binder:update(delta)
object_binder.update(self, delta)
like this : 'meceniy_work.stealthy_approach(self.object:id())'

And then, on loading saved game: see my error log.

So, what do I wrong ?
  07:30:56  31 January 2013
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
Messages: 2230
rename it .script.
  07:10:19  1 February 2013
profilee-mailreply Message URLTo the Top
Belasco1968
(Novice)
 
On forum: 01/28/2013
Messages: 13
Hello Alundaio !

Yes, you'r right.

Sorry. I'm totally stupid

The error log don't appear again.


The problem is not solve.

This what I made:

1° Create un file 'meceniy_work.script' with the following code:

function stealthy_approach(npc_id)

local enemy = db.storage[npc_id].enemy

if IsStalker(enemy) == false or npc_id == nil then
return end
-- check for enemies only--

local actor = db.actor
local outfit_act = actor:get_current_outfit()

if outfit_act:section() == "meceniy_outfit_new" then
-- player wears this camouflage suit--
bind_stalker.hide_weapon()
-- player cannot equip weapons because he wears a camouflage suit--
if distance_between(db.actor,enemy) >= 16 then
-- if distance between player and ennemies is >= 16 meters--
xr_conditions.dont_fighting_actor(db.actor, enemy)
-- then player is 'undectable' and enemies don't attack him--
end
else
-- otherwise--
if distance_between(db.actor,enemy) < 16 then
-- player wears the camouflage suit but distance between him and ennemies is < 16 meters--
xr_conditions.fighting_actor(db.actor, enemy)
-- then the player is 'detected' and enemies attack him
end--
else
If outfit:section()== nil or outfit:section() ~="meceniy_outfit_new" then
-- player wears no suit of a different suit than the camouflage suit--
bind_stalker.restore_weapon()
-- player can equip weapons--
xr_conditions.fighting_actor(db.actor, enemy)
-- then enemies attack the player--
end
end

2° I add the line 'meceniy_work.stealthy_approach' in de bind_stalker file, under the function 'actor_binder:update(delta)'.


Result: on the game load, crash.

This time, the error log is: "..... Arguments : LUA error: ...ow of chernobyl\gamedata\scripts\bind_stalker.script:239: attempt to index global 'meceniy_work' (a nil value)"

I suppose that's in relation withe these lines 'xr_conditions.fighting_actor(db.actor, enemy)' but I don't see how to write this part.

Any idea ??
 
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.