Author Topic: A function for vehicle impact?  (Read 2977 times)

So im thinking that if helicopters blew up on impact at a certain speed like the F18 and A10s do then that will prevent their dumb ass's from spassing out and crashing the server.

Now ive tried Implementing the OnImpact Function from the F18 into the Apache helicopter but it hasnt worked.

For the sake of TDM servers and air combat, i need a function.

onImpact is the correct function. Either you're doing it wrong, or the minimum impact velocity on the datablock is jacked up so much that you can't actually trigger it.

onImpact is the correct function. Either you're doing it wrong, or the minimum impact velocity on the datablock is jacked up so much that you can't actually trigger it.
What do you recomend it to be for a helicopter?

No idea. Helicopters land pretty softly, so I'd guess a value of 10-20 or so would be decent.

Okay so its still not working, heres the function:
Code: [Select]
function F18Vehicle::onImpact(%this,%obj,%data)
{
%speed = vectorLen(%obj.getVelocity());

  //Lets the pilot have an easy landing
  if(%obj.f18gear == 2)
   %obj.speedlimit = 10;
  else
    %obj.speedlimit = 5;

  if(%obj.speed > %obj.speedlimit )
  {
    if(%obj.destroyed)
      return;
    %obj.setDamageLevel(0);
    %obj.destroyed = 1;
    %obj.finalexplosion();

    %obj.target.islocked=false;
    %obj.schedule(10,"delete");
    if(isObject(%obj.spawnBrick.client.minigame))
      %respawn = %obj.spawnBrick.client.minigame.vehicleReSpawnTime;
    %obj.spawnBrick.schedule(%respawn+1000,"spawnVehicle");
  }
  else if(%obj.speed < %obj.speedlimit)
  {
    %obj.applydamage(10);
  }

}
Any idea as to what ive done wrong?

Okay so its still not working, heres the function:
Code: [Select]
-snip-Any idea as to what ive done wrong?
Put in an echo to see if the function is being called? What's the vehicle's min impact speed?

Put in an echo to see if the function is being called? What's the vehicle's min impact speed?
10 since its a helicopter and it doesnt require that much to destroy it.

The min impact speed is a variable on the datablock. Any collisions with a speed less than that value will not trigger onImpact.

You can't just copy and paste code and expect it to work
If you're copying code from an f18 into a helicopter, then you need to change any references to f18 to the apache datablock names
Start with the function name
Then f18gear is probably undefined on your vehicle
« Last Edit: November 27, 2014, 09:43:24 PM by Headcrab Zombie »

You can't just copy and paste code and expect it to work
If you're copying code from an f18 into a helicopter, then you need to change any references to f18 to the apache datablock names
Start with the function name
Then f18gear is probably undefined on your vehicle
IK im not that stupid, ive already renamed stuff, i also already took out the f18gear out.
So preatty much what id like to know is would this work? or can you guys give me a simpler version?

IK im not that stupid, ive already renamed stuff, i also already took out the f18gear out.
So preatty much what id like to know is would this work? or can you guys give me a simpler version?
Then post the code, because the code you posted earlier wasn't changed

It looks like you'll also have to make a new variable in the helicopter datablock called speedlimit

Heres whats in the helicopter.

Code: [Select]
function ApacheVehicle::onImpact(%this,%obj,%data)
{
%speed = vectorLen(%obj.getVelocity());

  //Lets the pilot have an easy landing
  if(%obj.Apachegear == 2)
   %obj.speedlimit = 10;
  else
    %obj.speedlimit = 5;

  if(%obj.speed > %obj.speedlimit )
  {
    if(%obj.destroyed)
      return;
    %obj.setDamageLevel(0);
    %obj.destroyed = 1;
    %obj.finalexplosion();

    %obj.target.islocked=false;
    %obj.schedule(10,"delete");
    if(isObject(%obj.spawnBrick.client.minigame))
      %respawn = %obj.spawnBrick.client.minigame.vehicleReSpawnTime;
    %obj.spawnBrick.schedule(%respawn+1000,"spawnVehicle");
  }
  else if(%obj.speed < %obj.speedlimit)
  {
    %obj.applydamage(10);
  }

}

Put in an echo to see if the function is being called?
this
we've done about everything we can to help you, you have to do some stuff yourself

It looks like you'll also have to make a new variable in the helicopter datablock called speedlimit
No, because that vaariable isn't being checked, it's being defined in the function
(also, it's being defined on the object, not the datablock)
But he will have to define apachegear if he wants that part to work

is "ApacheVehicle" even the name of the vehicle?
post all the code
« Last Edit: November 28, 2014, 10:24:22 PM by Headcrab Zombie »

Quote
this
we've done about everything we can to help you, you have to do some stuff yourself
Thats fine, you guys helped alot.


Quote
is "ApacheVehicle" even the name of the vehicle?
post all the code
Yep its the same name. But i know what i did wrong now.
« Last Edit: November 29, 2014, 04:13:43 PM by Ctrooper »