Raised This Month: $32 Target: $400
 8% 

Solved Make entities fly away and check for tank punch or rock hit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 11-16-2021 , 06:40   Make entities fly away and check for tank punch or rock hit
Reply With Quote #1

I used the tank car smash from Marttt and changed it so on tank hit, it removes the car model and currently places a tire and is supposed to fire it away from the player.

ATM it does that on every car, so you can test it on 1st map crash course as being tank.

I am facing 2 problems.

When I hit the car, the car entity gets killed as expected and the tire is spawned, it will fly away like 3 meters and then bounces back.

But there is nothing to bounce back from?! It just bounces back midair. But why?

Second problem is, it is only supposed to happen on tank punch and not on rock hit, so how to find out if direct hit or by rock?
__________________

Last edited by finishlast; 11-27-2021 at 14:37.
finishlast is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-16-2021 , 09:10   Re: Make entities fly away and check for tank punch or rock hit
Reply With Quote #2

To detect if is a tank rock you can look at the inflictor parameter and check it's classname.

Then check if is a "tank_rock" or a "weapon_tank_claw".
__________________

Last edited by Marttt; 11-17-2021 at 11:04.
Marttt is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 11-16-2021 , 10:28   Re: Make entities fly away and check for tank punch or rock hit
Reply With Quote #3

Instead of:
PHP Code:
if (!StrContains(modelname"models/props_vehicles")) 
You can do:
PHP Code:
if( strncmp(modelname"models/props_vehicles"21) == 0
to match the first 21 chars of that string. This is much more efficient and what you want.


Also this:
PHP Code:
PrecacheModel("models/props_vehicles/tire001c_car.mdl"true); 
Should be in OnMapStart() - you only ever want to cache models/sounds/particles in OnMapStart.


I can't see anything wrong with the physics except you use TeleportEntity twice. I would remove the first one: "TeleportEntity(ent_carpart1, vPos, vAng, NULL_VECTOR);"

What was your intention with the first and second teleport?
__________________
Silvers is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 11-16-2021 , 10:40   Re: Make entities fly away and check for tank punch or rock hit
Reply With Quote #4

Thank you Marttt

GetEdictClassname(inflictor, sWeapon, sizeof(sWeapon));
if(StrContains(sWeapon, "tank_rock") > -1)
return;

thats works like charm

I will change to your suggestions Silver.

I wasn't sure how to spawn the tire and give it a kick into the desired direction.


I thought I would have to spawn it where the car is, and then by teleporting it a bit in front of the tank which should be behind the car with acceleration, I thought mb I could then make it fly away from players view.

But then again my math skills are literally non existant.

Like spawning it at point A and then with acceleration to point B to make it fly in that direction.

EDIT

Oh I found out why it is bouncing, the acceleration in only in one direction at the moment
So when I punch it in one in flies in my direction. Punch on the other side, then to the right, punch at next side it flies (as intended) away from me, the other side then it flies left.

So the problem is, it is not flying away in the direction I look at.

Instead always in the same direction. mmmh

vDir[0] = 0.0;
vDir[1] = 400.0;
vDir[2] = 0.0;

Think that has to change accoringly to view too. But how is the question!?
__________________

Last edited by finishlast; 11-20-2021 at 09:42.
finishlast is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 11-16-2021 , 11:17   Re: Make entities fly away and check for tank punch or rock hit
Reply With Quote #5

Probably using "GetAngleVectors(vAng, vDir, NULL_VECTOR NULL_VECTOR)" something like that.

Again, replace:
PHP Code:
if(StrContains(sWeapon"tank_rock") > -1
With:
PHP Code:
if(strcmp(sWeapon"tank_rock") == -1
StrContains should only be used when you need to check for a substring of a string. Not for comparison checks, it's very inefficient for this because it checks every character of the string rather than checking for identical strings.
__________________
Silvers is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 11-18-2021 , 03:41   Re: Make entities fly away and check for tank punch or rock hit
Reply With Quote #6

Oh, yes, silly me, I change that too.

I have an idea now with the suggested GetAngleVectors, I will try that.

Thank you all!

edit:
hahaha, that is so much fun.

I attached the first working test. (only tested on l4d1)

I know, lots of same code repeats that should be put in seperate functions.

There was an issue with sac boats models show as models/props_vehicles\boat_smash_break01.mdl and not as models/props_vehicles/boat_smash_break01.mdl, dont know why.
I couldn't get it working with strcmp so I used string contains for that one.


Its a proof of concept.. or shitty programming... whatever it is a start...

Adjust smash chance in cvar

I wouldn't use 100% bc if you destroy a car you produce lots of entities and that could result in ERROR! Reliable snaphsot overflow if you destroy too many, Server crash etc.

Setting it to 5%-10% is more realistic anyways.

Other then that I would have to cleanup the mess after x seconds but ran into other problem with the timer.
Attached Files
File Type: sp Get Plugin or Get Source (l4d_boatstyle_carsv2.sp - 92 views - 40.2 KB)
__________________

Last edited by finishlast; 11-21-2021 at 07:26.
finishlast is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode