AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid player id 0 (https://forums.alliedmods.net/showthread.php?t=253338)

KiLLeR. 12-20-2014 10:21

Invalid player id 0
 
Error:
Code:

L 12/20/2014 - 17:10:34: Invalid player id 0
L 12/20/2014 - 17:10:34: [AMXX] Displaying debug trace (plugin "test.amxx")
L 12/20/2014 - 17:10:34: [AMXX] Run time error 10: native error (native "get_user_weapon")
L 12/20/2014 - 17:10:34: [AMXX]    [0] skill_system.sma::fw_PlayerTakeDamage (line 382)

and code from plugin:
PHP Code:

public fw_PlayerTakeDamage(thisidinflictoridattackerFloat:damagedamagebits)
{
    if(!
is_user_connected(idattacker) && !is_user_alive(idattacker) && this == idattacker)
        return 
HAM_IGNORED;
    
    if(
get_user_weapon(idattacker) != CSW_KNIFE
    { 
        
damage += 30
    
}
    else
    {
        
damage += 50
    
}
        
    
SetHamParamFloat(4damage);
    
    return 
HAM_IGNORED;



YamiKaitou 12-20-2014 10:24

Re: Invalid player id 0
 
Check to make sure idattacker is actually a player

KiLLeR. 12-20-2014 10:51

Re: Invalid player id 0
 
Sorry, but I didn't understood what should I do.

HamletEagle 12-20-2014 10:56

Re: Invalid player id 0
 
Check if 1 <= idattacker <= maxplayers

RateX 12-20-2014 10:57

Re: Invalid player id 0
 
Read the first check you wrote, that's where the problem lies.
@HamletEagle: is_user_connected is enough :)

Bugsy 12-20-2014 12:12

Re: Invalid player id 0
 
Quote:

Originally Posted by RateX (Post 2237590)
Read the first check you wrote, that's where the problem lies.
@HamletEagle: is_user_connected is enough :)

is_user_alive() checks valid player range (1 <-> maxplayers), connected status, and alive status all in one. You would not want to set damage to a connected but dead player.
PHP Code:

static cell AMX_NATIVE_CALL is_user_alive(AMX *amxcell *params/* 1 param */
{
    
int index params[1];
    
    if (
index || index gpGlobals->maxClients)
    {
        return 
0;
    }
    
    
CPlayerpPlayer GET_PLAYER_POINTER_I(index);

    if (
g_bmod_tfc)
    {
        
edict_t *pPlayer->pEdict;
        if (
e->v.flags FL_SPECTATOR || 
            (!
e->v.team || !e->v.playerclass))
        {
            return 
0;
        }
    }
    
    return ((
pPlayer->ingame && pPlayer->IsAlive()) ? 0);


I'm not sure what conditions you are checking, I just took a guess here.
PHP Code:

//If attacker is dead or attacker hurt himself, return.
if( !is_user_aliveidattacker ) || ( this == idattacker ) )
        return 
HAM_IGNORED


RateX 12-20-2014 12:43

Re: Invalid player id 0
 
@Bugsy: I was just talking about Hamlet's method of checking. Since the author's already check !is_user_connected, a connected player won't be out of 1 to maxplayers range.

Quote:

Originally Posted by Bugsy (Post 2237616)
I'm not sure what conditions you are checking, I just took a guess here.
PHP Code:

//If attacker is dead or attacker hurt himself, return.
if( !is_user_aliveidattacker ) || ( this == idattacker ) )
        return 
HAM_IGNORED


Yep, that's what I was referring to.
Anyway, welcome back! :)

KiLLeR. 12-20-2014 12:50

Re: Invalid player id 0
 
Quote:

Originally Posted by Bugsy (Post 2237616)
I'm not sure what conditions you are checking, I just took a guess here.
PHP Code:

//If attacker is dead or attacker hurt himself, return.
if( !is_user_aliveidattacker ) || ( this == idattacker ) )
        return 
HAM_IGNORED


I think there should be:
PHP Code:

//If attacker is dead or attacker hurt himself, return.
if( !is_user_aliveidattacker ) && ( this == idattacker ) )
        return 
HAM_IGNORED

I just want to increase or decrease taken damage from knife, weapon or fall.

This is the whole code:
PHP Code:

public fw_PlayerTakeDamage(thisidinflictoridattackerFloat:damagedamagebits)
{
    if(!
is_user_alive(idattacker) || this == idattacker)
        return 
HAM_IGNORED;
    
    if(
get_user_weapon(idattacker) != CSW_KNIFE
    { 
        
damage += // here we increase damage by shooting
    
}
    else
    {
        
damage += // here we increase damage by knife
    
}
    
    
damage -= // here we reduce damage from shooting
        
    
SetHamParamFloat(4damage);
    
    if(
damagebits DMG_FALL)
    {
        
damage -= // here we reduce damage from falling
        
        
SetHamParamFloat(4damage);
    }


Could I detected using the damagebits parameter when damage is caused by a knife and when a weapon?

Bugsy 12-20-2014 12:55

Re: Invalid player id 0
 
Quote:

Originally Posted by RateX (Post 2237631)
@Bugsy: I was just talking about Hamlet's method of checking. Since the author's already check !is_user_connected, a connected player won't be out of 1 to maxplayers range.



Yep, that's what I was referring to.
Anyway, welcome back! :)

Thanks!

His ultimate issue is using AND's instead of OR's in his statement, is_user_connected is also a redundancy.

His if-statement could return true if a player tossed a grenade to hurt himself then immediately disconnected.
PHP Code:

if(!is_user_connected(idattacker) && !is_user_alive(idattacker) && this == idattacker)
IF ( ( 
ATTACKER NOT CONNECTED ) AND ( ATTACKER NOT ALIVE ) AND ( VICTIM=ATTACKER ) ) 


HamletEagle 12-20-2014 13:05

Re: Invalid player id 0
 
@RateX, I just explained what Yami told him, not taking into account his code.


All times are GMT -4. The time now is 15:18.

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