[Include] Car damage system - Damage a car without a driver!
#1

Damage Car System V2.5
Hi,

Here I bring this simple system, basicly, you can damage cars without a driver with a gun.

Usage:

Extract the files to your 'pawno/include' folder, then in your script you put: #include <Damage>, and you are ready to use it.

You can also change some configuration opening damage.inc and tweak it to your taste.

You must include those callbacks, if you don't, you will get an error message.

pawn Code:
public OnPlayerShotVehicle(playerid, vehicleid)
{
    //your code here...
    printf("playerid %d is shooting vehicleid %d", playerid, vehicleid);
    return 1;
}

public OnPlayerUnShotVehicle(playerid, vehicleid)
{
    //your code here...
    printf("playerid %d stopped shooting vehicleid %d", playerid, vehicleid);
    return 1;
}
You will have to add this under their respective callbacks:

pawn Code:
D_OnPlayerConnect(playerid); //Under OnPlayerConnect
D_OnPlayerDisconnect(playerid); //Under OnPlayerDisconnect
D_OnPlayerKeyStateChange(playerid, newkeys, oldkeys); //Under OnPlayerKeyStateChange
That's all, if you don't put it, it won't work and it will give you some warnings.

Functions:

Well, there is just one for now, if you need any other fuction that I can make just post in here.

pawn Code:
IsPlayerShootingVehicle(playerid);
It will return the vehicle id if he is shooting, 0 if not.

pawn Code:
if(IsPlayerShooting(playerid))
{
    printf("playerid %d is shooting vehicleid %d", playerid, IsPlayerShooting(playerid));
}
Bugs:

» It doesn't work with the rifle, shotgun, and with some other constant reloading weapons.
» You can damage cars trough walls.
» If there are too many cars together, it may not work properly.

Special thanks:
niCe for the IsPlayerAimingAt.
For the guys who made IsVehicleOccupied and GetClosestVehicle.
And to g_aSlice for some helping

Links:
Solidfiles > Errors FIXED. <

Version history:
  • V2.5: Fixed a bug when the vehicle exploded, now it will respawn if health is less than 250, fixed errors, added damage to car.
  • V2.0: Added callbacks and functions.
  • V1.0: Just the script.
Peace.
Reply
#2

Can you show some things?
Reply
#3

Quote:
Originally Posted by willsuckformoney
View Post
Can you show some things?
I'll make a vid tomorrow, im going to bed right now, if you want and can make a vid for me, it will be apreciated :P
Reply
#4

Busy myself, looked at the script, you need to post some credits :S. Also You could had at least showed us an example on how to use it or something.
Reply
#5

Omg, 1 milisecond timer when presing/holding fire key..

Errrm.. You should add credit for
Code:
IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius)
This sucks.. soz but its true. First reson - 1 millisecond timer.
No credits added for all functions include IsPlayerAimngAt.
Reply
#6

Quote:
Originally Posted by GaGlets®
View Post
Omg, 1 milisecond timer when presing/holding fire key..

Errrm.. You should add credit for
Code:
IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius)
This sucks.. soz but its true. First reson - 1 millisecond timer.
No credits added for all functions include IsPlayerAimngAt.
Where is the one milisecond timer?

I only see a 794 milisecond timer..

Gonna add the credits, I forgot :S

EDIT:

OMG I am so tired that putted the wrong link, now it's okay, credits added also.

BTW Gaglets, you suck.
Reply
#7

Looks nice, i will use this, thanks!
Reply
#8

Quote:

EDIT:

OMG I am so tired that putted the wrong link, now it's okay, credits added also.

BTW Gaglets, you suck.

Lmao^^ Also that '1' that he seen and said was millisecond is the repeat (true/false) he put 1 for true.
Reply
#9

Look's cool yet simple.
Goodjob!
Reply
#10

Couple problems (some can be fixed, some can't):
  • Hold fire and tap the action key to do loads of damage to cars (I think, I have only looked at the code).
  • The damage is random.
  • Large vehicles are hard to hit, and small vehicles are easy.
  • Cars take damage when shooting through walls.
  • You can jump/fall/lay down and damage vehicles.
pawn Code:
new veh = GetClosestVehicle(playerid);
        if(veh)
Will always be true (INVALID_VEHICLE_ID is 0xFFFF)

pawn Code:
if(weap == 0 || weap == 1 || weap == 4 || weap == 15 || weap == 40 || weap == 46 || weap == 43 || weap == 45 || weap == 44
    || weap == 42 || weap == 17 || weap == 3 || weap == 7 || weap == 8 || weap == 10 || weap == 11 || weap == 12 || weap == 13)
    {
        return 1;
    }
Will return 1 when unarmed, aswell.

pawn Code:
Hook:D_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(HOLDING(KEY_ACTION) || HOLDING(KEY_FIRE))
    {
        Timer[playerid] = SetTimerEx("C_Update", UPDATE_TIME, 1, "i", playerid);
    }
    else
    {
        KillTimer(Timer[playerid]);
    }
    return 1;
}
The timer can be re-created several time. One crafty person could probably cause havoc in the server by holding fire and tapping tab.
Reply
#11

warning 201: redefinition of constant/macro (symbol "OnPlayerEnterCheckpoint")
warning 201: redefinition of constant/macro (symbol "OnPlayerLeaveCheckpoint")

??
Reply
#12

Doesnt works for me

error at compile
Reply
#13

