Raised This Month: $51 Target: $400
 12% 

xBullets Rule ~ (Anti-AWP Camp Plugin) [2015]


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands       
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-11-2015 , 00:35   xBullets Rule ~ (Anti-AWP Camp Plugin) [2015]
Reply With Quote #1


Written by Syturi0
Version 2.1
Updated 17nd August 2015



xDescription ~
This simple plugin is mainly for Surf Mod Servers wich have the Rule that only allows players to shoot X bullets of AWP every Xsecs./spot.
The main porpuse of that rule is to make players move/surf more, and stay less time camping with AWP.
It forces AWP to have X ammo (3 by default), once the player shoots the X bullets, he will have to wait X seconds (15 by default) before he can shoot them again.
Also, the refresh time starts at the first bullet, wich means your ammo still gets refreshed even if you only used 1 bullet.

xCvars ~
amx_time_xbullets - The amount of time player has to wait before he gets new ammo. (15 seconds by default)
amx_ammo_xbullets - The amount bullets player gets on AWP. (3 bullets by default)

xCredits ~
Kazalu - For helping me with the base code.
xPaw - Took some ideas from his Thread design.
Jhob94 - Some improvements.
Attached Files
File Type: sma Get Plugin or Get Source (xBullets_Rule.sma - 735 views - 6.3 KB)

Last edited by Syturi0; 03-30-2016 at 03:53.
Syturi0 is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-11-2015 , 00:35   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #2

xChange Log ~
Version: 1.0 (11 January 2015)
- Public release.

Version: 1.1 (12 January 2015)
- Optimizations & improvements.

Version: 2.0 (10 August 2015)
- Fixed a bug, the plugin now works properly.
- Removed unnecessary code and loops.

Version: 2.1 (17 August 2015)
- More optimizations.
- Fixed a error that appeared on console.
- Added cvar to see servers using this plugin.

xServers using this Plugin ~
Gametracker

xDownloads ~
Version: 1.0 & 1.1 = 50
Version: 2.0 = 9

xOld Versions ~
Attached Files
File Type: sma Get Plugin or Get Source (xBullets_Rule_v1.0.sma - 643 views - 3.1 KB)
File Type: sma Get Plugin or Get Source (xBullets_Rule_v1.1.sma - 617 views - 5.6 KB)
File Type: sma Get Plugin or Get Source (xBullets_Rule_v2.0.sma - 712 views - 5.5 KB)

Last edited by Syturi0; 08-16-2015 at 21:57.
Syturi0 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 01-11-2015 , 11:09   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #3

