ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Calling Script Functions on Actor Firing Weapon

1 2 3 4 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  05:50:11  12 July 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454
Calling Script Functions on Actor Firing Weapon

Pretty much as the title says, I'd like to know if it's possible to trigger functions when the player shoots their gun. And hopefully, to detect only when a specific type of gun is fired.
Thanks in advance for your help!
  17:23:45  12 July 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
Messages: 867
The format might be a little wrong, but I'm pretty sure it's correct:

http://pastebin.com/eG9UgAGU

Only did the weapon firing part, didn't do specific weapons.

For this you will need packet_utils.script by Barin. It should be floating around this forum, just do a search.
  17:42:26  12 July 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
Messages: 1519

---QUOTATION---
Only did the weapon firing part, didn't do specific weapons.
---END QUOTATION---



Where did you hook this in? As there is AFAIK no callback function that automatically triggers when the weapon is fired. When you hook that code into bind_stalker.script Update function you have a noticeable delay between the moment the weapon is fired and that when the function is called. And using packet_util.script even increases that delay. When I did something similar I didn't manage to get the function called "immediately" what caused a somewhat weird behavior feeling.
  19:03:35  12 July 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
07/12/2013 19:10:12
Messages: 867

---QUOTATION---
Only did the weapon firing part, didn't do specific weapons.

Where did you hook this in? As there is AFAIK no callback function that automatically triggers when the weapon is fired. When you hook that code into bind_stalker.script Update function you have a noticeable delay between the moment the weapon is fired and that when the function is called. And using packet_util.script even increases that delay. When I did something similar I didn't manage to get the function called "immediately" what caused a somewhat weird behavior feeling.
---END QUOTATION---



I'm on COP of course, and for me it's hooked into a script which hooks it into _g.script function start_game_callback()

Not sure if this exists in SOC but I'll assume it does.

I'm no scripter so I don't understand why it would make a difference if you put it in bind_stalker update function but maybe it's because you're making the game call the update function every single time a weapon is fired, which I assume would cause performance issues.
Someone like NatVac would know for sure.

*Edit*
It also has this at the top of the example script I used this for (can't share the whole script as it's a Misery 2 script unfortunately, even though I don't think they're using it), but it also has the following at the top:


function on_game_start()
	callback_register("actor_on_update",update)
end



I have no idea what that does, but worth a try.

*Edit 2*
Also to clarify, I didn't actually test this script myself, I just copy/pasted from a script which does work and then modified it slightly to (hopefully) work in SOC.
  21:33:15  12 July 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
 

Message edited by:
TKGP
07/12/2013 21:33:51
Messages: 454
I must confess I'm very new to scripting so please bear with me, I'm sure there are some obvious things I'm missing.
I tried placing your code block in function actor_binder:update, which I assume is what Meltac was referring to. However I just end up with

LUA error: ...ow of chernobyl\gamedata\scripts\bind_stalker.script:216: attempt to index global 'wpn' (a nil value)


where line 216 is

local se_wpn = alife():object(wpn:id())

  21:42:04  12 July 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
07/12/2013 21:43:11
Messages: 867

---QUOTATION---
I must confess I'm very new to scripting so please bear with me, I'm sure there are some obvious things I'm missing.
I tried placing your code block in function actor_binder:update, which I assume is what Meltac was referring to. However I just end up with

LUA error: ...ow of chernobyl\gamedata\scripts\bind_stalker.script:216: attempt to index global 'wpn' (a nil value)


where line 216 is

local se_wpn = alife():object(wpn:id())


---END QUOTATION---



That's okay, my bad.


local wpn = db.actor:active_item()
wpn = packet_utils.item_is_fa(wpn) and wpn



at the top, but add this to packet_utils.script first:

http://pastebin.com/v8tke3Mj

Since I'm not actively modifying it in SOC I have no idea if it works correctly or not, I'm just making assumptions, and I'm no scripter either.
  22:03:41  12 July 2013
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
 

Message edited by:
TKGP
07/12/2013 22:04:07
Messages: 454
Hmm. First there was a crash in item_is_fa but that turned out to just be because there's no auto shotgun in SoC, commented that line out and it seems to be fine. Now we get

LUA error: ...ow of chernobyl\gamedata\scripts\bind_stalker.script:218: attempt to index local 'wpn' (a boolean value)



My block in bind_stalker reads like this

function actor_binder:update(delta)

	local wpn = db.actor:active_item()
	wpn = packet_utils.item_is_fa(wpn) and wpn
	local se_wpn = alife():object(wpn:id()) --this is line 218
	local data = packet_utils.state_read(se_wpn)
	if (data.weapon_state == 5) then
		spawn_at_actor.spawn_bolts()
	end

  01:56:50  13 July 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
Messages: 867
I'm pretty sure you should be referring to an external script rather than putting it directly in bind_stalker, however I'll let someone who knows how to script take it from here.
  02:45:01  19 July 2013
profilee-mailreply Message URLTo the Top
gannebamm
has abondened XRay and uses Unity3D now
(Resident)

 

 
On forum: 05/02/2007
 

Message edited by:
gannebamm
07/19/2013 2:45:16
Messages: 1077
http://pastebin.com/2ubBcscg

never understood what this

myVar = myFunc() and myOtherVar


is actually doing exactly...
  02:53:27  19 July 2013
profilee-mailreply Message URLTo the Top
gannebamm
has abondened XRay and uses Unity3D now
(Resident)

 

 
On forum: 05/02/2007
Messages: 1077

---QUOTATION---
Only did the weapon firing part, didn't do specific weapons.

Where did you hook this in? As there is AFAIK no callback function that automatically triggers when the weapon is fired. When you hook that code into bind_stalker.script Update function you have a noticeable delay between the moment the weapon is fired and that when the function is called. And using packet_util.script even increases that delay. When I did something similar I didn't manage to get the function called "immediately" what caused a somewhat weird behavior feeling.
---END QUOTATION---


I´ve done this with various stuff in COP and never had a noticable delay. I hooked it into actors update function and used packet utils.
It worked very good for the horn feature from the gritty zone and the mutant loot (in which you actually have to slash the mutant with your knife weapon to get parts) mechanic I designed and tested with 3ncryptabl3. You have to be carefull to not fire expensive stuff with every update since this would slow down the game at a whole but other than that it is fine.
The very old "actor hit and has chance to get a camera shake / loose his weapon" feature is built with an fake callback through actor update, too.
 
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.