AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help needed]Exclusive damage rate (https://forums.alliedmods.net/showthread.php?t=274106)

RaZ_HU 11-01-2015 17:33

[Help needed]Exclusive damage rate
 
Hi, I am trying to make a VIP/ADMINS exclusive plugin for our fun server and it does work but meanwhile it generates errorlogs about get_user_weapon() function.

Can someone take a look at the code about what's wrong?

Code:
#include <amxmodx> #include <amxmisc> #include <hamsandwich> #define ACCESS ADMIN_CFG #define VERSION "0.2" new damageMultiplier new Float:dmgRate new clip, ammo public plugin_init() {     register_plugin("VIP Sebzes Bonusz", VERSION, "RaZ")     damageMultiplier = register_cvar("vipbonus_dmgrate", "1.3")     RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage") } public fw_TakeDamage(victim, inflictor, attacker, Float:damage) {     dmgRate = get_pcvar_float(damageMultiplier)     new iWeapon = get_user_weapon(attacker, clip, ammo)     new playerCount = get_maxplayers()         if(attacker > playerCount)         return PLUGIN_CONTINUE     if(attacker < 1)         return PLUGIN_CONTINUE     if(!attacker)         return PLUGIN_CONTINUE         if (is_user_connected(attacker) && is_user_alive(attacker) && get_user_flags(attacker) & ACCESS)     {         new iWeaponUsed = get_user_weapon(inflictor)         if(iWeapon == CSW_KNIFE || iWeapon == CSW_AWP || iWeapon == CSW_SCOUT || iWeaponUsed == CSW_HEGRENADE)             return PLUGIN_CONTINUE                 SetHamParamFloat(4, damage * dmgRate)     }         return HAM_HANDLED }

Detailed error log:
Quote:

L 11/01/2015 - 19:25:15: Start of error session.
L 11/01/2015 - 19:25:15: Info (map "cs_iraq") (file "addons/amxmodx/logs/error_20151101.log")
L 11/01/2015 - 19:25:15: Invalid player id 154
L 11/01/2015 - 19:25:15: [AMXX] Displaying debug trace (plugin "vipdmgbonus.amxx", version "0.2")
L 11/01/2015 - 19:25:15: [AMXX] Run time error 10: native error (native "get_user_weapon")
L 11/01/2015 - 19:25:15: [AMXX] [0] vipdmgbonus.sma::fw_TakeDamage (line 23)
L 11/01/2015 - 19:25:15: Invalid player id 155
L 11/01/2015 - 19:25:15: [AMXX] Displaying debug trace (plugin "vipdmgbonus.amxx", version "0.2")
L 11/01/2015 - 19:25:15: [AMXX] Run time error 10: native error (native "get_user_weapon")
L 11/01/2015 - 19:25:15: [AMXX] [0] vipdmgbonus.sma::fw_TakeDamage (line 23)
L 11/01/2015 - 19:25:15: Invalid player id 156
L 11/01/2015 - 19:25:15: [AMXX] Displaying debug trace (plugin "vipdmgbonus.amxx", version "0.2")
L 11/01/2015 - 19:25:15: [AMXX] Run time error 10: native error (native "get_user_weapon")
L 11/01/2015 - 19:25:15: [AMXX] [0] vipdmgbonus.sma::fw_TakeDamage (line 23)
L 11/01/2015 - 19:25:15: Invalid player id 329
L 11/01/2015 - 19:25:15: [AMXX] Displaying debug trace (plugin "vipdmgbonus.amxx", version "0.2")
L 11/01/2015 - 19:25:15: [AMXX] Run time error 10: native error (native "get_user_weapon")
L 11/01/2015 - 19:25:15: [AMXX] [0] vipdmgbonus.sma::fw_TakeDamage (line 23)
L 11/01/2015 - 19:25:28: Invalid player id -1
L 11/01/2015 - 19:25:28: [AMXX] Displaying debug trace (plugin "vipdmgbonus.amxx", version "0.2")
L 11/01/2015 - 19:25:28: [AMXX] Run time error 10: native error (native "get_user_weapon")
L 11/01/2015 - 19:25:28: [AMXX] [0] vipdmgbonus.sma::fw_TakeDamage (line 23)

Bugsy 11-01-2015 17:54

Re: [Help needed]Exclusive damage rate
 
You should use attacker here, not inflictor. Inflictor is not always the same as attacker, in the case of grenade damage, and possibly C4, it is the entity index of the grenade. I also fixed and improved other things that were done incorrectly.
Code:
if (is_user_connected(attacker) && is_user_alive(attacker) && get_user_flags(attacker) & ACCESS) {     new iWeaponUsed = get_user_weapon(inflictor)     if(iWeapon == CSW_KNIFE || iWeapon == CSW_AWP || iWeapon == CSW_SCOUT || iWeaponUsed == CSW_HEGRENADE)         return PLUGIN_CONTINUE             SetHamParamFloat(4, damage * dmgRate) }
Untested
PHP Code:


#include <amxmodx>
#include <hamsandwich>

#define VERSION "0.2"

#define MAX_PLAYERS 32
#define ACCESS ADMIN_CFG

new const DMG_GRENADE = ( << 24 );
new const 
IGNORE_WEAPONS = ( << CSW_KNIFE ) | ( << CSW_AWP ) | ( << CSW_SCOUT );

new 
pCVar_DamageRate;

public 
plugin_init()
{
    
register_plugin"VIP Sebzes Bonusz" VERSION "RaZ" );
    
    
pCVar_DamageRate register_cvar"vipbonus_dmgrate" "1.3" );

    
RegisterHamHam_TakeDamage "player" "fw_TakeDamage" ); 
}

public 
fw_TakeDamageiVictim iInflictor iAttacker Float:fDamage DamageBits )
{
    if( !( 
<= iAttacker <= MAX_PLAYERS ) || 
        ( 
DamageBits DMG_GRENADE ) ||
        !( 
get_user_flagsiAttacker ) & ACCESS ) ||
        ( ( 
<< get_user_weaponiAttacker ) ) & IGNORE_WEAPONS ) )
        return 
HAM_IGNORED;
        
    
SetHamParamFloatfDamage get_pcvar_floatpCVar_DamageRate ) )
    
    return 
HAM_HANDLED;



RaZ_HU 11-02-2015 14:41

Re: [Help needed]Exclusive damage rate
 
Tested and works perfectly without any errors, thank you sir for the help :D


All times are GMT -4. The time now is 17:56.

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