AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Non player is out of range? (https://forums.alliedmods.net/showthread.php?t=246370)

proffs 08-16-2014 15:48

Non player is out of range?
 
I don't get it why I get this error.

Code:

L 08/16/2014 - 11:06:15: [CSTRIKE] Non-player entity 0 out of range
L 08/16/2014 - 11:06:15: [AMXX] Displaying debug trace (plugin "trainpcw.amxx")
L 08/16/2014 - 11:06:15: [AMXX] Run time error 10: native error (native "cs_get_weapon_ammo")
L 08/16/2014 - 11:06:15: [AMXX]    [0] trainpcw.sma::eDeath (line 9999999)

PHP Code:

public eDeath()  

        new 
iKiller read_data(1); 
        new 
iVictim read_data(2);
        new 
szKillMSG[50];
        new 
weapon_id fm_find_ent_by_owner(-1weapon_weaponiKiller);
      
      
        if( 
IsPlayer(iKiller) && is_user_alive(iKiller) && Tonly[iKiller]) 
        { 
        if( 
iVictim != iKiller
        { 
            switch( 
cs_get_weapon_ammo(weapon_id) )
            {
            case 
0formatex(szKillMSGcharsmax(szKillMSG), "K");
            case 
1formatex(szKillMSGcharsmax(szKillMSG), "P");
            }
            
            
set_hudmessage(02550, -1.00.406.02.50.00.0, -1);
            
show_hudmessage(iKillerszKillMSG);
        
            if( 
is_user_alive(iKiller) )
            {
            if( 
weapon_id 
            {
                if( 
cs_get_weapon_ammo(weapon_id) == )
                {
                
cs_set_weapon_ammo(weapon_id1); 
                }
            }
            }
        } 
        } 
         
        return 
PLUGIN_HANDLED



baneado 08-16-2014 17:50

Re: Non player is out of range?
 
create weapon_id and szKillMSG after the two iKiller checks

why are you using is_user_alive two times?

create a new var to save the value of cs_get_weapon_ammo, before using this native check if weapon_id is valid

proffs 08-16-2014 17:53

Re: Non player is out of range?
 
Quote:

Originally Posted by baneado (Post 2184878)
create weapon_id and szKillMSG after the two iKiller checks

What? Sorry for being now, Can you show me? Never worked with these type of stuff.

colossus 08-16-2014 18:28

Re: Non player is out of range?
 
PHP Code:

public eDeath()   
{  
    new 
iKiller read_data(1);  
    new 
iVictim read_data(2); 
    new 
szKillMSG[50]; 
    new 
weapon_id fm_find_ent_by_owner(-1weapon_weaponiKiller);
    
    if(!
is_valid_ent(weaponid))
        return 
PLUGIN_CONTINUE
        
    
new ammo cs_get_weapon_ammo(weapon_id)
       
    if(
IsPlayer(iKiller) && is_user_alive(iKiller) && Tonly[iKiller])  
    {  
        if( 
iVictim != iKiller)  
        {
            if(
ammo
            { 
                
formatex(szKillMSGcharsmax(szKillMSG), "P"); 
                
cs_set_weapon_ammo(weapon_id1); 
            }
            else
                
formatex(szKillMSGcharsmax(szKillMSG), "K"); 
                
            
set_hudmessage(02550, -1.00.406.02.50.00.0, -1); 
            
show_hudmessage(iKillerszKillMSG)
        }
    }
    return 
PLUGIN_CONTINUE


TEST

proffs 08-17-2014 04:54

Re: Non player is out of range?
 
Quote:

Originally Posted by colossus (Post 2184895)
PHP Code:

public eDeath()   
{  
    new 
iKiller read_data(1);  
    new 
iVictim read_data(2); 
    new 
szKillMSG[50]; 
    new 
weapon_id fm_find_ent_by_owner(-1weapon_weaponiKiller);
    
    if(!
is_valid_ent(weaponid))
        return 
PLUGIN_CONTINUE
        
    
new ammo cs_get_weapon_ammo(weapon_id)
       
    if(
IsPlayer(iKiller) && is_user_alive(iKiller) && Tonly[iKiller])  
    {  
        if( 
iVictim != iKiller)  
        {
            if(
ammo
            { 
                
formatex(szKillMSGcharsmax(szKillMSG), "P"); 
                
cs_set_weapon_ammo(weapon_id1); 
            }
            else
                
formatex(szKillMSGcharsmax(szKillMSG), "K"); 
                
            
set_hudmessage(02550, -1.00.406.02.50.00.0, -1); 
            
show_hudmessage(iKillerszKillMSG)
        }
    }
    return 
PLUGIN_CONTINUE


TEST

Now you don't get +1 bullet if u kill someone

baneado 08-17-2014 08:26

Re: Non player is out of range?
 
on the mobile..

PHP Code:

public eDeath()
{
   new 
iKiller read_data(1);
   new 
iVictim read_data(2);

   if (
IsPlayer(Killer) && iVictim != iKiller && Tonly[iKiller])
   {
       new 
weapon_id find_ent_by_owner(-1"weapon_*"iKiller);
       if (!
weapon_id) return;

       new 
szKillMSG[3];
       switch (
cs_get_weapon_ammo(weapon_id))
       {
          case 
0: {
              
//formatex....
              
cs_set_weapon_ammo(weapon_id1);
          }
          case 
1: {
             
//formatex...
          
}
          default: return;
       }

        
//hudmessage
   
}



proffs 08-17-2014 11:01

Re: Non player is out of range?
 
Quote:

Originally Posted by baneado (Post 2185137)
on the mobile..

PHP Code:

public eDeath()
{
   new 
iKiller read_data(1);
   new 
iVictim read_data(2);

   if (
IsPlayer(Killer) && iVictim != iKiller && Tonly[iKiller])
   {
       new 
weapon_id find_ent_by_owner(-1"weapon_*"iKiller);
       if (!
weapon_id) return;

       new 
szKillMSG[3];
       switch (
cs_get_weapon_ammo(weapon_id))
       {
          case 
0: {
              
//formatex....
              
cs_set_weapon_ammo(weapon_id1);
          }
          case 
1: {
             
//formatex...
          
}
          default: return;
       }

        
//hudmessage
   
}



Makes no sense, tells me to return n shitz :S
Ty for helping...
I get few errors still.

baneado 08-17-2014 12:07

Re: Non player is out of range?
 
post errors.

the code should work as you want

proffs 08-17-2014 13:25

Re: Non player is out of range?
 
Quote:

Originally Posted by baneado (Post 2185246)
post errors.

the code should work as you want

Get this
Warning: Function "eDeath" should return a value on line 979

3,4 times

fysiks 08-17-2014 17:31

Re: Non player is out of range?
 
Quote:

Originally Posted by proffs (Post 2185291)
Get this
Warning: Function "eDeath" should return a value on line 979

3,4 times

So, what are the errors that are preventing you from compiling your plugin?

To get rid of warnings like that, you need to make sure that if you return a value anywhere in your function that you also return a value in every possible situation in that function.

If it is simply a death message that you are hooking, you don't need to return anything (i.e. you don't return PLUGIN_CONTINUE or PLUGIN_HANDLED) because the return value does nothing. Simply use "return".


All times are GMT -4. The time now is 12:57.

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