Post by ShaunCraft15 on Jan 27, 2023 17:44:28 GMT
Hello, i have small problem in my unlimited clip plugin, when round started the plugin restore the current weapon clip but the other weapon no how i can fix this???
/*-----------------------------------------------------------------------------------------------------
[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
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.0"
#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
// CS Player CBase Offsets (win32)
const PDATA_SAFE = 2
const OFFSET_ACTIVE_ITEM = 373
// Item Name & Cost
new const Item_Name[] = { "Unlimited Clip \r(One Round)" }
const Item_Cost = 30
new iItemID
new const MAXCLIP[] = { -1, 13, -1, 10, 1, 7, -1, 30, 30, 1, 30, 20, 25, 30, 35, 25, 12, 20,
10, 30, 100, 8, 30, 30, 20, 2, 7, 30, 30, -1, 50 }
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
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 fActiveItem = get_pdata_cbase(this, OFFSET_ACTIVE_ITEM);
new weapon = cs_get_weapon_id(fActiveItem)
new weapon_ent = fm_cs_get_current_weapon_ent( this )
if( !pev_valid( weapon_ent ) )
return;
cs_set_weapon_ammo( weapon_ent, MAXCLIP[weapon] )
}
}
/*-------------------------------------------------{ Round Start Event }-----------------------------------------------------*/
public Event_NewRound( )
{
for (new this; this <= 32; this++)
{
if( native_get_user_unlimited_clip( this ) )
{
native_set_user_unlimited_clip( this, 0 )
}
}
}
/*-------------------------------------------------{ Extra Items }-----------------------------------------------------*/
#if defined USE_ZP50
public zp_fw_items_select_pre( this, itemid )
{
if( itemid == iItemID )
{
if( zp_core_is_zombie( this ) )
return ZP_ITEM_DONT_SHOW;
if( native_get_user_unlimited_clip( this ) )
return ZP_ITEM_NOT_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 )
}
}
#else
public zp_extra_item_selected( this, itemid )
{
if ( itemid == iItemID )
{
if( native_get_user_unlimited_clip( this ) )
{
PrintColorChat( this, "You Already Have Unlimited Clip" )
return ZP_PLUGIN_HANDLED;
}
else native_set_user_unlimited_clip( this, 1 )
}
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()
}
}