SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Includes (https://forum.sa-mp.com/forumdisplay.php?f=83)
-   -   [Include] weapon-config.inc - Damage system with many features (https://forum.sa-mp.com/showthread.php?t=563387)

Slice 15/02/2015 05:05 PM

weapon-config.inc - Damage system with many features
 
This is an include that provides a more consistent and responsive damage system with many new features.

It's pretty much plug-and-play if you don't have any filterscripts that interfere with the health or death events.

Demo server

Code:

HostName: Slice's test server
Address:  ulclan.com:1234
Players:  0 / 100
Ping:    42
Mode:    Slice's test gm
Map:      San Andreas

Features
  • Server-side health
    • Impossible to use health hacks on lagcomp mode
    • Any type of damage can be modified/prevented, even falling 1000m from the sky
    • Vending machines are controlled server-side (buildings removed and objects created)
    • Paused players can be killed (with death animations) and their HP bars always show the correct values
  • Destroy vehicles with a passenger but no driver
  • Custom falling damage (optional)
    • Adjust the damage and at which speed a player will die
  • Sounds and on-screen TextDraw indicators of damage given/taken
    • Also shows another player's damage feed when spectating
  • New weapon types detected:
    • WEAPON_PISTOLWHIP - When you punch someone with a gun
    • WEAPON_VEHICLE_M4 - Vehicles with M4 guns (e.g. Rustler)
    • WEAPON_VEHICLE_MINIGUN - Vehicles with miniguns (e.g. Hunter)
    • WEAPON_HELIBLADES - Helikill
    • WEAPON_CARPARK - When you park your car on someone
  • Extensive sanity checking on shots:
    • Modified weapon.dat is automatically detected
    • Shot vector, player distance, and much more is examined
    • A callback is invoked for each so-called "rejected hit" so that the player is informed. A few of these are:
      • Inflicting damage when already dead (due to lag)
      • Hit a player too far from the shot hit position (due to severe lag or cheating)
      • Hitting/shooting too fast (due to severe lag or cheating)
  • Modify every weapon's damage amount
    • To a single value
    • To multiple values depending on the shot distance
    • With custom logic in a callback, for example:
      • Increase damage for headshots
      • Increase/lower damage for combos
      • Lower damage for c-bug rapid fire
  • Knife sync fixed in both lagcomp and no-lagcomp
  • New death atnimations and respawn logic
    • Customize respawn time globally and for each death
    • Fully customizable animations, with a nice set of defaults
    • Different animation depending on weapon/bodypart, for example:
      • Headshots make you fall back with both hands in your face
      • Shotgun kills make you fly backward like in GTA:VC (unless killed from behind)

Download

GitHub: https://github.com/oscar-broman/samp-weapon-config

Skully82 15/02/2015 05:12 PM

Re: weapon-config.inc - Damage system with many features
 
Another Awesome Relases Of You,Slice!
Amazing work,Well done

Abagail 15/02/2015 05:18 PM

Re: weapon-config.inc - Damage system with many features
 
Second. Great release! Hopefully this will end the era of health hacking in SA-MP.

Adoniiz 15/02/2015 05:27 PM

Respuesta: weapon-config.inc - Damage system with many features
 
Nice release, Slice. I like the anti hh. thanks

Admigo 15/02/2015 05:39 PM

Re: weapon-config.inc - Damage system with many features
 
Looks nice;)

Ritzy2K 15/02/2015 05:46 PM

Re: weapon-config.inc - Damage system with many features
 
Nice... :D its gonna help a lot :) specially to tdm dm...and cnr..

GiamPy. 15/02/2015 06:13 PM

Re: weapon-config.inc - Damage system with many features
 
I like it.

Crayder 15/02/2015 06:24 PM

Re: weapon-config.inc - Damage system with many features
 
Great! Love it!

Abagail 15/02/2015 06:25 PM

Re: weapon-config.inc - Damage system with many features
 
That is some very complex, and lengthy code. How long did it take you to write the include?

Crayder 15/02/2015 07:01 PM

