PDA

View Full Version : is player behind object


GoldenLion
22/04/2017, 08:18 PM
Hi. I've been thinking of adding a flashbang system to my script so I've been wondering if it's possible to check if player is behind an object or something like that? I want to make it like that when a player throws a flashbang he can run behind a wall so he won't get blind. That's the only thing that's stopping me from making it.

Toroi
22/04/2017, 08:20 PM
Using ColAndreas could help you to achieve this.

http://forum.sa-mp.com/showthread.php?t=586068

GoldenLion
22/04/2017, 09:24 PM
I don't know how to make it with ColAndreas. Could anyone help?

Battlezone
22/04/2017, 09:54 PM
There's another way to it, you can use AbyssMorgan's IsElementOnPlayerScreen to see if the flashbang object was seen by the player and thus flash him: https://www.youtube.com/watch?v=ih9P_Cwkz68

GoldenLion
22/04/2017, 10:13 PM
There's another way to it, you can use AbyssMorgan's IsElementOnPlayerScreen to see if the flashbang object was seen by the player and thus flash him: https://www.youtube.com/watch?v=ih9P_Cwkz68
Thanks, that's exactly what I wanted before, but it would be too easy to avoid the flashbang if player could just turn their screen away. What I want is to check if there's something like a wall between the player and the flashbang. Is that possible with ColAndreas? If not then I think I'll use IsElementOnPlayerScreen.

Battlezone
22/04/2017, 10:19 PM
Thanks, that's exactly what I wanted before, but it would be too easy to avoid the flashbang if player could just turn their screen away. What I want is to check if there's something like a wall between the player and the flashbang. Is that possible with ColAndreas? If not then I think I'll use IsElementOnPlayerScreen.

That's definitely possible, but I'm actually too busy to search the appropriate functions as I've almost never used it before and am pretty unexperienced, so just wait for someone used with it to help
Edit: A simple proof that it is possible is that people use in NPC systems, you would see NPCs changing directions whenever they come across walls in some servers
Edit: Another way to it is to use simple Ray casting, it makes a virtual line between the player and the flashbang objects and checks if an objects is between them, but according to my knowledge, I know how to code it only in case a created object is between those 2, not a world object, maybe this would help though if you find a function in colandreas that helps in detecting world objects

AbyssMorgan
22/04/2017, 10:32 PM
About Screen function:
http://i.imgur.com/16gRWpG.png

Battlezone
22/04/2017, 10:43 PM
About Screen function:
http://i.imgur.com/16gRWpG.png

It's solved then, you just have to find code Abyss used for walls detection in his screen script

GoldenLion
22/04/2017, 10:46 PM
It's solved then, you just have to find code Abyss used for walls detection in his screen script
OK, thanks, I'll have a look tomorrow.

GoldenLion
23/04/2017, 09:17 PM
If anyone has the same question then I could achieve that by using CA_RayCastLine and IsPlayerFacingPoint (http://forum.sa-mp.com/showthread.php?t=573961). I used CA_RayCastLine to check if there's something between the player and the flashbang and IsPlayerFacingPoint obviously to check if player is even facing the flashbang. That's all to know whether the character sees the flashbang, not the player itself.