ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Clear Sky Forum » Mod discussion
Geting npc visual and forcing npc into animation.

1 2 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  06:02:22  22 August 2013
profilee-mailreply Message URLTo the Top
Reisen
(Novice)
 
On forum: 02/09/2012
Messages: 26
Geting npc visual and forcing npc into animation.

I am looking for a way to get npc's visual (outfit).
I read about function "get_visual_name()" but it was added only in CoP.
I read something about getting visual with net packets but cant understand how its done.

Another thing is, I need to force npc into animation.
The problem is that, npc wont go into animation probably because its being overridden by something with more priority.
Even if animation start playing npc instantly goes back to what it was doing.
Any way to force npc into animation without him leaving it no matter what?
  14:36:21  22 August 2013
profilee-mailreply Message URLTo the Top
smoq2
Forklift operator
(Resident)

 

 
On forum: 09/08/2008
Messages: 2433
You cannot force an NPC to play any animation without implementing a whole new AI module, which is basically an action it will perform when certain conditions are met.

I think AI is the most difficult task when it comes to scripting, so I suggest downloading a simple mod that allows NPCs to pick up items, and see how it is done. I can't seem to find it anymore though.

As for getting a visual, google packet_utils21.script. It is my version of packet utils, adapted to CS (since the original didn't work for CS). Then use this

local data = packet_utils.21.get_object_data(npc:id())
local model = data.visual_name

The "model" var will contain the path to the NPCs mesh.
  16:19:48  22 August 2013
profilee-mailreply Message URLTo the Top
Reisen
(Novice)
 
On forum: 02/09/2012
 

Message edited by:
Reisen
08/22/2013 16:23:33
Messages: 26
Google returned only one page with 6 results on packet_utils21.script and Bing return only two results.
Searched this forum and the only links I found mediafire and sendspace were dead.
Can you reupload it?

Also, I am trying to get weapon of the npc that shoot someone, any idea whats wrong with this approach?

local shooter = obj:who_hit_name() --/Works fine
local weapon = shooter:active_item() --/adding this line causes ctd for asigning shooter a nil value.

I know active_item() works fine on npc because I used it to make npc drop weapon when shot in hand, why doesnt it work here?
  16:34:56  22 August 2013
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
Messages: 129

---QUOTATION---
local shooter = obj:who_hit_name() --/Works fine
local weapon = shooter:active_item() --/adding this line causes ctd for asigning shooter a nil value.

---END QUOTATION---


That's your answer, shooter is nil. And most likely who_hit_name() doesn't work, it probably always returns nil.
It's never used in vanilla scripts, so there wasn't need to make it work.
  16:50:37  22 August 2013
profilee-mailreply Message URLTo the Top
Reisen
(Novice)
 
On forum: 02/09/2012
 

Message edited by:
Reisen
08/22/2013 16:52:01
Messages: 26

---QUOTATION---

That's your answer, shooter is nil. And most likely who_hit_name() doesn't work, it probably always returns nil.
---END QUOTATION---


Thats why I noted that it works fine.
When I test it via

say = shooter
news_manager.send_tip(db.actor, say, nil, nil, 2000)


It prints single_player if I shoot someone and if someone being shoot by someone else, it prints stuff like agr_bar_stalker_121249, sim_default_duty_121110 so it certainly knows who shot who.
Its when I add local weapon = shooter:active_item() I get ctd for assigning shooter a nil value.
  17:09:06  22 August 2013
profilee-mailreply Message URLTo the Top
smoq2
Forklift operator
(Resident)

 

 
On forum: 09/08/2008
 

Message edited by:
smoq2
08/22/2013 17:10:08
Messages: 2433
I'll upload the scripts later today then.

If you want to get the NPC who shot and hit another NPC, it is best to use this method:

Search for a function called hit_callback in sim_combat.script.

Add your function there, e.g:

my_script.my_hit_callback(victim_id, attacker_id)

Then create a script called e.g. "my_script" this:


local t = {}

function my_hit_callback(victim_id, attacker_id)
	local attacker = level.object_by_id(attacker_id)
        if IsStalker(attacker) or IsMonster(attacker) then
	       t[victim_id] = attacker
        end
end

function who_hit_npc_last(npc_id)
	return t[victim_id]
end



Calling my_script.who_hit_npc_last(argument with npc's id) will return the object that last hit the NPC. Until you reload your game or change level that is, cause that's when all the gathered data is lost.
The method is far from optimal, but will get you started and on the right track.

If you want to get the weapon an NPC is carrying you need to do this:

function get_weapon(npc_id)
	local npc = level.object_by_id(npc_id)
	local active_item = npc:active_item()
	if npc ~= nil and isWeapon(active_weapon) then
		return active_item
	end
end


However, it's up to you to use the script correctly and not provide npc ids that are offline or nonexistent.
  17:22:55  22 August 2013
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
Messages: 129
Ah, sorry. Should have occurred to me, you get a string back not an userdata(/luabind) object (of type game_object). And strings don't have an active_item function, that's the reason for crashing.

As for what you're trying to accomplish, smog2 knows more than me. Though be advised callbacks for things like being 'hit' have a high chance of firing a lot.
LuaJIT is pretty fast, but still too slow to make that even seem reasonable.
  18:16:49  22 August 2013
profilee-mailreply Message URLTo the Top
Reisen
(Novice)
 
On forum: 02/09/2012
 

Message edited by:
Reisen
08/22/2013 18:19:21
Messages: 26

---QUOTATION---
If you want to get the NPC who shot and hit another NPC, it is best to use this method:

---END QUOTATION---


I am trying to process this so I get back to you later, I hope I manage it.

---QUOTATION---
Search for a function called hit_callback in sim_combat.script.
---END QUOTATION---


By the way, I am adding all my scripts in function motivator_binder:hit_callback...
in xr_motivator.script, do you think it can create difficulties in the future?

---QUOTATION---
Ah, sorry. Should have occurred to me, you get a string back not an userdata...
---END QUOTATION---


So thats the reason... Thanks for explaining.

---QUOTATION---

As for what you're trying to accomplish, smog2 knows more than me...
LuaJIT is pretty fast, but still too slow to make that even seem reasonable.
---END QUOTATION---


Actually its not that bad, I am running scripts called on hit, detecting where bullet hit and depending on it causing additional damage, randomly ricocheting or causing npc to drop weapon, even if its slow as you say its fast enough to manage it.

Now I am trying to add physical damage from bullet which didnt pierce the bulletproof vest but still caused damage by impact (damage will wary depending on armor) so I need to get the victim armor, attacker ID and weapon used in one hit callback.
  19:46:05  22 August 2013
profilee-mailreply Message URLTo the Top
Xetrill
(Senior)
 
On forum: 07/08/2008
 

Message edited by:
Xetrill
08/22/2013 20:11:51
Messages: 129

---QUOTATION---
Actually its not that bad, I am running scripts called on hit, detecting where bullet hit and depending on it causing additional damage, randomly ricocheting or causing npc to drop weapon, even if its slow as you say its fast enough to manage it.
---END QUOTATION---


I don't doubt that, and I don't mean to discourage you, not at all. Though, the thing is - generally speaking - Lua isn't the tool you'd use for that. If possible, you'd use C++ for anything that has the potential to causing hundreds on checks per second.
Because you'd have to make sure you can render a frame in 16.67ms (=60fps), and of course
things add up. But well, nothing we could do about that. Unless, GSC/Vostok Games release the source code...


---QUOTATION---
... so I need to get the victim armor, attacker ID and weapon used in one hit callback.
---END QUOTATION---


And ammo type used (k_impulse & k_ap), and you'll probably want to use each weapons hit_impulse value as a baseline, I guess.

Edit: I can offer you too look over your code and maybe we can squeeze out bit more throughput. Now though, it's time to lift some weights .
  21:18:21  22 August 2013
profilee-mailreply Message URLTo the Top
Reisen
(Novice)
 
On forum: 02/09/2012
 

Message edited by:
Reisen
08/22/2013 21:28:29
Messages: 26

---QUOTATION---

And ammo type used and you'll probably want to use each weapons hit_impulse value as a baseline, I guess.
---END QUOTATION---


Actually I just want to divide weapons in 3-4 general groups, 1 - handguns, 2 - machine pistols, 3 - assault riffles, 4 - sniper riffles (or just heavy stuff).

Now, if npc wears bullet proof vest of second class and gets shot with pm (first group), while vest wont get pierced, npc will still fall on the ground after approximately 5 shots (as kevlar wont protect from impact). Until armor is pierced by bullet he wont die (not fast at least) but will be injured.

Now npc who wears vest of fifth defence class wont go down from blunt trauma caused by pm, because its protected from it.
To inflict blunt trauma on person wearing this kind of vest, you will need something heavier, like ak47 (third group), while it might not penetrate the vest it will still inflict blunt trauma.
Its just approximation of what I am aiming for, question of balance left for later.

So it just checks, defence class of a vest (by visual), to which group weapon you used belong and decides what kind of blunt trauma it will cause. Weapons of low class wont cause much of blunt trauma on peoples wearing vest with high defence class.

Ammo piercing capabilities, vest defence and damage dealt by gun is already dealt with, this mod its just port of (very good) weapon system from "Difficult Zone Mod" to OGSM while trying to develop few ideas of my own like npc reaction to being shot in hands, legs, head and taking blunt trauma into consideration.


---QUOTATION---
I can offer you too look over your code and maybe we can squeeze out bit more throughput.
---END QUOTATION---


I would gladly accept help of someone who can help me with it, as for I am still trying to implement smoq2 script.

While I am dealing with it, here http://pastebin.com/MZZLdaSJ (ctrl+F Weapon Drop and Head Shot) you can see how I did with weapon drop script and script that calculates npc's odds of survival after shot in the head if bullet havent penetrated the helmet (though obviously it still should have made heavy damage due to blunt trauma).
As you can see there are left overs of my attempts to put npc into different states according to injury, those are not working.
 
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.: Clear Sky 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.