Good job! Looks very nice!
Reply
#14

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
Couple problems (some can be fixed, some can't):
  • Hold fire and tap the action key to do loads of damage to cars (I think, I have only looked at the code).
  • The damage is random.
  • Large vehicles are hard to hit, and small vehicles are easy.
  • Cars take damage when shooting through walls.
  • You can jump/fall/lay down and damage vehicles.
pawn Код:
new veh = GetClosestVehicle(playerid);
        if(veh)
Will always be true (INVALID_VEHICLE_ID is 0xFFFF)

pawn Код:
if(weap == 0 || weap == 1 || weap == 4 || weap == 15 || weap == 40 || weap == 46 || weap == 43 || weap == 45 || weap == 44
    || weap == 42 || weap == 17 || weap == 3 || weap == 7 || weap == 8 || weap == 10 || weap == 11 || weap == 12 || weap == 13)
    {
        return 1;
    }
Will return 1 when unarmed, aswell.

pawn Код:
Hook:D_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(HOLDING(KEY_ACTION) || HOLDING(KEY_FIRE))
    {
        Timer[playerid] = SetTimerEx("C_Update", UPDATE_TIME, 1, "i", playerid);
    }
    else
    {
        KillTimer(Timer[playerid]);
    }
    return 1;
}
The timer can be re-created several time. One crafty person could probably cause havoc in the server by holding fire and tapping tab.
Hey, thanks for the feedback!
  • It may be.. I changed it to KEY_FIRE.
  • Yes, I made the damage random, if you see the defines at the bottom, you can change it.
  • Yep, I'll fix that.
  • That's a bug from PlayerAimingAt.
  • That has nothing to do with the script.
Quote:

Will return 1 when unarmed, aswell.

I made it like that, that's why I said only with guns :P

Quote:
Originally Posted by [ISS]jumbo
Посмотреть сообщение
warning 201: redefinition of constant/macro (symbol "OnPlayerEnterCheckpoint")
warning 201: redefinition of constant/macro (symbol "OnPlayerLeaveCheckpoint")

??
That's not from my script..

Quote:
Originally Posted by Brian_Furious
Посмотреть сообщение
Doesnt works for me

error at compile
Error?
Reply
#15

Lol, the only reason I commented was thanks for the IsVehicleOccupied function, other than that, this has been done before, but in a FS. And it's released too, but I'm not going to waste my time searching for it
Reply
#16

I'm wondering, I only did a same stock just like the IsVehicleOccupied (Almost same coding, but even less optimized ), wouldn't it be more efficient if you'd use it like this?

pawn Код:
new bool:VehicleOccupied[MAX_VEHICLES];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
  if(newstate == PLAYER_STATE_DRIVER)
  {
    VehicleOccupied[GetPlayerVehicleID(playerid) - 1] = true;
    SetPVarInt(playerid, "InVehicle", GetPlayerVehicleID(playerid));
  }
  if(oldstate == PLAYER_STATE_DRIVER)
  {
    VehicleOccupied[GetPVarInt(playerid, "InVehicle") - 1] = false;
    DeletePVar(playerid, "InVehicle");
  }
  return 1;
}

stock bool:IsVehicleOccupied(vehicleid) //Are bools needed here? :D
{
  return VehicleOccupied[vehicleid - 1];
}
Just an idea of what I think might be a bit efficienter, correct me if I'm wrong. Now I'm gonna try this at home :P
Reply
#17

Quote:
Originally Posted by [FU]Victious
Посмотреть сообщение
Lol, the only reason I commented was thanks for the IsVehicleOccupied function, other than that, this has been done before, but in a FS. And it's released too, but I'm not going to waste my time searching for it
I didn't know about that

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
I'm wondering, I only did a same stock just like the IsVehicleOccupied (Almost same coding, but even less optimized ), wouldn't it be more efficient if you'd use it like this?

pawn Код:
new bool:VehicleOccupied[MAX_VEHICLES];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
  if(newstate == PLAYER_STATE_DRIVER)
  {
    VehicleOccupied[GetPlayerVehicleID(playerid) - 1] = true;
    SetPVarInt(playerid, "InVehicle", GetPlayerVehicleID(playerid));
  }
  if(oldstate == PLAYER_STATE_DRIVER)
  {
    VehicleOccupied[GetPVarInt(playerid, "InVehicle") - 1] = false;
    DeletePVar(playerid, "InVehicle");
  }
  return 1;
}

stock bool:IsVehicleOccupied(vehicleid) //Are bools needed here? :D
{
  return VehicleOccupied[vehicleid - 1];
}
Just an idea of what I think might be a bit efficienter, correct me if I'm wrong. Now I'm gonna try this at home :P
Mhh.. it could be.. try it :P
Reply
#18

You can't know if a player is aiming through a wall or not. Unless you load collision files from the GTA game and check the collision, which would be incredibly slow and a waste of time imo.
Also, what I meant by damaging the vehicle while jumping: You can jump/lay down/etc. and press tab/fire to damage the vehicle..
Also.. If someone is HOLDING fire while pressing another key, OnPlayerKeyStateChange will be called several times and the timer will be created several times.
Reply
#19

Nothing new,
and 1ms timer always suck...
Reply
#20

Quote:
Originally Posted by Trooper[Y]
Посмотреть сообщение
Nothing new,
and 1ms timer always suck...
There is no 1ms timer in there. You suck.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)