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

Heart Health


Post New Thread Reply   
 
Thread Tools Display Modes
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-16-2016 , 15:07   Re: Heart Health [1.1] [ Last up: 3 December of 2016 ]
Reply With Quote #21

Lol , i just observe in the code i'm already use engfunc alloc string ,look:

PHP Code:
    new iEnt engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocString"info_target" ) ); 
It is correct ?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-16-2016 , 15:16   Re: Heart Health [1.1] [ Last up: 3 December of 2016 ]
Reply With Quote #22

You have to cache that value, don't call this every time.
__________________
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-16-2016 , 15:31   Re: Heart Health [1.2] [ Last up: 16 December of 2016 ]
Reply With Quote #23

Done. Now i understand.

Edit: topic style changed.
Edit2: 'Changelog' moved inside of source file.
__________________
Project: Among Us

Last edited by Craxor; 12-17-2016 at 03:50.
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-18-2016 , 23:36   Re: Heart Health
Reply With Quote #24

I took a quick look and found the below items that should be addressed:
  1. Define gHealthEntity[] as a constant. You do this for the string defined above this but not for this one.
  2. gTimes[] does not need to be defined with a value of 0.0, this happens automatically. You only need this if you want a default value other than 0.
  3. In cmd_lives_reset(), you do not need to use get_players() and a for-loop to set all values in the array to 0. Just use arrayset().
  4. In hh_hook(), you should store the value of get_pcvar_num( CVS[HEALTH_LIMIT] ) in a variable. You should never call a get_[p]cvar_() native more than once for the same cvar in a function.
  5. This is more of a preference thing, but try to be consistent with your bracketing. If you have an if-else and you bracket the code in the if{}, you should also do it for the else{} code. Again, not required but IMO it looks nicer.
  6. In respawn_hook(), same issue with cvar CVS[RESPAWN_LIVES] as in #4. above. Store the value in a variable.
  7. You should move plugin_precache() and plugin_end() closer to plugin_init(). It's more organized keeping these plugin-oriented functions together.
  8. In client_authorized() and client_disconnect(), you can reduce the size of szData[] since a 10 digit number will likely never happen. 3 or 4 will probably be more than enough. In client_authorized(), you are better off using nvault_get() since this returns an integer. You can then eliminate the szData[11] and iTs variables and do not have to use str_to_num().
  9. You should define a max-players value and use that to size player arrays (#DEFINE MAX_PLAYERS 32) then do gArray[ MAX_PLAYERS + 1 ]) You define gLives at 33 and then gAuthId at 35 when they should be the same.
__________________

Last edited by Bugsy; 12-18-2016 at 23:41.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-19-2016 , 00:37   Re: Heart Health
Reply With Quote #25

Finally, bugsy post a review
__________________

Last edited by HamletEagle; 12-19-2016 at 00:38.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-19-2016 , 01:50   Re: Heart Health
Reply With Quote #26

Bugsy, about number 4:

I'm using them just once, they are 3 different cvars:

PHP Code:
        if( get_user_healthid ) < get_pcvar_numCVS[HEALTH_LIMIT] ) )
            {
                if( 
CTime >= gTimes[id] )
                {
                    
set_user_healthidget_user_healthid ) + get_pcvar_numCVS[HEALTH_AMMOUNT] ) );

                    
gTimes[id] = CTime floatget_pcvar_numCVS[HEALTH_TIME] ) ); 
And also about number 9, what do you mean? what i am doing with gArray after? Why gLives and gAuthid should be same if i'm taking number of Lives with gLives and gAuthId is the key in nvault, i don't understand at all here.
Edit: Something like this do you mean:
PHP Code:

#define Max_Players 32

new gLivesMax_Players ];
new 
gAuthIdMax_Players ][ 35 ]; 
# Also , bugsy about arrayset() , can i juse use this stock:

PHP Code:
UTIL_ArrayArr[] , Size Value )
{
    for ( new 
Size i++ )
    {
        
gLivesArr] ] = Value;    
    }

Usage:
PHP Code:
    UTIL_Array Players Num ); 
I checked arrayset, and i almost the same, is making a loop through the array and set the value for each-one in part so is not big difference: https://github.com/alliedmodders/amx...modx.cpp#L4397
__________________
Project: Among Us

Last edited by Craxor; 12-19-2016 at 02:46.
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-19-2016 , 06:15   Re: Heart Health
Reply With Quote #27

Quote:
Originally Posted by Craxor View Post
Bugsy, about number 4:

I'm using them just once, they are 3 different cvars:
My mistake, I didn't notice they were different in hh_hook() . They are the same in respawn_hook(), though.

Quote:
Originally Posted by Craxor View Post
And also about number 9, what do you mean? what i am doing with gArray after? Why gLives and gAuthid should be same if i'm taking number of Lives with gLives and gAuthId is the key in nvault, i don't understand at all here.
Edit: Something like this do you mean:
gLives[33]
gAuthId[35][33]

What I mean is both arrays are for storing a value for each player. You size gLives at 33 (for 32 players), while g_AuthId is sized at 35 (for 34 players). You should be consistent between your variables if they serve the same relative purpose. And yes what I suggested is using Max_Players + 1 to size all player arrays.

Quote:
Originally Posted by Craxor View Post
# Also , bugsy about arrayset() , can i juse use this stock:

I checked arrayset, and i almost the same, is making a loop through the array and set the value for each-one in part so is not big difference: https://github.com/alliedmodders/amx...modx.cpp#L4397
It really doesn't matter how you reset the array, but it makes no sense to use get_players(). Use a for-loop (without get_players() ) or arrayset().
__________________

Last edited by Bugsy; 12-19-2016 at 06:16.
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-19-2016 , 06:43   Re: Heart Health
Reply With Quote #28

again about arrayset() , how do i know how many players are connected on the server if i'm using arrayset() with no get_players()

arrayset( Array, Value , Size ) - what will be the size ?

i realy don't know can you show a me an example?

Another q: i will not get any index out of bounds error ?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-19-2016 , 06:57   Re: Heart Health
Reply With Quote #29

Quote:
Originally Posted by Craxor View Post
again about arrayset() , how do i know how many players are connected on the server if i'm using arrayset() with no get_players()

arrayset( Array, Value , Size ) - what will be the size ?

i realy don't know can you show a me an example?

Another q: i will not get any index out of bounds error ?
The goal is to reset the entire array, nothing to do with how many players are currently connected. See if you can figure it out. If you correctly set the size value you will get no errors.
__________________
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-19-2016 , 07:04   Re: Heart Health
Reply With Quote #30

Tested and works like that, it is ok?
PHP Code:
arraysetgLivessizeof gLives ); 
Also you didn't answer if is correct like that ( 35 should be size of a steamid, 33 the array ):
PHP Code:
#define Max_Players 32

new gLivesMax_Players ];
new 
gAuthIdMax_Players ][ 35 ]; 
__________________
Project: Among Us

Last edited by Craxor; 12-19-2016 at 07:06.
Craxor is offline
Send a message via ICQ to Craxor
Reply


Thread Tools
Display Modes

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 03:51.


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