Scripts / [SOLVED] How to activate entities when player make noise?

Author
Message
LeGugusse
17
Years of Service
User Offline
Joined: 15th Feb 2007
Location: Paris - France
Posted: 24th Aug 2021 12:05
Hi.
I would like to activate entities when the player makes some noise ( using a firearm by example) , so the alert is on and some soldiers can be activated.
It would be a way to force the player to use melee weapon if he doesn't want to have a lot of ennemies after him.

Do I need to use AIGetEntityHeardSound(AIObjNo)? And attach the script to an active object?
If so, where can I get the AIObjNo value?

Thank you for help and ideas.
Cry \"Havoc!\" and let slip the dogs of war

The author of this post has marked a post as an answer.

Go to answer
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Aug 2021 15:17 Edited at: 24th Aug 2021 15:18
This post has been marked by the post author as the answer.
g_Entity is the main global list of values for entities, e_Entity[e].obj gives you the object Id value.

A quick an dirty way of reacting to player gunfire is to use the global variable g_PlayerGunFired like this:



The dist value will cause this function to return true if the player is closer than that value or it will return true if the player fires and the entity is within 1000 units. Obviously you could tweak the 1000 part to suit.

To use:

if playerHeard( e, 100 ) then
--- do whatever ---
end

So in this example if the player is within 100 units or within 1000 and firing the weapon then the '-- do whatever --' part will be triggered.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 25th Aug 2021 09:24
note that g_PlayerGunFired will also trigger on melee weapons so you would want to add more checks to find out what type of weapon it is (checking the ammo count might be a good way as melee weapons should return a different value as they have unlimited ammo)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
LeGugusse
17
Years of Service
User Offline
Joined: 15th Feb 2007
Location: Paris - France
Posted: 25th Aug 2021 16:22
Thank you very much for your answers. I'll try this!
Cry \"Havoc!\" and let slip the dogs of war
PM
LeGugusse
17
Years of Service
User Offline
Joined: 15th Feb 2007
Location: Paris - France
Posted: 25th Aug 2021 17:03
SmallG, thank you again! It works very well!

I attached this script to an active barrel:




And when the player shoots, it activitates a bunch of patrol soldiers .
That's great!

Cry \"Havoc!\" and let slip the dogs of war
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 25th Aug 2021 18:16
don't thank me, amen gave the answer
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
LeGugusse
17
Years of Service
User Offline
Joined: 15th Feb 2007
Location: Paris - France
Posted: 26th Aug 2021 16:11
Oh yes, my mistake!
Thank you Amen!
Cry \"Havoc!\" and let slip the dogs of war
PM
LeGugusse
17
Years of Service
User Offline
Joined: 15th Feb 2007
Location: Paris - France
Posted: 26th Aug 2021 16:44
Now I want the player to use a silent weapon, like the Welrod.
The only idea I had for the moment (and it works) is to modify the noise detection script like that, using the variable g_PlayerGunName:

function detect_player_noise_init(e)
end



But I've seen in this forum that the variable soundstrength could be configured in the gunspec file. So maybe I could configure the silencing mode of the weapon in the gunspec file.
I've tried to put: "soundstrength=0" but it doesn't do anything.
The shot is still heard.
It could be interesting to have a real silencing gun feature...
Anyone has a idea to realise this?



Cry \"Havoc!\" and let slip the dogs of war
PM
LeGugusse
17
Years of Service
User Offline
Joined: 15th Feb 2007
Location: Paris - France
Posted: 26th Aug 2021 17:14
Again, I realized that if the ennemy shoots at me, it doesn't "wake up" the ennemys as no noise is heard.

So I added a global variable named "g_ennemyGunFired" and I modified:

- module_combatCore.lua like this:



and my detectNoise script like that:


Cry \"Havoc!\" and let slip the dogs of war
PM
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 30th Aug 2021 18:24
Thanks LeGugusse (and Amen Moses and smallg) Great scripts!
PM
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 31st Aug 2021 19:07
Not sure what I am doing wrong but when I entered bsp_mw2\\hk mk23 in this line in place of the welrod : return ( (g_PlayerGunFired == 1 and g_PlayerGunName ~= "bsp_ww2\\welrod") the soldier still "hears the shot" turns and shoots.

Any ideas?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 1st Sep 2021 13:29
bsp_mw2\\hk mk23
is it mw2 or ww2?
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 1st Sep 2021 17:50
It's mw2. It's the silenced pistol from BSP in the store. Name comes up as bsp_mw2\hkmk23. Tried putting the name in in different ways but no success
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Sep 2021 16:53
now you don't have a space, it has to be exactly what is being shown on screen when you prompt g_PlayerGunName but put \\ instead of \
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 4th Sep 2021 16:51 Edited at: 4th Sep 2021 16:53
I tried to include a screen shot of exactly how the gun name appears. It is bsp_mw2\hk mk23. I added the space in my script and now it does not say "player heard" but the soldier still turns and shoots

He is the script as I have it.
PM
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 4th Sep 2021 17:04 Edited at: 4th Sep 2021 17:06
For future reference, is there a way to delete one of my posts or just an option to edit?
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Sep 2021 21:08
Click on the Edit button on the left.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 4th Sep 2021 22:23
well yes if you are using the default AI and the player is nearby it will still aggro, all you are doing is spawning an entity if the player is heard.. nothing to do with the AI character?
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 5th Sep 2021 18:29
Ok thanks smallg. And thanks AmenMoses for your reply.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Sep 2021 16:56
did you fix it? what i meant to say was that you need to edit the AI script to match what was posted above as well - if your AI script is not changed it will not take into account the new function (make sure you also add the global variables)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Pink Panther
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 6th Sep 2021 17:54
Not yet.
I edited the module_combatCore.lua script as directed. When you say add the global variables does that mean going into the global file and adding g_ennemyGunFired? If so what is the proper way to add it ? g_ennemyGunFired = 0 ? (Sorry for not knowing this as it seems I am a way over my head)
As of right now when I place an enemy character, after making the above changes, the gun name is no longer shown but rather "player heard" right from the start.

PM

Login to post a reply

Server time is: 2024-04-20 06:00:21
Your offset time is: 2024-04-20 06:00:21