sfcnr/pawno/include/irresistible/features/weapon_drop.inc

202 lines
5.4 KiB
PHP
Raw Normal View History

2018-05-21 09:21:53 +00:00
/*
* Irresistible Gaming (c) 2018
* Developed by Lorenc_
* Module: weapon_drop.inc
* Purpose: weapon drop system for players
*/
/* ** Includes ** */
#include < YSI\y_hooks >
/* ** Error Handling ** */
#if !defined __WEAPONDAMAGEINC__
#error "This module requires weapon data functions"
#endif
#define WEAPON_DROP_ENABLED
/* ** Definitions ** */
#define MAX_WEAPON_DROPS ( 50 )
2018-05-24 20:29:21 +00:00
#define WEAPON_HEALTH ( 100 )
#define WEAPON_ARMOUR ( 101 )
2018-05-21 09:21:53 +00:00
/* ** Variables ** */
enum E_WEAPONDROP_DATA {
E_WEAPON_ID, E_AMMO, E_PICKUP,
E_EXPIRE_TIMESTAMP, E_SLOT_ID
};
static g_weaponDropData [ MAX_WEAPON_DROPS ] [ E_WEAPONDROP_DATA ];
static Iterator: weapondrop < MAX_WEAPON_DROPS >;
2018-05-24 20:29:21 +00:00
static const g_rankHealthPayout[ ] = { 100, 75, 50, 45, 40, 35, 30, 25, 20, 15, 10 };
static g_HealthPickup;
2018-05-21 09:21:53 +00:00
/* ** Hooks ** */
2018-05-24 20:29:21 +00:00
hook OnGameModeInit( )
{
g_HealthPickup = CreateDynamicPickup( 1240, 3, -1980.3679, 884.4898, 45.2031 );
return 1;
}
2018-05-21 09:21:53 +00:00
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
2018-05-24 20:29:21 +00:00
static
2018-05-21 09:21:53 +00:00
Float: X, Float: Y, Float: Z;
if ( IsPlayerConnected( killerid ) && ! IsPlayerNPC( killerid ) )
2018-05-21 09:21:53 +00:00
{
if ( IsPlayerJailed( playerid ) || IsPlayerInPaintBall( playerid ) || IsPlayerInEvent( playerid ) || IsPlayerDueling( playerid ) )
2018-05-24 20:29:21 +00:00
return 1;
GetPlayerPos( playerid, X, Y, Z );
2018-05-24 20:29:21 +00:00
new
killer_rank = GetPlayerRank( killerid ),
expire_time = gettime( ) + 180;
2018-05-21 09:21:53 +00:00
for ( new slotid = 0; slotid < 13; slotid++ )
{
new
weaponid,
ammo;
GetPlayerWeaponData( playerid, slotid, weaponid, ammo );
2018-05-24 20:29:21 +00:00
// third of what player had
2018-06-09 04:11:47 +00:00
ammo /= 10;
2018-05-24 20:29:21 +00:00
// check valid parameters and shit
2018-05-21 09:21:53 +00:00
if ( weaponid != 0 && 1 < ammo < 5000 && ! IsWeaponBanned( weaponid ) ) {
2018-05-24 20:29:21 +00:00
CreateWeaponPickup( weaponid, ammo, slotid, X + fRandomEx( 0.5, 3.0 ), Y + fRandomEx( 0.5, 3.0 ), Z, expire_time );
2018-05-21 09:21:53 +00:00
}
}
2018-05-24 20:29:21 +00:00
// health drop
CreateWeaponPickup( WEAPON_HEALTH, g_rankHealthPayout[ killer_rank ], 0, X + fRandomEx( 0.5, 3.0 ), Y + fRandomEx( 0.5, 3.0 ), Z, expire_time );
2018-05-21 09:21:53 +00:00
}
return 1;
}
hook OnPlayerPickUpDynPickup( playerid, pickupid )
{
new keys;
new existing_weapon;
new existing_ammo;
2018-05-24 20:29:21 +00:00
// Health Pickups
if ( pickupid == g_HealthPickup ) {
SetPlayerHealth( playerid, 100.0 );
return 1;
}
// Player Drops
2018-05-21 09:21:53 +00:00
foreach ( new dropid : weapondrop )
{
if ( g_weaponDropData[ dropid ] [ E_PICKUP ] == pickupid )
{
2018-05-24 20:29:21 +00:00
if ( g_weaponDropData[ dropid ] [ E_WEAPON_ID ] == WEAPON_HEALTH )
{
new
Float: health;
if ( GetPlayerHealth( playerid, health ) )
{
// no weed like effects
2018-06-09 04:11:47 +00:00
if ( ( health += float( g_weaponDropData[ dropid ] [ E_AMMO ] ) ) > 100.0 ) {
2018-05-24 20:29:21 +00:00
health = 100.0;
2018-06-09 04:11:47 +00:00
}
2018-05-24 20:29:21 +00:00
SetPlayerHealth( playerid, health );
}
2018-05-21 09:21:53 +00:00
}
2018-05-24 20:29:21 +00:00
else
{
new current_weapon = GetPlayerWeapon( playerid );
2018-05-24 20:29:21 +00:00
GetPlayerKeys( playerid, keys, existing_weapon, existing_weapon );
GetPlayerWeaponData( playerid, g_weaponDropData[ dropid ] [ E_SLOT_ID ], existing_weapon, existing_ammo );
2018-05-21 09:21:53 +00:00
new holding_replace_key = ( keys & KEY_ACTION );
2018-05-24 20:29:21 +00:00
// if ( existing_weapon > g_weaponDropData[ dropid ] [ E_WEAPON_ID ] && ! ( keys & KEY_ACTION ) && existing_ammo )
if ( existing_weapon != g_weaponDropData[ dropid ] [ E_WEAPON_ID ] && ! holding_replace_key && existing_ammo )
2018-05-24 20:29:21 +00:00
{
ShowPlayerHelpDialog( playerid, 2500, "Hold ~r~~k~~PED_ANSWER_PHONE~~w~ To Take %s", ReturnWeaponName( g_weaponDropData[ dropid ] [ E_WEAPON_ID ] ) );
return 1;
}
2018-05-21 09:21:53 +00:00
2018-05-24 20:29:21 +00:00
#if defined AC_INCLUDED
p_PlayerHasWeapon[ playerid ] { g_weaponDropData[ dropid ] [ E_WEAPON_ID ] } = true;
#endif
GivePlayerWeapon( playerid, g_weaponDropData[ dropid ] [ E_WEAPON_ID ], g_weaponDropData[ dropid ] [ E_AMMO ] );
// don't change player weapon
if ( ! holding_replace_key ) {
SetPlayerArmedWeapon( playerid, current_weapon );
}
2018-05-24 20:29:21 +00:00
}
// destroy health pickup
2018-05-21 09:21:53 +00:00
PlayerPlaySound( playerid, 1150, 0.0, 0.0, 0.0 );
DestroyWeaponPickup( dropid );
return 1;
}
}
return 1;
}
/* ** Functions ** */
stock CreateWeaponPickup( weaponid, ammo, slotid, Float: X, Float: Y, Float: Z, expire_time ) {
new handle = Iter_Free( weapondrop );
if ( handle != ITER_NONE )
{
2018-05-24 20:29:21 +00:00
g_weaponDropData[ handle ] [ E_PICKUP ] = CreateDynamicPickup( weaponid == WEAPON_HEALTH ? 1240 : GetWeaponModel( weaponid ), 1, X, Y, Z );
2018-05-21 09:21:53 +00:00
g_weaponDropData[ handle ] [ E_EXPIRE_TIMESTAMP ] = expire_time;
g_weaponDropData[ handle ] [ E_WEAPON_ID ] = weaponid;
g_weaponDropData[ handle ] [ E_AMMO ] = ammo;
g_weaponDropData[ handle ] [ E_SLOT_ID ] = slotid;
2018-05-24 20:29:21 +00:00
Iter_Add( weapondrop, handle );
2018-05-21 09:21:53 +00:00
}
else
{
ClearInactiveWeaponDrops( gettime( ) );
}
return handle;
}
stock DestroyWeaponPickup( handle )
{
if ( ! Iter_Contains( weapondrop, handle ) ) return 0;
DestroyDynamicPickup( g_weaponDropData[ handle ] [ E_PICKUP ] );
g_weaponDropData[ handle ] [ E_EXPIRE_TIMESTAMP ] = 0;
g_weaponDropData[ handle ] [ E_PICKUP ] = -1;
Iter_Remove( weapondrop, handle );
return 1;
}
stock ClearInactiveWeaponDrops( global_timestamp )
{
foreach ( new dropid : weapondrop ) if ( g_weaponDropData[ dropid ] [ E_EXPIRE_TIMESTAMP ] != 0 && global_timestamp > g_weaponDropData[ dropid ] [ E_EXPIRE_TIMESTAMP ] )
{
new
cur = dropid;
DestroyDynamicPickup( g_weaponDropData[ dropid ] [ E_PICKUP ] );
g_weaponDropData[ dropid ] [ E_EXPIRE_TIMESTAMP ] = 0;
g_weaponDropData[ dropid ] [ E_PICKUP ] = -1;
Iter_SafeRemove( weapondrop, cur, dropid );
}
return 1;
}