Re: weapon-config.inc - Damage system with many features
 
Is SKY compiled? Where are the binaries... I can't build right now...

Slice 15/02/2015 09:21 PM

Re: weapon-config.inc - Damage system with many features
 
It took quite a while to develop, since I didn't stop until the animations looked perfect! Though I still have some more things I want to add.

Binaries will be officially released for SKY soon.

In the mean time, try this: http://server.ulclan.com/SKY.so

PT 15/02/2015 09:58 PM

Re: weapon-config.inc - Damage system with many features
 
The health bar bigger is because the knife bug?

Nice work dude!

PaulDinam 15/02/2015 10:55 PM

Re: weapon-config.inc - Damage system with many features
 
Using wide screen fix mod for gta sa will cause this:
http://i.imgur.com/Z4NpxMQ.png

Slice 15/02/2015 11:07 PM

Re: weapon-config.inc - Damage system with many features
 
How exactly does wide screen need to be fixed?

Either way, is there a way to detect that mode by reading the camera mode or vectors?

PaulDinam 15/02/2015 11:12 PM

Re: weapon-config.inc - Damage system with many features
 
I don't think so, this is an old ASI mod for GTA.

Kyle 15/02/2015 11:15 PM

Re: weapon-config.inc - Damage system with many features
 
Quote:

Originally Posted by Slice (Post 3372331)
How exactly does wide screen need to be fixed?

Either way, is there a way to detect that mode by reading the camera mode or vectors?

GetPlayerCameraAspectRatio.

Will return 0.0000 for WIDESCREEN and 0.333333 for NON-WIDESCREEN.

Slice 15/02/2015 11:24 PM

Re: weapon-config.inc - Damage system with many features
 
He's talking about some CLEO, which by the way makes you impossible to hit on non-lagcomp servers and fucks up rocket launcher shoot vectors.

I suppose the aspect ratio should be another value for it. Could someone look into that?

PaulDinam 15/02/2015 11:28 PM

Re: weapon-config.inc - Damage system with many features
 
1.776470 is returned when using this CLEO mod, you think perhaps you could modify the include to detect whether a player is using it or not?

Crayder 15/02/2015 11:40 PM

Re: weapon-config.inc - Damage system with many features
 
Since you create a custom bar, I think you could add a define for the color. Like WC_HEALTH_COLOR. By default it'd be the normal color.

Or, you could use this color array and set the bar to (floatround(health)-1).

pawn Code:
new RGY[100] =
{
    0xFF0000FF,0xFF0500FF,0xFF0A00FF,0xFF0F00FF,0xFF1400FF,0xFF1900FF,0xFF1E00FF,0xFF2300FF,0xFF2800FF,0xFF2D00FF,
    0xFF3300FF,0xFF3800FF,0xFF3D00FF,0xFF4200FF,0xFF4700FF,0xFF4C00FF,0xFF5100FF,0xFF5600FF,0xFF5B00FF,0xFF6000FF,
    0xFF6600FF,0xFF6B00FF,0xFF7000FF,0xFF7500FF,0xFF7A00FF,0xFF7F00FF,0xFF8400FF,0xFF8900FF,0xFF8E00FF,0xFF9300FF,
    0xFF9900FF,0xFF9E00FF,0xFFA300FF,0xFFA800FF,0xFFAD00FF,0xFFB200FF,0xFFB700FF,0xFFBC00FF,0xFFC100FF,0xFFC600FF,
    0xFFCC00FF,0xFFD100FF,0xFFD600FF,0xFFDB00FF,0xFFE000FF,0xFFE500FF,0xFFEA00FF,0xFFEF00FF,0xFFF400FF,0xFFF900FF,
    0xFFFF00FF,0xF9FF00FF,0xF4FF00FF,0xEFFF00FF,0xEAFF00FF,0xE4FF00FF,0xDFFF00FF,0xDAFF00FF,0xD5FF00FF,0xD0FF00FF,
    0xCAFF00FF,0xC5FF00FF,0xC0FF00FF,0xBBFF00FF,0xB6FF00FF,0xB0FF00FF,0xABFF00FF,0xA6FF00FF,0xA1FF00FF,0x9CFF00FF,
    0x96FF00FF,0x91FF00FF,0x8CFF00FF,0x87FF00FF,0x82FF00FF,0x7CFF00FF,0x77FF00FF,0x72FF00FF,0x6DFF00FF,0x68FF00FF,
    0x62FF00FF,0x5DFF00FF,0x58FF00FF,0x53FF00FF,0x4EFF00FF,0x48FF00FF,0x43FF00FF,0x3EFF00FF,0x39FF00FF,0x34FF00FF,
    0x2EFF00FF,0x29FF00FF,0x24FF00FF,0x1FFF00FF,0x1AFF00FF,0x14FF00FF,0x0FFF00FF,0x0AFF00FF,0x05FF00FF,0x00FF00FF
};

