dim3 Forum

Full Version: Flashbang
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, I need some help coding a flashbang.
(it's like a grenade but instead of exploding it emits a bright flash of light, temporarily blinding anyone looking at it, and makes a loud banging sound.)

It seems easy, you could just spawn a small melee and check to see which projectile hit you (and add some line of sight stuff), but almost none of dim3's obj.hit commands seem to work for me. I tried obj.hit.projectileName, but as the projectile spawns a melee it doesn't work. Weapon name won't work as the grenade is a secondary weapon and can be thrown from any weapon, so if I'm holding a crowbar when I throw it, it thinks I was hit with a crowbar. I also tried setting the flashbang to do 1 damage, and check how much the player was damaged but even if you die obj.hit.damage returns 0.

Any ideas?
Warning, this solution is probably not the best. And has been shown to cause cancer in laboratory animals...

Okay, so when the grenade explodes, it starts a looping command where it finds the nearest of the enemy team (or player maybe?) , using the appropriate map search. It finds it, send it a message. When the bot receives this, it activates the appropriate commands to make it 'confused' in its actions (if the player is affected, it would also play sound/show flash here). It would then set obj.setting.find to false. Hopefully, as the find command is looping, it will quickly go through all the bots in the flashbang's radius, and it stops once the find command returns -1. The bots all have timers for the effect, and possibly a shorter timer that will turn back on obj.setting.find, since the grenades find loop should only take a fraction of a second.

Note, this will obviously mess up other map.object finds during this time, so it that could pose a problem.

Edit: There also another way using teams. Instead of turning off settings.find, you would switch the objects team (then back after the timer). It would work the same, since the search is only for the specific enemy team. Now, I don't know how you're using teams in your game, so this might require you to double up all your team searches if you use them elsewhere.
E.G.
Code:
n=map.object.nearestTeam(x,z,y,TEAM_A,angle,angleSweep,minDist,maxDist);
if (n==-1) n=map.object.nearestTeam(x,z,y,TEAM_B,angle,angleSweep,minDist,maxDist);
Thanks gordon! It works, except line of sight. I need to get that working. :P
Does line of sight work in the new beta? It won't for me, but that's probably my fault.

Here are my settings:
Code:
    obj.sight.sideFieldAngle=45;
    obj.sight.lookFieldAngle=45;
    obj.sight.sideFieldDivision=10;
    obj.sight.lookFieldDivision=10;
    obj.sight.distance=900000;
I told it to check if a crate was in the players line of sight every tick on a timer, but it always returns false. :|
Code:
obj.sight.sideFieldDivision=10;
obj.sight.lookFieldDivision=10;
Use something like 80 or 90 for those.
10 is not accurate enough and will almost NEVER detect the player correctly.
Did that on every tick to see if it worked, still returns false every time. :|
We really need a new way to do line of sight...

EDIT: Maybe detect if the player is in a certain area, and if he is, do the current line of sight to figure out if anything is in between. Wouldn't that work?
You mean draw a line towards the player and see if it hits? I was thinking about that to. It wouldn't work as the object could be partially covered, though it might be accurate enough for me to use for the flashbang. (the flashbang is very small)

I'm going to try this with hitscans if I can't get los to work.
[EDIT]I think line of sight is broken for the player. Can someone else test this for me? I works when I set another object to find the player, instead of the player to find the object.
[EDT1]What's the difference between angle and angle sweep? (in map.object.find)
Reference URL's