AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help regarding "CurWeapon" (https://forums.alliedmods.net/showthread.php?t=272275)

Krtola 09-27-2015 05:56

Help regarding "CurWeapon"
 
Biohazard mode have this function:
PHP Code:

register_event("CurWeapon""event_curweapon""be""1=1"

PHP Code:

public event_curweapon(id)
{
    if(!
is_user_alive(id))
        return 
PLUGIN_CONTINUE
    
    
static weapon
    weapon 
read_data(2)

    static 
ammotype
    ammotype 
get_pcvar_num(cvar_ammo)
    
    if(!
ammotype || (AMMOWP_NULL & (1<<weapon)))
        return 
PLUGIN_CONTINUE

    
static maxammo
    
switch(ammotype)
    {
        case 
1maxammo g_weapon_ammo[weapon][MAX_AMMO]
        case 
2maxammo g_weapon_ammo[weapon][MAX_CLIP]
    }

    if(!
maxammo)
        return 
PLUGIN_CONTINUE
    
    
switch(ammotype)
    {
        case 
1:
        {
            static 
ammo
            ammo 
cs_get_user_bpammo(idweapon)
            
            if(
ammo 1
                
cs_set_user_bpammo(idweaponmaxammo)
        }
        case 
2:
        {
            static 
clipclip read_data(3)
            if(
clip 1)
            {
                static 
weaponname[32]
                
get_weaponname(weaponweaponname31)
                
                static 
ent 
                ent 
find_ent_by_owner(-1weaponnameid)
                
                
cs_set_weapon_ammo(entmaxammo)
            }
        }
    }    
    return 
PLUGIN_CONTINUE


The purpose of this is to adjust whether the players have unlimited ammo,or unlimited clip.
My question is:Could this be implemented without the use of Curweapon?

Bugsy 09-27-2015 09:25

Re: Help regarding "CurWeapon"
 
Yes, most things can be done multiple ways. Why do you want to not use the CurWeapon event?

Krtola 09-27-2015 11:37

Re: Help regarding "CurWeapon"
 
I read everywhere that the function CurWeapon call very often and that can cause lag in game.
So I decided to changde/delete CurWeapon in every plugin.
About this topic : many plugin I have reviewed on this forum but everywhere is used CurWeapon.
Give me an example for this problem,how can I realize this please?

Depresie 09-28-2015 06:31

Re: Help regarding "CurWeapon"
 
Well, you could use Ham Primary Attack i think, but it will be called almost as often as CurWeapon does...
I don't think the author of Biohazzard used it in that case because it was inefficient...

Krtola 09-28-2015 06:40

Re: Help regarding "CurWeapon"
 
Ham Primary Attack=bad idea
I have in mind that this function does the occasion of each reload(every time when player reload weapon),but do not know how I can do that.

Depresie 09-28-2015 16:24

Re: Help regarding "CurWeapon"
 
There is Ham_Weapon_Reload, and you can check the weapon's bullets there, but i think you will encounter bugs that way...
Stick to CurWeapon, i use it in over 10 plugins and i have 20-30% cpu usage on a heavy modified ZP 5.0 version...

You are wasting time trying to optimize that code... Biohazzard has 2000 lines of code.. i got 10k only in nade modes plugin...

z0mbiland 09-29-2015 15:52

Re: Help regarding "CurWeapon"
 
you don't have a good host server or what? i play on your server and i have allmost full fps / no lagg; some players have a bad internet connection and they are moving in "teleporting mode" ))); and yes this depends on a good configuration off plugins; about eating cpu/net packets/net bandwidth space - if you have a low bandwidth this may cause lag to players/ 15 players - 15 slots - more bandwidth and fast data packet sender to client side; some net packets drop it and that information never come to player = this make the screen freeze for a ms/short time; these errors can affect cpu and make it highter; are few zombie servers full of plugins installed and well customized - they don't have any problems with lag or fps;
when you write in console "developer 1" you will see you have an repeating error from a weapon, this flood the backgroung of the client console and eat some of his fps!

aron9forever 10-02-2015 11:41

Re: Help regarding "CurWeapon"
 
curweapon is called when the hud info regarding wep is changed
that means it will be called for every shot you take, every reload and when you switch weps

since your code is about bullets, there is no better function for that


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

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