100 colors, fade from green to yellow to red. :D





Edit: My server keeps crashing, is it because it is 0.3.7? Also, the bar is pretty wide (tall).

Slice 16/02/2015 12:19 AM

Re: weapon-config.inc - Damage system with many features
 
0.3.7 is not supported by SKY yet. I'll deal with it as fast as I can.

Could you attach gdb to the process and print a backtrace of the crash?

Crayder 16/02/2015 01:06 AM

Re: weapon-config.inc - Damage system with many features
 
Quote:

Originally Posted by Slice (Post 3372417)
0.3.7 is not supported by SKY yet. I'll deal with it as fast as I can.

Could you attach gdb to the process and print a backtrace of the crash?

It only crashes when I'm in game, and I can't connect to the server (or even query it) while gdb is attached. Lol, alternative?


EDIT: ALso, I can't run the server from the gdb console. It says server.cfg could not be run (and I get the intro stuff).

Slice 16/02/2015 01:11 AM

Re: weapon-config.inc - Damage system with many features
 
You need to type continue (or c) when you attach gdb. Look on GitHub in a few minutes, there will be an update which will fix the crashes.

Crayder 16/02/2015 01:32 AM

Re: weapon-config.inc - Damage system with many features
 
http://i.imgur.com/gQcevBS.jpg

Slice 16/02/2015 01:34 AM

Re: weapon-config.inc - Damage system with many features
 
Try with this one: https://github.com/oscar-broman/SKY/...-BETA-0.3.7RC1

Crayder 16/02/2015 01:40 AM

Re: weapon-config.inc - Damage system with many features
 
It seems to be working... Now about that health bar... :P
Should it be this large?

1024x768 http://i.imgur.com/MtqhCmW.png

Also, would you consider adding custom colors? (Possibly the fading color array I provided above :3)





EDIT: You could also consider adding damage to unoccupied vehicles (I made a pull request to do so), and damage when falling into water (this would be awesome).
EDIT2:For pawns function list: (retrieved using regex on include)
Code:

