Scripts / Sniper and cover

Author
Message
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 17th May 2017 10:44
I'm trying to create a scenario in which the player must avoid being hit by a sniper stationed on the roof of a building. I can't do it 'for real' because adjusting the View Range and View Cone makes no difference to whether the enemies can see me (the view cone, for example, acts more like a view 'wedge' and doesn't account for the player being above or below the enemy). Instead I'm cheating. I have a dummy object running a script that plays a gunshot sound every 6 seconds provided the player is within 5000 units of the dummy. The script also features a distance-based ricochet sound effect so the further away you are, the longer it takes for the ricochet to play.

However, I now want to add cover for the player. I'm trying to do this using zones but I'm having trouble. Here's what my test map looks like - I haven't added all the cover zones yet.



The 'cover zones' are all running the same script. Basically the problem is that g_Entity[e]['plrinzone'] == 1 looks for the player to be in the zone running that script. As soon as they leave the zone, even if they enter another bit of cover, the script will still return a 0. And just because they are not in that specific zone, it doesn't mean the player isn't in a cover zone somewhere else. So what I need is an argument that basically says 'if player is in any zone called x then play the ricochet' or 'if player is not in any zone called x then hurt player'.

The second part of this question is should I be splitting this into 2 scripts (one for the sniper, one for the cover zones), or should it all be in the sniper script?

AE
Scene Commander
Support Manager
15
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 17th May 2017 11:22
Just a thought. What about a global variable that is set if the player is in a zone. You would then know if the player was in cover.

SC
i7-4770s 3.10ghz - Geforce GTX 650ti
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 17th May 2017 12:12
Quote: "Just a thought. What about a global variable that is set if the player is in a zone. You would then know if the player was in cover."


That's the first thing I tried. The trouble is when the player is not in the zone running the script, it returns a 0...even if they enter another cover zone running the same script.

AE
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 17th May 2017 13:19 Edited at: 17th May 2017 18:44
You could do this with the new IntersectAll() command, just ray cast from the snipers to the player and if it doesn't hit anything (returns nil) then you know the shot was successful.
edit, here you go, this works with multiple snipers but if you have more than 1 in the same spot you will want to edit the settings individually so they don't fire at the same speed etc (i don't believe we can get the fire rate from the properties yet).

doesn't rely on normal eyesight so it can technically fire from any range if set to always active but adjust it in the script to fit your needs.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
Avenging Eagle
18
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 18th May 2017 17:18 Edited at: 18th May 2017 20:45
Thanks smallg, this works great.
The only thing I would change if I knew how would be to delay the hurt or ricochet based on the player's distance. So if they are far away, there is a noticeable delay from gunshot to damage and if they are close it is near instant. Basically I'm trying to figure out whether to put...



...into the script. I guess the IntersectAll should be called at the moment of firing, then the 'outcomes' should be called later once ^that^ statement is true.

EDIT: OK, explain to me what I'm doing wrong here:



AE
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th May 2017 19:06 Edited at: 23rd May 2017 19:41
Quote: "I guess the IntersectAll should be called at the moment of firing, then the 'outcomes' should be called later once ^that^ statement is true."

new version that won't fire through terrain (hills etc)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-25 05:27:59
Your offset time is: 2024-04-25 05:27:59