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

Optimize Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-17-2018 , 17:57   Re: Optimize Plugin
Reply With Quote #21

Quote:
Originally Posted by E1_531G View Post
if(is_user_alive(id)) - if true, player is connected and alive.
if(is_user_connected(id) && !is_user_alive(id)) - if true, player is connected but not alive.
There's no need to check is_user_connected if you're already checking is_user_alive.
is_user_alive itself checks if player is connected.

Code:
static cell AMX_NATIVE_CALL is_user_alive(AMX *amx, cell *params) /* 1 param */ {     int index = params[1];     if (index < 1 || index > gpGlobals->maxClients)     {         return 0;     }     CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);     if (g_bmod_tfc)     {         edict_t *e = pPlayer->pEdict;         if (e->v.flags & FL_SPECTATOR ||             (!e->v.team || !e->v.playerclass))         {             return 0;         }     }
    return ((pPlayer->ingame && pPlayer->IsAlive()) ? 1 : 0);
}
__________________

Last edited by edon1337; 07-17-2018 at 17:57.
edon1337 is offline
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 07-17-2018 , 18:35   Re: Optimize Plugin
Reply With Quote #22

I know I don't need check connected with is_user_alive.

My question is:

!is_user_alive && is_user_connected
__________________
A plugin that is needed for every server.
PHP Code:
public client_connect(id)
{
    if(
get_user_iq(id) < 80)
    {
        
server_cmd("kick #%d 'You have kicked from the server because your IQ is not high enough'"get_user_userid(id));
    }

PurposeLessx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-17-2018 , 18:58   Re: Optimize Plugin
Reply With Quote #23

Quote:
Originally Posted by PurposeLessx View Post
I know I don't need check connected with is_user_alive.

My question is:

!is_user_alive && is_user_connected
Put some logic before posting, is_user_alive and !is_user_alive are both the same native, you're just using a negation mark.

PHP Code:
is_user_alive(id
This is what happens inside the AMXX module
Code:
pPlayer->ingame && pPlayer->IsAlive()

So in your case:

!is_user_alive would return true if either player is not connected or not alive.

What you're doing:

!is_user_alive(id) && is_user_connected(id)

What happens in the module:
Code:
pPlayer->ingame && !(pPlayer->IsAlive()) && pPlayer->ingame

So basically you're calling a native for nothing.

Last edited by edon1337; 07-17-2018 at 19:02.
edon1337 is offline
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 07-18-2018 , 03:28   Re: Optimize Plugin
Reply With Quote #24

I have thought like this.

Code:
is_user_alive  = pPlayer->ingame && pPlayer->IsAlive()

!is_user_alive = !(pPlayer->ingame && pPlayer->IsAlive())
So, Even if player is not in game, is_user_alive will be false. !is_user_alive will be true.
?
__________________
A plugin that is needed for every server.
PHP Code:
public client_connect(id)
{
    if(
get_user_iq(id) < 80)
    {
        
server_cmd("kick #%d 'You have kicked from the server because your IQ is not high enough'"get_user_userid(id));
    }

PurposeLessx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-18-2018 , 06:49   Re: Optimize Plugin
Reply With Quote #25

Quote:
Originally Posted by PurposeLessx View Post
I have thought like this.

Code:
is_user_alive  = pPlayer->ingame && pPlayer->IsAlive()

!is_user_alive = !(pPlayer->ingame && pPlayer->IsAlive())
So, Even if player is not in game, is_user_alive will be false. !is_user_alive will be true.
?
Well, if you're checking

is_user_alive, the game will return
true - if player is in game (connected) and alive.
false - if either player is not connected or not alive.


!is_user_alive, will return the same as is_user_alive just that now you're checking for the negative value.

This
if(!is_user_alive(id))

will return the same but you'll be checking (!) not

So:
if(!is_user_alive(id))

Player not alive or not connected.

Last edited by edon1337; 07-18-2018 at 06:51.
edon1337 is offline
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 07-18-2018 , 08:10   Re: Optimize Plugin
Reply With Quote #26

I want to revive all dead people. If not connected, how I will revive?

Code:
Player not alive or not connected.
__________________
A plugin that is needed for every server.
PHP Code:
public client_connect(id)
{
    if(
get_user_iq(id) < 80)
    {
        
server_cmd("kick #%d 'You have kicked from the server because your IQ is not high enough'"get_user_userid(id));
    }

PurposeLessx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-18-2018 , 08:13   Re: Optimize Plugin
Reply With Quote #27

Quote:
Originally Posted by PurposeLessx View Post
I want to revive all dead people. If not connected, how I will revive?

Code:
Player not alive or not connected.
Well, you can't revive someone who isn't in the server, can you? To revive all the dead players do this:
PHP Code:
new szPlayers32 ], iNum;
get_playersszPlayersiNum"b" );

static 
iTempID;

for( new 
iiTempIDi++ )
{
    
iTempID szPlayers];
    
    
ExecuteHamHam_CS_RoundRespawniTempID );

edon1337 is offline
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 07-18-2018 , 08:13   Re: Optimize Plugin
Reply With Quote #28

So, how can I optimize this plugin?

Spoiler
__________________
A plugin that is needed for every server.
PHP Code:
public client_connect(id)
{
    if(
get_user_iq(id) < 80)
    {
        
server_cmd("kick #%d 'You have kicked from the server because your IQ is not high enough'"get_user_userid(id));
    }

PurposeLessx is offline
PurposeLessx
Senior Member
Join Date: Jun 2017
Old 07-18-2018 , 08:14   Re: Optimize Plugin
Reply With Quote #29

Quote:
Originally Posted by edon1337 View Post
Well, you can't revive someone who isn't in the server, can you? To revive all the dead players do this:
PHP Code:
new szPlayers32 ], iNum;
get_playersszPlayersiNum"b" );

static 
iTempID;

for( new 
iiTempIDi++ )
{
    
iTempID szPlayers];
    
    
ExecuteHamHam_CS_RoundRespawniTempID );

I will check if he is still dead or still in the server in the handler of menu.
So I need it.
__________________
A plugin that is needed for every server.
PHP Code:
public client_connect(id)
{
    if(
get_user_iq(id) < 80)
    {
        
server_cmd("kick #%d 'You have kicked from the server because your IQ is not high enough'"get_user_userid(id));
    }

PurposeLessx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-18-2018 , 08:15   Re: Optimize Plugin
Reply With Quote #30

Quote:
Originally Posted by PurposeLessx View Post
So, how can I optimize this plugin?

Spoiler
It's good like that, no need to optimize
edon1337 is offline
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 16:18.


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