Post by ShaunCraft15 on Jan 10, 2023 16:52:42 GMT
This Plugin is not normal unlimited clip, it's a special unlimited clip like the zp server SilentGamerz, finally i did it well, this project from 4 months
Here is The Code:
/*-----------------------------------------------------------------------------------------------------
[ZP] Extra Items: Unlimited Clip
- Plugin Information:
* This Plugin is same as default unlimited clip, but with SilentGamerz Style
- Credits:
CarsonMotion: No Recoil Plugin Owner, I Use Some Codes From His Plugin
- Support Me on YouTube:
* Link: https://www.youtube.com/channel/UCWVhiguRxt4tyacImGjiqQw
- Releases:
V1.0:
* First Release
* Multi ZP Support (ZP43, ZP50)
* Natives Support
V1.1.1:
* Fixed The Unlimited Clip Still When Infected & Cured
* Added Item Limit
Sorry For bad english!!!
Enjoy With This Plugin :)
------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------{ Definitions }-----------------------------------------------------*/
// Remove "//" If You Are Using Zombie Plague 5.0 or above
//#define USE_ZP50
// If You Modify The Plugin Please Don't Change The Author Name, Just Add Like This "ShaunCraft || User"
#define PLUGIN "[ZP43||ZP50] Extra Items: Unlimited Clip"
#define VERSION "1.1.1"
#define AUTHOR "ShaunCraft"
// Max Players Count
#define MAXPLAYERS 32
// Don't Modify The Value
#define UNLIMITED_CLIP_VALUE 99839
// Change ZP Prefix Here
#define ZP_PREFIX "^1[^4ZP^1] "
#if defined USE_ZP50
#define GetPlayerBit(%1,%2) (%1 & (1 << (%2 & 31)))
#define GetPlayerBitBoolean(%1,%2) (GetPlayerBit(%1,%2) ? true : false)
#define SetPlayerBit(%1,%2) %1 |= (1 << (%2 & 31))
#define ClearPlayerBit(%1,%2) %1 &= ~(1 << (%2 & 31))
#endif
/*-------------------------------------------------{ Includes }-----------------------------------------------------*/
#include < amxmodx >
#include < cstrike >
#include < fakemeta >
#include < hamsandwich >
#if defined USE_ZP50
#include < zp50_items >
#include < zp50_core >
#else
#include < zombieplague >
#endif
/*-------------------------------------------------{ Variables And Constants }-----------------------------------------------------*/
#if defined USE_ZP50
new g_iUnlimited_Clip, g_iDeployAccess
#else
new g_iUnlimited_Clip[ MAXPLAYERS+1 ], g_iDeployAccess[ MAXPLAYERS+1 ]
#endif
// Item Limitation
new g_iLimit[ MAXPLAYERS+1 ], cvar_limit, g_iPcvarLimit
// CS Player CBase Offsets (win32)
const PDATA_SAFE = 2
const OFFSET_ACTIVE_ITEM = 373
// Item Name & Cost
new const Item_Name[] = { "Unlimited Clip (One Round)" }
const Item_Cost = 30
new iItemID
const WEAPONS_BITSUM = (1<<CSW_KNIFE|1<<CSW_HEGRENADE|1<<CSW_FLASHBANG|1<<CSW_SMOKEGRENADE|1<<CSW_C4)
/*-------------------------------------------------{ Plugins Registeration & Hams }-----------------------------------------------------*/
public plugin_init( )
{
register_plugin(PLUGIN, VERSION, AUTHOR)
#if defined USE_ZP50
iItemID = zp_items_register( Item_Name, Item_Cost )
#else
iItemID = zp_register_extra_item( Item_Name, Item_Cost, ZP_TEAM_HUMAN )
#endif
cvar_limit = register_cvar("zp_unlimited_clip_limit", "1")
register_event( "HLTV", "Event_NewRound", "a", "1=0", "2=0" )
new iWeaponName[ 24 ]
for (new i = 1; i <= 30; i++)
{
if ( !(WEAPONS_BITSUM & 1 << i) && get_weaponname( i, iWeaponName, 23 ) )
{
RegisterHam( Ham_Item_Deploy, iWeaponName, "cBaseWeapon_Deploy_Pre")
RegisterHam( Ham_Weapon_Reload, iWeaponName, "cBaseWeapon_Reload_Pre" )
}
}
}
/*-------------------------------------------------{ Natives }-----------------------------------------------------*/
public plugin_natives( )
{
#if defined ZP50
register_native( "zp_item_unlimited_clip_get", "native_get_user_unlimited_clip", 1 )
register_native( "zp_item_unlimited_clip_set", "native_set_user_unlimited_clip", 1 )
#else
register_native( "zp_get_user_unlimited_clip", "native_get_user_unlimited_clip", 1 )
register_native( "zp_get_user_unlimited_clip", "native_set_user_unlimited_clip", 1 )
#endif
}
public native_get_user_unlimited_clip( this )
{
#if defined USE_ZP50
return GetPlayerBitBoolean( g_iUnlimited_Clip, this )
#else
return g_iUnlimited_Clip[ this ]
#endif
}
public native_set_user_unlimited_clip( this, set )
{
if ( set )
{
#if defined USE_ZP50
SetPlayerBit( g_iUnlimited_Clip, this )
SetPlayerBit( g_iDeployAccess, this )
#else
g_iUnlimited_Clip[ this ] = true
g_iDeployAccess[ this ] = true
#endif
client_cmd( this, "weapon_knife" )
}
else
{
#if defined USE_ZP50
ClearPlayerBit( g_iUnlimited_Clip, this )
ClearPlayerBit( g_iDeployAccess, this )
#else
g_iUnlimited_Clip[ this ] = false
g_iDeployAccess[ this ] = false
#endif
new weapon_ent = fm_cs_get_current_weapon_ent( this )
if( !pev_valid( weapon_ent ) )
return;
cs_set_weapon_ammo( weapon_ent, 7 )
}
}
/*-------------------------------------------------{ Round Start Event & Plugin Cfg }-----------------------------------------------------*/
public Event_NewRound( )
{
for (new this; this <= 32; this++)
{
native_set_user_unlimited_clip( this, 0 )
g_iLimit[ this ] = 0
}
}
public plugin_cfg( )
{
g_iPcvarLimit = get_pcvar_num(cvar_limit)
}
/*-------------------------------------------------{ Infect & Cure Forward }-----------------------------------------------------*/
#if defined USE_ZP50
public zp_fw_core_infect_post( this )
{
if( native_get_user_unlimited_clip( this ) )
{
native_set_user_unlimited_clip( this, 0 )
}
}
public zp_fw_core_cure_post( this )
{
if( native_get_user_unlimited_clip( this ) )
{
native_set_user_unlimited_clip( this, 0 )
}
}
#else
public zp_user_infected_post( this )
{
if( native_get_user_unlimited_clip( this ) )
{
native_set_user_unlimited_clip( this, 0 )
}
}
public zp_user_humanized_post( this )
{
if( native_get_user_unlimited_clip( this ) )
{
native_set_user_unlimited_clip( this, 0 )
}
}
#endif
/*-------------------------------------------------{ Extra Items }-----------------------------------------------------*/
#if defined USE_ZP50
public zp_fw_items_select_pre( this, itemid )
{
if( itemid == iItemID )
{
// This Item For Human Only
if( zp_core_is_zombie( this ) )
return ZP_ITEM_DONT_SHOW;
// Already Have Unlimited Clip?
if( native_get_user_unlimited_clip( this ) )
return ZP_ITEM_NOT_AVAILABLE;
// When The Cvar Set To 0 The Item Limitaion Will Be Disabled
if( g_iPcvarLimit )
{
static g_iText[128]
if(g_iLimit >= g_iPcvarLimit)
{
formatex(g_iText, charsmax(g_iText), "[%d/%d]", g_iLimit, g_iPcvarLimit)
zp_items_menu_text_add(g_iText)
return ZP_ITEM_NOT_AVAILABLE;
}
else
{
formatex(g_iText, charsmax(g_iText), "[%d/%d]", g_iLimit, g_iPcvarLimit)
zp_items_menu_text_add(g_iText)
return ZP_ITEM_AVAILABLE;
}
}
return ZP_ITEM_AVAILABLE;
}
return ZP_ITEM_AVAILABLE;
}
public zp_fw_items_select_post( this, itemid )
{
if( itemid == iItemID )
{
native_set_user_unlimited_clip( this, 1 )
g_iLimit[ this ]++
}
}
#else
public zp_extra_item_selected( this, itemid )
{
if ( itemid == iItemID )
{
// Already Have Unlimited Clip?
if( native_get_user_unlimited_clip( this ) )
{
PrintColorChat( this, "You Already Have Unlimited Clip" )
return ZP_PLUGIN_HANDLED;
}
// When The Cvar Set To 0 The Item Limitaion Will Be Disabled
if( g_iPcvarLimit )
{
if( g_iLimit[ this ] >= g_iPcvarLimit )
{
PrintColorChat( this, "You Reached Item Limit" )
return ZP_PLUGIN_HANDLED;
}
}
native_set_user_unlimited_clip( this, 1 )
g_iLimit[ this ]++
}
return PLUGIN_CONTINUE;
}
#endif
/*-------------------------------------------------{ Unlimited Clip System }-----------------------------------------------------*/
public cBaseWeapon_Deploy_Pre( this )
{
new pPlayer; pPlayer = get_pdata_cbase(this, 41, 4)
if( native_get_user_unlimited_clip( pPlayer ) )
{
#if defined USE_ZP50
if( GetPlayerBit( g_iDeployAccess, pPlayer ) )
#else
if( g_iDeployAccess[ pPlayer ] )
#endif
{
new weapon_ent = fm_cs_get_current_weapon_ent( pPlayer )
if( !pev_valid( weapon_ent ) )
return;
new current_ammo = cs_get_weapon_ammo( weapon_ent )
// If The Current Clip is same
if( current_ammo == UNLIMITED_CLIP_VALUE )
return;
// Apply The Unlimited Clip & bugfix
set_task( 0.1, "ApplyUnlimited_Clip", weapon_ent )
}
}
}
public ApplyUnlimited_Clip( this )
{
// Set The Weapon Ammo Like SG
cs_set_weapon_ammo( this, UNLIMITED_CLIP_VALUE )
}
public cBaseWeapon_Reload_Pre( this )
{
new pPlayer; pPlayer = get_pdata_cbase(this, 41, 4)
if( native_get_user_unlimited_clip( pPlayer ) )
{
// Block The Reload When Unlimited Clip Activated
return HAM_SUPERCEDE;
}
return PLUGIN_CONTINUE;
}
/*-------------------------------------------------{ Stocks }-----------------------------------------------------*/
// Get User Current Weapon Entity
stock fm_cs_get_current_weapon_ent( id )
{
// Prevent server crash if entity's private data not initalized
if ( pev_valid( id ) != PDATA_SAFE )
return -1;
return get_pdata_cbase( id, OFFSET_ACTIVE_ITEM );
}
stock PrintColorChat( target, const message[], any:... )
{
static buffer[512], msg_SayText = 0
if( !msg_SayText ) msg_SayText = get_user_msgid("SayText")
// Send to everyone
if (!target)
{
static player, maxplayers, argscount
maxplayers = get_maxplayers()
argscount = numargs()
for (player = 1; player <= maxplayers; player++)
{
// Not connected
if (!is_user_connected(player))
continue;
// Remember changed arguments
static arg_index, changed_args[20], changedcount // [20] = max LANG_PLAYER occurencies
changedcount = 0
// Replace LANG_PLAYER with player id
for (arg_index = 2; arg_index < argscount; arg_index++)
{
if (getarg(arg_index) == LANG_PLAYER && arg_index + 1 < argscount)
{
// Check if next param string is a registered language translation
static lang_key[64], arg_subindex
arg_subindex = 0
while ((lang_key[arg_subindex] = getarg(arg_index + 1, arg_subindex++))) { /* keep looping */ }
if (GetLangTransKey(lang_key) != TransKey_Bad)
{
setarg(arg_index, 0, player)
changed_args[changedcount++] = arg_index
arg_index++ // skip next argument since we know it's a translation key
}
}
}
// Format message for player (+add ZP prefix)
vformat(buffer, charsmax(buffer), message, 3)
format(buffer, charsmax(buffer), "%s%s", ZP_PREFIX, buffer)
// Send it
message_begin(MSG_ONE_UNRELIABLE, msg_SayText, _, player)
write_byte(player)
write_string(buffer)
message_end()
// Replace back player id's with LANG_PLAYER
for (arg_index = 0; arg_index < changedcount; arg_index++)
setarg(changed_args[arg_index], 0, LANG_PLAYER)
}
}
// Send to specific target
else
{
// Format message for player (+add ZP prefix)
vformat(buffer, charsmax(buffer), message, 3)
format(buffer, charsmax(buffer), "%s%s", ZP_PREFIX, buffer)
// Send it
message_begin(MSG_ONE, msg_SayText, _, target)
write_byte(target)
write_string(buffer)
message_end()
}
}