AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   error 10 (cs_get_user_armor) (https://forums.alliedmods.net/showthread.php?t=224596)

Ardonicek 08-26-2013 06:49

error 10 (cs_get_user_armor)
 
This crashes server after spamming console with error 10 on cs_get_user_armor

Fix please?


PHP Code:

    if(Level[id] == 69
    { 
        new 
CsArmorType:armortype;
        if (
cs_get_user_armor(idarmortype) <= 100)
    {
        new 
CsArmorType:armortype;
        
cs_set_user_armor(idcs_get_user_armor(idarmortype) + 30armortype);
    }
    
set_user_rendering(idkRenderFxNone000kRenderTransAlpha185)
    
set_user_gravity(id0.7)
    
cs_set_user_money(id, (cs_get_user_money(id) + 1000))
    
cs_set_user_nvg(id1)
    
give_item(id"weapon_hegrenade")
    
give_item(id"weapon_flashbang")



YamiKaitou 08-26-2013 10:18

Re: error 10 (cs_get_user_armor)
 
Give us the complete error message

~Ice*shOt 08-26-2013 10:22

Re: error 10 (cs_get_user_armor)
 
I guess that you forgot to check is user alive? It's only guess because I don't know what kind of really are.

^SmileY 08-26-2013 10:37

Re: error 10 (cs_get_user_armor)
 
Quote:

Originally Posted by ~Ice*shOt (Post 2022006)
I guess that you forgot to check is user alive? It's only guess because I don't know what kind of really are.

Remember: is_user_alive enforcing a is_user_connected, so you do not need to check is_user_connected it is only is_user_alive

:)

Post full code to better resolution, but you need like this

if(Level[id] == 69)

change to

if((Level[id] == 69) && is_user_alive(id))

jimaway 08-26-2013 11:32

Re: error 10 (cs_get_user_armor)
 
i'm guessing the error comes from trying to set armor +30 with CS_ARMOR_NONE type

edit: or not

Black Rose 08-26-2013 16:35

Re: error 10 (cs_get_user_armor)
 
Quote:

Originally Posted by ^SmileY (Post 2022013)
Remember: is_user_alive enforcing a is_user_connected, so you do not need to check is_user_connected it is only is_user_alive

:)

Post full code to better resolution, but you need like this

if(Level[id] == 69)

change to

if((Level[id] == 69) && is_user_alive(id))

Since Level[id] is checked before is_user_alive() you may get an index out of bounds error on Level[].
They should be switched for best result.

Ardonicek 08-26-2013 16:54

Re: error 10 (cs_get_user_armor)
 
Quote:

Originally Posted by Black Rose (Post 2022241)
Since Level[id] is checked before is_user_alive() you may get an index out of bounds error on Level[].
They should be switched for best result.


So it should be like this?

PHP Code:

if((is_user_alive(id) && (Level[id] == 69)) 


Black Rose 08-26-2013 17:07

Re: error 10 (cs_get_user_armor)
 
It depends how the complete function looks. For this small script either way is fine...

Code:
if ( ! is_user_alive(id) )     return; if ( Level[id] == 69 ) {     // ...

Code:
if ( is_user_alive(id) && Level[id] == 69 ) {     // ...

Ardonicek 08-27-2013 02:03

Re: error 10 (cs_get_user_armor)
 
No more console errors, i think it works, thanks.

^SmileY 08-27-2013 07:23

Re: error 10 (cs_get_user_armor)
 
Quote:

Originally Posted by Black Rose (Post 2022258)
It depends how the complete function looks. For this small script either way is fine...

Code:
if ( ! is_user_alive(id) )     return; if ( Level[id] == 69 ) {     // ...

Code:
if ( is_user_alive(id) && Level[id] == 69 ) {     // ...


When you use a IF statement correctly you do not need an return in your code...


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

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