/*
native public OnPlayerPrepareDeath(playerid, animlib[32], animname[32], &anim_lock, &respawn_time)
native public OnRejectedHit(playerid, hit[E_REJECTED_HIT])
native public OnPlayerDeathFinished(playerid)
native public OnInvalidWeaponDamage(playerid, damagedid, Float:amount, weaponid, bodypart, error, bool:given)
native public OnPlayerDamageDone(playerid, Float:amount, issuerid, weapon, bodypart)
native public OnPlayerDamage(&playerid, &Float:amount, &issuerid, &weapon, &bodypart)
native stock IsBulletWeapon(weaponid)
native stock IsHighRateWeapon(weaponid)
native stock IsMeleeWeapon(weaponid)
native stock IsPlayerSpawned(playerid)
native stock AverageShootRate(playerid, shots, &multiple_weapons = 0)
native stock AverageHitRate(playerid, hits, &multiple_weapons = 0)
native stock SetRespawnTime(ms)
native stock GetRespawnTime()
native stock ReturnWeaponName(weaponid)
native stock SetWeaponDamage(weaponid, damage_type, Float:amount, Float:...)
native stock SetDamageSounds(taken, given)
native stock SetCustomFallDamage(bool:toggle, Float:damage_multiplier = 25.0, Float:death_velocity = -0.6)
native stock SetCustomVendingMachines(bool:toggle)
native stock SetVehiclePassengerDamage(bool:toggle)
native stock SetDamageFeed(bool:toggle)
native stock SetWeaponShootRate(weaponid, max_rate)
native stock IsPlayerDying(playerid)
native stock SetWeaponMaxRange(weaponid, Float:range)
native stock DamagePlayer(playerid, Float:amount, issuerid = INVALID_PLAYER_ID, weaponid = WEAPON_UNKNOWN, bodypart = BODY_PART_UNKNOWN)
native stock GetRejectedHit(playerid, idx, output[], maxlength = sizeof(output))
native static UpdatePlayerVirtualWorld(playerid)
native static HasSameTeam(playerid, otherid)
native static IsPlayerPaused(playerid)
native static UpdateHealthBar(playerid, bool:force = false)
native static SetHealthBarVisible(playerid, bool:toggle)
native static PosInFront(playerid, Float:distance, &Float:x, &Float:y, &Float:z)
native static UpdateSyncData(playerid)
native static RemoveDefaultVendingMachines(playerid)
native static CreateVendingMachines()
native static DestroyVendingMachines()
native static ProcessDamage(&playerid, &issuerid, &Float:amount, &weaponid, &bodypart, &Float:bullets)
native static InflictDamage(playerid, Float:amount, issuerid = INVALID_PLAYER_ID, weaponid = WEAPON_UNKNOWN, bodypart = BODY_PART_UNKNOWN)
native static PlayerDeath(playerid, animlib[32], animname[32], anim_lock = 1, respawn_time = -1, bool:freeze_sync = true)
native static DamageFeedUpdate(playerid, bool:modified = false)
native static DamageFeedUpdateText(playerid)
native static DamageFeedAddHitGiven(playerid, issuerid, Float:amount, weapon)
native static DamageFeedAddHitTaken(playerid, issuerid, Float:amount, weapon)
native static DamageFeedAddHit(arr[WC_FEED_HEIGHT][E_DAMAGE_FEED_HIT], playerid, issuerid, Float:amount, weapon)
native static DamageFeedRemoveHit(arr[WC_FEED_HEIGHT][E_DAMAGE_FEED_HIT], idx)
native static ResyncPlayer(playerid)
native static Float:AngleBetweenPoints(Float:x1, Float:y1, Float:x2, Float:y2)
native static MakePlayerFacePlayer(playerid, targetid, opposite = false, forcesync = true)
native static IsPlayerBehindPlayer(playerid, targetid, Float:diff = 90.0)
native static AddRejectedHit(playerid, damagedid, reason, weapon, i1 = 0, i2 = 0, i3 = 0)
*/

Ps. I like how I can still move my head when I'm dead... :P (I usually keep /headmove on though, so it doesn't bother me)

Excel™ 16/02/2015 02:46 AM

Re: weapon-config.inc - Damage system with many features
 
Could you explain syncing part for knives?

thaKing 16/02/2015 05:31 AM

Re: weapon-config.inc - Damage system with many features
 