Some improvements:
PHP Code:
public Function()
{
    new 
Players[32
    new 
playerCountiidweaponctimexcvar
    get_players
(PlayersplayerCount"a"
    
    for (
i=0playerCounti++) 
    {
        
id Players[i
        
        
weapon get_user_weapon(id)
        
        if(!
wait[id])
        {
            if(
get_user_weapon(idammoclip) == CSW_AWP)
            {
                if(
ammo get_pcvar_num(xAmmo))
                {
                    
cs_set_weapon_ammo(find_ent_by_owner(-1"weapon_awp"id), get_pcvar_num(xAmmo))
                    
cs_set_user_bpammo(idCSW_AWP0)
                }
            
                else    
// Starts the 'xTime' on the first bullet.
                
{
                    
startTime get_gametime()
                    
wait[id] = true
                
}
            }
        }
    
        else
        {
            
ctime get_gametime() - startTime
            xcvar 
float(get_pcvar_num(xTime)) // Why dont you just use a float cvar instead?
            
            
if(ctime xcvar)
            {
                
cs_set_user_bpammo(idCSW_AWP0)
                
                if(
weapon == CSW_AWP)
                    
client_print(idprint_center"Next Ammo in [%d]"floatround(float(get_pcvar_num(xTime)) - get_gametime() + startTime))    // Countdown Message
                
                
else
                    
client_print(id,print_center" ")    // To insta-hide the Countdown Message if player changes weapon.
            
}
            
            else if(
ctime xcvar >= 0)
            {
                
cs_set_weapon_ammo(find_ent_by_owner(-1"weapon_awp"id), get_pcvar_num(xAmmo))
                
wait[id] = false
                
                
if(weapon != CSW_AWP)
                    
client_print(idprint_center"Your AWP Ammo is ready!")
                else
                    
client_print(id,print_center" ")    // To insta-hide the Countdown Message at 0 sec.
            
}
        }
    }

Anyway, using a task of 0.1 seems to be cpu overkill. And as you said, it's for surf, in surf cpu is very important since this may reduce fps.
It's better to hook primary attack and loop a task of 1 second during the cooldown time that is defined in the cvar and remove the task when can use awp again.
__________________

Last edited by Jhob94; 01-11-2015 at 11:09.
Jhob94 is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-11-2015 , 21:33   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #4

Quote:
Originally Posted by Jhob94 View Post
Some improvements:
Spoiler


Anyway, using a task of 0.1 seems to be cpu overkill. And as you said, it's for surf, in surf cpu is very important since this may reduce fps.
It's better to hook primary attack and loop a task of 1 second during the cooldown time that is defined in the cvar and remove the task when can use awp again.
Thank you.
Updated to Version: 1.1

PHP Code:
ctime get_gametime() - startTime
xcvar 
float(get_pcvar_num(xTime)) // Why dont you just use a float cvar instead? 
^ Gave me errors.

Last edited by Syturi0; 01-11-2015 at 21:34.
Syturi0 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-11-2015 , 22:30   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #5

Quote:
^ Gave me errors.
What errors? Use get_pcvar_float will save you from needing to float a int.

Last edited by RateX; 01-11-2015 at 22:30.
RateX is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 01-11-2015 , 23:14   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #6

Quote:
Originally Posted by RateX View Post
What errors? Use get_pcvar_float will save you from needing to float a int.
Quote:
Warning 213: tag mismatch
Syturi0 is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-12-2015 , 00:51   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #7

Not for me:
PHP Code:
xTime register_cvar("amx_time_xbullets""15.0")
xcvar get_pcvar_float(xTime
RateX is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 03-05-2015 , 21:14   Re: xBullets Rule ~ [11-01-2015]
Reply With Quote #8

Please expand your knowledge some more before posting plugins. You've missed quite a few very basic concepts here. Essentially this plugin needs to be completely re-written to avoid unnecessary loops, unnecessary checks, wasted memory, etc. Unapproved.
hornet is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 08-10-2015 , 09:39   Re: xBullets Rule ~ [UPDATED 10-08-2015]
Reply With Quote #9

Quote:
- Version: 2.0 (10 August 2015)
* Fixed a bug, the plugin now works properly.
* Removed unnecessary code and loops.
Syturi0 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-10-2015 , 12:02   Re: xBullets Rule ~ (Anti-AWP Camp Plugin) [UPDATED 10-08-2015]
Reply With Quote #10

Why do you use both PrimaryAttack and CurWeapon ? This does not make sense, you should look at what game does and do the same.
1.here
2.here

All you have to do is to hook PrimaryAttack as post and set m_flNextPrimaryAttack and m_flNextSecondaryAttack with the delay. It may be needed to this in Deploy too. Basically, you can check in Deploy is the restriction exists and set it again(and substracting the elapsed time).
You won't have to use silly task, to remove his bullets and whatever you are doing.

So, this is how I would do it:
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

const m_flPrevPrimaryAttack   78
const m_flLastFireTime        79
const m_flNextPrimaryAttack   46
const m_flNextSecondaryAttack 47
const m_pPlayer               41
const XoWeapon                4

new Float:CustomDelay[33]

public 
plugin_init()
{
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_awp""CBasePlayerWeapon_PrimaryAttack"true)
    
RegisterHam(Ham_Item_Deploy"weapon_awp""CBasePlayerWeapon_ItemDeploy"true)
}

public 
CBasePlayerWeapon_ItemDeploy(Entity)
{
    if(
pev_valid(Entity))
    {
        new 
id get_pdata_cbase(Entitym_pPlayerXoWeapon)
        new 
Float:GameTime get_gametime()
        
        if(
CustomDelay[id] > GameTime)
        {
            
            
set_pdata_float(Entitym_flNextPrimaryAttackCustomDelay[id]- GameTimeXoWeapon)
            
set_pdata_float(Entitym_flNextSecondaryAttackCustomDelay[id] - GameTime XoWeapon)
        }
    }
}

public 
CBasePlayerWeapon_PrimaryAttack(Entity)
{
    if(
pev_valid(Entity))
    {
        new 
id get_pdata_cbase(Entitym_pPlayerXoWeapon)
        
        
CustomDelay[id] = GetNextAttackDelay(Entity15.0
        
set_pdata_float(Entitym_flNextPrimaryAttackCustomDelay[id], XoWeapon)
        
set_pdata_float(Entitym_flNextSecondaryAttackCustomDelay[id], XoWeapon)
        
        
CustomDelay[id] = CustomDelay[id] + get_gametime()
    }
}

Float:GetNextAttackDelay(EntityFloat:Delay)
{
    new 
Float:CurrentGameTime get_gametime()
    if(
get_pdata_float(Entitym_flLastFireTimeXoWeapon) == 0.0 || get_pdata_float(Entitym_flNextPrimaryAttackXoWeapon) == -1.0)
    {
        
set_pdata_float(Entitym_flLastFireTimeCurrentGameTimeXoWeapon)
        
set_pdata_float(Entitym_flPrevPrimaryAttackDelayXoWeapon)
    }

    new 
Float:ElapsedFireTime CurrentGameTime get_pdata_float(Entitym_flLastFireTimeXoWeapon)
    new 
Float:TimeOffset      0.0

    
if(ElapsedFireTime 0.0)
    {
        
TimeOffset ElapsedFireTime get_pdata_float(Entitym_flPrevPrimaryAttackXoWeapon)
    }

    new 
Float:NextDelay Delay TimeOffset
    
    set_pdata_float
(Entitym_flLastFireTimeCurrentGameTimeXoWeapon)
    
set_pdata_float(Entitym_flPrevPrimaryAttackNextDelayXoWeapon)
    
    return 
NextDelay

The "15" is the delay.
__________________

Last edited by HamletEagle; 08-10-2015 at 13:48.
HamletEagle is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode