SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 23/01/2010, 10:52 PM   #1
Torran
High-roller
 
Join Date: Jan 2010
Posts: 1,783
Reputation: 1
Default Function/Callback that detects...

Function And/Or Callback that detects the tiniest damage on a vehicle?
Torran is offline  
Old 23/01/2010, 11:21 PM   #2
mansonh
Gangsta
 
Join Date: Jun 2009
Posts: 613
Reputation: 0
Default Re: Function/Callback that detects...

Nope there isn't one. All callbacks are listed here
You can make it yourself though.

put this in your filterscript
pawn Code:
#include vhealth.inc
public OnFilterScriptInit()
{
  SetTimer("VehicleHCheck", 500, 1);
}
//put this callback where you want it
public OnVehicleDamage(driverid, vehicleid)
{
.....
}

in an include file call it vhealth.inc put it in pawn/include
pawn Code:
//This is in here for security, just leave as is
#if defined _vhealthcallback_Included
    #endinput
#endif
#define _vhealthcallback_Included

//have a variable for all players for their cars vehicle healths.
new Float:playerVHealth[GetMaxPlayers()];

//This is your callback, put this where you want it in your filterscript
forward OnVehicleDamage(driverid, vehicleid);

forward VehicleHCheck();
public VehicleHCheck()
{
  new Float:VHealth, vehicleid;
  for(new playerid=0; player<GetMaxPlayers();playerid++)
  {
    if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER) continue;
    vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicleid, VHealth);
    if(VHealth < playerVHealth[playerid])
    {
      OnVehicleDamage(playerid, vehicle);
    }
    playerVHealth[playerid] = VHealth;
  }
}
__________________
mansonh is offline  
Old 23/01/2010, 11:27 PM   #3
Torran
High-roller
 
Join Date: Jan 2010
Posts: 1,783
Reputation: 1
Default Re: Function/Callback that detects...

Wouldnt work for what im wanting it for
Torran is offline  
Old 24/01/2010, 01:00 AM   #4
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,161
Reputation: 361
Default Re: Function/Callback that detects...

pawn Code:
/* not tested, but it should work*/

forward myTimer();
forward OnVehicleHealthChange(vehicleid, newhealth, oldhealth);

new
    oldVehicleHealth[MAX_VEHICLES], newVehicleHealth[MAX_VEHICLES]; // change MAX_VEHICLES to your own vehicle amount.

Float:VehicleHealth(vehicleid)
{
  new
      Float:health;
  GetVehicleHealth(vehicleid, health);
  return health;
}

public myTimer()
{
  for(new v = 1; v <= MAX_VEHICLES; v++) // change MAX_VEHICLES to your own vehicle amount or use foreach function.
  {
    newVehicleHealth[v] = floatround(VehicleHealth(v));
    if(newVehicleHealth[v] != oldVehicleHealth[v])
    {
      OnVehicleHealthChange(v, newVehicleHealth[v], oldVehicleHealth[v]);
      oldVehicleHealth[v] = newVehicleHealth[v];
    }
  }
  return true;
}

public OnVehicleHealthChange(vehicleid, newhealth, oldhealth)
{
  if(newhealth < oldhealth)
  {
    // damage..
  }
  return true;
}

// under OnGameModeInit/OnFilterScriptInit-callback.
SetTimer("myTimer", 1000, true); // every second.
Correlli is offline  
Old 24/01/2010, 01:04 AM   #5
Torran
High-roller
 
Join Date: Jan 2010
Posts: 1,783
Reputation: 1
Default Re: Function/Callback that detects...

Quote:
Originally Posted by Don Correlli
pawn Code:
/* not tested, but it should work*/

forward myTimer();
forward OnVehicleHealthChange(vehicleid, newhealth, oldhealth);

new
    oldVehicleHealth[MAX_VEHICLES], newVehicleHealth[MAX_VEHICLES]; // change MAX_VEHICLES to your own vehicle amount.

Float:VehicleHealth(vehicleid)
{
  new
      Float:health;
  GetVehicleHealth(vehicleid, health);
  return health;
}

public myTimer()
{
  for(new v = 1; v <= MAX_VEHICLES; v++) // change MAX_VEHICLES to your own vehicle amount or use foreach function.
  {
    newVehicleHealth[v] = floatround(VehicleHealth(v));
    if(newVehicleHealth[v] != oldVehicleHealth[v])
    {
      OnVehicleHealthChange(v, newVehicleHealth[v], oldVehicleHealth[v]);
      oldVehicleHealth[v] = newVehicleHealth[v];
    }
  }
  return true;
}

public OnVehicleHealthChange(vehicleid, newhealth, oldhealth)
{
  return true;
}

// under OnGameModeInit/OnFilterScriptInit-callback.
SetTimer("myTimer", 1000, true); // every second.
Still wouldnt work for what i want it for xd
Torran is offline  
Old 24/01/2010, 01:06 AM   #6
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,161
Reputation: 361
Default Re: Function/Callback that detects...

Quote:
Originally Posted by Torran
Still wouldnt work for what i want it for xd
And what do you want it for?
Correlli is offline  
Old 24/01/2010, 01:15 AM   #7
Torran
High-roller
 
Join Date: Jan 2010
Posts: 1,783
Reputation: 1
Default Re: Function/Callback that detects...

Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by Torran
Still wouldnt work for what i want it for xd
And what do you want it for?
http://forum.sa-mp.com/index.php?topic=148011.0
Torran is offline  
Old 24/01/2010, 01:42 AM   #8
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,161
Reputation: 361
Default Re: Function/Callback that detects...

I already gave you the correct code.
Correlli is offline  
Old 24/01/2010, 01:47 AM   #9
Torran
High-roller
 
Join Date: Jan 2010
Posts: 1,783
Reputation: 1
Default Re: Function/Callback that detects...

Quote:
Originally Posted by Don Correlli
I already gave you the correct code.
I mean, It wouldnt work for planes, Like hitting buildings, Or rockets or something like that
Torran is offline  
Old 24/01/2010, 01:48 AM   #10
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,161
Reputation: 361
Default Re: Function/Callback that detects...

How about if you try it out before you post again?
Correlli is offline  
 

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AVG Scanner - Detects SA-MP.exe as malware caion Client Support 7 08/06/2010 02:15 PM
Is there an existing function/callback/define for... Torran Help Archive 1 20/03/2010 08:19 PM
Callback Bomber Help Archive 4 04/03/2010 09:08 PM
Is there such callback as JoeDaDude Help Archive 12 21/01/2010 06:29 PM
How to execute plugin function on native callback? izstas Plugin Development 1 13/12/2009 09:35 AM


All times are GMT. The time now is 08:01 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.