Really useful, especially for role play servers. Thanks.
(I'll still check the code later.)

Crayder 16/02/2015 05:34 AM

Re: weapon-config.inc - Damage system with many features
 
Also (considering my last comment and the vehicle branch of this library) I suggest you should add separate damage for the armoured vehicles. Like instead of shotguns taking 120 they would take 60 health from a rhino and hunter. I made a pull request too, adding unoccupied vehicle damage which works the exact same way as passenger damages, but without the passenger part.

JeaSon 16/02/2015 06:19 AM

Re: weapon-config.inc - Damage system with many features
 
its really great

Slice 16/02/2015 07:39 AM

Re: weapon-config.inc - Damage system with many features
 
Quote:

Originally Posted by Excel™ (Post 3372789)
Could you explain syncing part for knives?

lagcomp
The syncing of the aim key is disabled, which means you will never see anyone hold their knife up and stealth knife you.
The reason I did this is if you get knifed and OnPlayerTakeDamage is called, your game will be bugged until you respawn.
Instead, when you knife someone with OnPlayerGiveDamage, an animation is applied (foresync) and a death message is sent.
This removes all issues related to knives causing players to get desynced.

non-lagcomp
When someone does a stealth knife with OnPlayerGiveDamage, a timer is set that checks if the player you knifed will get knifed "on his screen". If not, that player will be respawned for you to get out of the death state.

Quote:

Originally Posted by Crayder (Post 3373081)
Also (considering my last comment and the vehicle branch of this library) I suggest you should add separate damage for the armoured vehicles. Like instead of shotguns taking 120 they would take 60 health from a rhino and hunter. I made a pull request too, adding unoccupied vehicle damage which works the exact same way as passenger damages, but without the passenger part.

I'm looking into a nice way to make vehicle damage server-side. The damage should be processed and friendly fire should be toggleable. There are some quirks I need to work around, such as recognizing collision damage.
One little idea I have is make the health sync just like with other stuff and attach custom smoke particles to the vehicles.

Sanady 16/02/2015 08:50 AM

Re: weapon-config.inc - Damage system with many features
 
Well it`s seems nice to me. But I have guestion. This inc can be used like anticheat and optimization for our scripts?

Slice 16/02/2015 08:54 AM

Re: weapon-config.inc - Damage system with many features
 
Quote:

Originally Posted by Sanady (Post 3373154)
Well it`s seems nice to me. But I have guestion. This inc can be used like anticheat and optimization for our scripts?

Yes. The anti-cheat part does not cover everything, however. There are still some cheats that can't be detected automatically that easily.

This will, as it says on page 1, make it impossible to use health hacks. It will also make it impossible to modify weapon damage to do more damage or take less damage.

Slice 16/02/2015 09:34 AM

Re: weapon-config.inc - Damage system with many features
 
Thanks. You probably don't want to look at the part where there's ~100 ALS hooks. Anyway, try their trei bung kanh chhet!

LivingLikeYouDo 16/02/2015 10:01 AM

Re: weapon-config.inc - Damage system with many features
 
This is a really nice release indeed! I love those health-hack detecting, and this can be a must include to stop the era of health hacking in SA-MP!

I'm loving all the features from reading the topic, and I can say you did a great job!
I'll check the code later and give feedback soon! Have a cookie :)

dominik523 16/02/2015 01:15 PM

Re: weapon-config.inc - Damage system with many features
 
Awesome, thank you so much for this Slice!

ZombieNest 16/02/2015 02:38 PM

Re: weapon-config.inc - Damage system with many features
 
Quote:

Originally Posted by Crayder (Post 3372369)
Since you create a custom bar, I think you could add a define for the color. Like WC_HEALTH_COLOR. By default it'd be the normal color.

Or, you could use this color array and set the bar to (floatround(health)-1).

pawn Code:
new RGY[100] =
{
    0xFF0000FF,0xFF0500FF,0xFF0A00FF,0xFF0F00FF,0xFF1400FF,0xFF1900FF,0xFF1E00FF,0xFF2300FF,0xFF2800FF,0xFF2D00FF,
    0xFF3300FF,0xFF3800FF,0xFF3D00FF,0xFF4200FF,0xFF4700FF,0xFF4C00FF,0xFF5100FF,0xFF5600FF,0xFF5B00FF,0xFF6000FF,
    0xFF6600FF,0xFF6B00FF,0xFF7000FF,0xFF7500FF,0xFF7A00FF,0xFF7F00FF,0xFF8400FF,0xFF8900FF,0xFF8E00FF,0xFF9300FF,
    0xFF9900FF,0xFF9E00FF,0xFFA300FF,0xFFA800FF,0xFFAD00FF,0xFFB200FF,0xFFB700FF,0xFFBC00FF,0xFFC100FF,0xFFC600FF,
    0xFFCC00FF,0xFFD100FF,0xFFD600FF,0xFFDB00FF,0xFFE000FF,0xFFE500FF,0xFFEA00FF,0xFFEF00FF,0xFFF400FF,0xFFF900FF,
    0xFFFF00FF,0xF9FF00FF,0xF4FF00FF,0xEFFF00FF,0xEAFF00FF,0xE4FF00FF,0xDFFF00FF,0xDAFF00FF,0xD5FF00FF,0xD0FF00FF,
    0xCAFF00FF,0xC5FF00FF,0xC0FF00FF,0xBBFF00FF,0xB6FF00FF,0xB0FF00FF,0xABFF00FF,0xA6FF00FF,0xA1FF00FF,0x9CFF00FF,
    0x96FF00FF,0x91FF00FF,0x8CFF00FF,0x87FF00FF,0x82FF00FF,0x7CFF00FF,0x77FF00FF,0x72FF00FF,0x6DFF00FF,0x68FF00FF,
    0x62FF00FF,0x5DFF00FF,0x58FF00FF,0x53FF00FF,0x4EFF00FF,0x48FF00FF,0x43FF00FF,0x3EFF00FF,0x39FF00FF,0x34FF00FF,
    0x2EFF00FF,0x29FF00FF,0x24FF00FF,0x1FFF00FF,0x1AFF00FF,0x14FF00FF,0x0FFF00FF,0x0AFF00FF,0x05FF00FF,0x00FF00FF
};

100 colors, fade from green to yellow to red. :D


Edit: My server keeps crashing, is it because it is 0.3.7? Also, the bar is pretty wide (tall).

Thanks for the colors :p

kristo 16/02/2015 03:10 PM

Re: weapon-config.inc - Damage system with many features
 
I think the scripter should have some more liberty in choosing which parts of the include are being used. For example, I would like to disable the damage indicators (both visual and audible) because they don't fit to a roleplay server. I also have my own damage system (Armor is reduced only when the player's torso is shot. In any other case, his/her health is reduced). I haven't tried how they work together but I doubt that it's good.

