Raised This Month: $51 Target: $400
 12% 

Solved Problem with set_user_health native.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-11-2020 , 12:42   Problem with set_user_health native.
Reply With Quote #1

Hi,

I have this piece of code:
PHP Code:
public Regeneration(id)
{
    if(
get_user_health(id) >= get_pcvar_num(CvarMAXHP))
    {
        
set_user_health(id,get_pcvar_num(CvarMAXHP))
        return 
PLUGIN_HANDLED
    
}
    
    else
    {
    
/*-->>*/ set_user_health(id,get_user_health(id) + get_pcvar_num(PcvarHpRegenAdd)) /*<<--*/
    
}
    return 
PLUGIN_CONTINUE

The problem is when it is used, it throws this debug state:
PHP Code:
L 04/11/2020 13:42:00: [AMXXDisplaying debug trace (plugin "VIP_DEV.amxx"version "1.3")
L 04/11/2020 13:42:00: [AMXXRun time error 10native error (native "set_user_health")
L 04/11/2020 13:42:00: [AMXX]    [0VIP_DEV.sma::Regeneration (line 1366)
L 04/11/2020 13:42:01: [GOInvalid player 11 
After thinking some time, I wrote it like this and it didn't work:
PHP Code:
public Regeneration(id)
{
    if(!
is_user_alive(id)
        return 
PLUGIN_HANDLED
        
    
if(get_user_health(id) >= get_pcvar_num(CvarMAXHP))
    {
        
set_user_health(id,get_pcvar_num(CvarMAXHP))
        return 
PLUGIN_HANDLED
    
}
    
    else
    {
    
/*-->>*/ set_user_health(id,get_user_health(id) + get_pcvar_num(PcvarHpRegenAdd)) /*<<--*/
    
}
    return 
PLUGIN_CONTINUE

So... what's the problem with that line, or where did I wrong?
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 04-11-2020 at 18:11.
Shadows Adi is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-11-2020 , 12:44   Re: Problem with set_user_health native.
Reply With Quote #2

When is that function called? Can u provide the full code?
__________________

Last edited by Napoleon_be; 04-11-2020 at 12:44.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 04-11-2020 , 12:47   Re: Problem with set_user_health native.
Reply With Quote #3

check is_user_connected too.
__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 04-11-2020 at 13:03.
+ARUKARI- is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-11-2020 , 12:49   Re: Problem with set_user_health native.
Reply With Quote #4

Quote:
Originally Posted by +ARUKARI- View Post
check is_user_connected and is_user_alive
He tried that, and is_user_alive() is enough since it also checks if the user is connected.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-11-2020 , 12:58   Re: Problem with set_user_health native.
Reply With Quote #5

The function is called through set_task:
PHP Code:
 set_task(2.0,"Regeneration",id+regen,_,_,"b"
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 04-11-2020 , 12:59   Re: Problem with set_user_health native.
Reply With Quote #6

Quote:
Originally Posted by Shadows Adi View Post
The function is called through set_task:
PHP Code:
 set_task(2.0,"Regeneration",id+regen,_,_,"b"
PHP Code:
public Regeneration(id)
{
    
id -= regen
    
if(!is_user_alive(id)
        return 
PLUGIN_HANDLED
.... 
__________________
GitHub
SteamWishlist

六四天安門事件

Last edited by +ARUKARI-; 04-11-2020 at 13:06.
+ARUKARI- is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-11-2020 , 18:10   Re: Problem with set_user_health native.
Reply With Quote #7

Thanks guys, I solved it with a server restart.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-12-2020 , 04:34   Re: Problem with set_user_health native.
Reply With Quote #8

Quote:
Originally Posted by Shadows Adi View Post
Thanks guys, I solved it with a server restart.
Just a simple server restart won't do, check what ARUKARI said.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-12-2020 , 06:11   Re: Problem with set_user_health native.
Reply With Quote #9

Quote:
Originally Posted by +ARUKARI- View Post
PHP Code:
public Regeneration(id)
{
    
id -= regen
    
if(!is_user_alive(id)
        return 
PLUGIN_HANDLED
.... 
I added it into code, thanks
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:37.


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