Slice 16/02/2015 03:44 PM

Re: weapon-config.inc - Damage system with many features
 
To disable damage indicators and sounds:
pawn Code:
SetDamageFeed(false);
SetDamageSounds(0, 0);

For your damage system, you will need to do this:
pawn Code:
public OnPlayerDamage(&playerid, &Float:amount, &issuerid, &weapon, &bodypart) {
    if (bodypart == BODY_PART_BLABLA) {
        amount = amount / 2.0; // 50% damage
    }

    return 1;
}

Abagail 16/02/2015 06:43 PM

Re: weapon-config.inc - Damage system with many features
 
Why does OnPlayerDamage use variables passed by reference? Is there actually any reason behind this?

Slice 16/02/2015 07:21 PM

Re: weapon-config.inc - Damage system with many features
 
Yes - you may modify them. See the post before yours.

Here are a few more examples:
pawn Code:
public OnPlayerDamage(playerid, &Float:amount, &issuerid, &weapon, &bodypart) {
    // Disable helikill and carpark
    if (weapon == WEAPON_CARPARK || weapon == WEAPON_HELIBLADES)
    {
        return 0;
    }

    // Ignore low fall damage
    if (weapon == WEAPON_COLLISION && amount < 10.0)
    {
        return 0;
    }

    // the time in milliseconds between the last 3 shots
    // SHOT - time - SHOT - time - SHOT
    new avg_rate = AverageShootRate(issuerid, 2);

    // Lower rapid fire damage (C-bug fast shooting)
    if (avg_rate != -1) {
        if (weapon == WEAPON_DEAGLE && avg_rate < 500) {
            amount /= 1.4;
        } else if (weapon == WEAPON_SHOTGSPA && avg_rate < 250) {
            amount /= 1.4;
        }
    }

    // Increase headshot damage
    if (IsBulletWeapon(weapon) && bodypart == 9) {
        amount *= 1.25;
    }

    return 1;
}


All times are GMT. The time now is 05:13 AM.

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