AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimize Plugin (https://forums.alliedmods.net/showthread.php?t=309208)

PurposeLessx 07-17-2018 13:07

Optimize Plugin
 
Hey friends, I make a plugin. It has 3951 lines so I want to make it optimized for server.
In menus, what I should use?

Code:

static data[6], name[32], access, callback, key;
menu_item_getinfo(menu, item, access, data, charsmax(data), _, _, callback);
key = str_to_num(data);

// or

new data[6], name[32], access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), _, _, callback);
new key = str_to_num(data);


klippy 07-17-2018 13:11

Re: Optimize Plugin
 
It doesn't matter.

PurposeLessx 07-17-2018 13:19

Re: Optimize Plugin
 
So what should I do for optimizing plugin?

Example commands;

PHP Code:

//#define MAX_CLIENTS                     32 
            
new TeamName:team;
            for(new 
Uid 1Uid <= MAX_CLIENTSUid++)
            {
                
team get_member(Uidm_iTeam);

                if(
team == TEAM_CT && is_user_alive(Uid))
                {
                    
set_entvar(Uidvar_takedamageDAMAGE_NO);
                    
set_entvar(Uidvar_health99999.0);
                    
unammocuk[Uid] = true;
                }
            }
            
clcmd_ctmenu(id);
            
rh_emit_sound2(00CHAN_AUTOsound_godmodeVOL_NORMATTN_NORMATTN_NORM0PITCH_NORM); 


OciXCrom 07-17-2018 13:28

Re: Optimize Plugin
 
For starters, using get_players() to loop all players.

PurposeLessx 07-17-2018 13:37

Re: Optimize Plugin
 
Quote:

Originally Posted by OciXCrom (Post 2604299)
For starters, using get_players() to loop all players.

The all servers which use my plugin is 32 players. Do I need check it?

OciXCrom 07-17-2018 13:42

Re: Optimize Plugin
 
Do they have all 32 players online 24/7? Probably not.
The only right way to loop all players is by using get_players().

PurposeLessx 07-17-2018 13:46

Re: Optimize Plugin
 
Quote:

Originally Posted by OciXCrom (Post 2604306)
Do they have all 32 players online 24/7? Probably not.
The only right way to loop all players is by using get_players().

Is get_players more optimized than for(new .... , also ?

maqi 07-17-2018 14:00

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604308)
Is get_players more optimized than for(new .... , also ?

What kind of question is this ?

PurposeLessx 07-17-2018 14:18

Re: Optimize Plugin
 
My english is not good enough as you all. My bad.
I guess you understand my question, so there is no problem :D.

"Is using get_players more optimized than using for(new Uid = 1 ; Uid <= 32 ; Uid++)"

OciXCrom 07-17-2018 14:33

Re: Optimize Plugin
 
If it wasn't, would I be writing this in a thread that says "OPTIMIZE PLUGIN"?

Ghosted 07-17-2018 15:27

Re: Optimize Plugin
 
What about increasing heap size by #pragma dynamic ? (default value = 4096)

PurposeLessx 07-17-2018 15:28

Re: Optimize Plugin
 
Quote:

Originally Posted by OciXCrom (Post 2604323)
If it wasn't, would I be writing this in a thread that says "OPTIMIZE PLUGIN"?

Wow, you are right. So can you give me some examples about using "stock bool or nothing"

For example;

First; there is anything tag of command. What if I add a tag (stock or public)
Second; there is stock and bool. What if I delete stock or bool?
Code:

rg_set_user_rendering(index, fx = kRenderFxNone, {Float,_}:color[3] = {0.0,0.0,0.0}, render = kRenderNormal, Float:amount = 0.0)
{
        set_entvar(index, var_renderfx, fx);
        set_entvar(index, var_rendercolor, color);
        set_entvar(index, var_rendermode, render);
        set_entvar(index, var_renderamt, amount);
}

stock bool:Stuck(index)
{
        static Float:origin[3];
        get_entvar(index, var_origin, origin);
        engfunc(EngFunc_TraceHull, origin,origin, IGNORE_MONSTERS, get_entvar(index, var_flags) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN, 0, 0);
        return (get_tr2(0, TR_StartSolid)) ? true:false;
}


OciXCrom 07-17-2018 15:38

Re: Optimize Plugin
 
You shouldn't be using "stock" in the .sma files. This tag is used only if there is a possibility that the function will not be used at all. Since this is your code and you added the function, you're probably going to use it as well, so remove the "stock" tag. Only use "stock" in include files where not all functions must be used in the code when included.

"bool" is pretty self-explainatory. If the variable is tagged with "bool", then the return value of the function should also be "bool". Bools can be only true or false.

PurposeLessx 07-17-2018 16:09

Re: Optimize Plugin
 
Quote:

Originally Posted by OciXCrom (Post 2604345)
You shouldn't be using "stock" in the .sma files. This tag is used only if there is a possibility that the function will not be used at all. Since this is your code and you added the function, you're probably going to use it as well, so remove the "stock" tag. Only use "stock" in include files where not all functions must be used in the code when included.

"bool" is pretty self-explainatory. If the variable is tagged with "bool", then the return value of the function should also be "bool". Bools can be only true or false.

Got it perfectly. If I use true,false, I should use bool. If not, I should not use any tag as stock :)
I guess it is not wrong? :)

OciXCrom 07-17-2018 16:20

Re: Optimize Plugin
 
Bool limits the variable to true or false (or 1 and 0). You don't need any tag if you don't need this.

PurposeLessx 07-17-2018 16:29

Re: Optimize Plugin
 
Okay, One question about is_user_alive.

I know is_user_alive checks is_user_connected.
But I don't know something.

Which I should use?

PHP Code:

// I know this
//if(is_user_connected(id) && is_user_alive(id))
if(is_user_alive(id))

//But this?
//Which?
if(!is_user_alive(id) && is_user_connected(id))
if(!
is_user_alive(id)) 


edon1337 07-17-2018 17:02

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604350)
Okay, One question about is_user_alive.

I know is_user_alive checks is_user_connected.
But I don't know something.

Which I should use?

PHP Code:

// I know this
//if(is_user_connected(id) && is_user_alive(id))
if(is_user_alive(id))

//But this?
//Which?
if(!is_user_alive(id) && is_user_connected(id))
if(!
is_user_alive(id)) 


Player can't be alive if he's not connected, so the 2nd one is wrong.

PurposeLessx 07-17-2018 17:31

Re: Optimize Plugin
 
So I must check if user connected while checking !is_user_alive

E1_531G 07-17-2018 17:33

Re: Optimize Plugin
 
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.

PurposeLessx 07-17-2018 17:35

Re: Optimize Plugin
 
Okay, got it thanks :)

edon1337 07-17-2018 17:57

Re: Optimize Plugin
 
Quote:

Originally Posted by E1_531G (Post 2604362)
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); }

PurposeLessx 07-17-2018 18:35

Re: Optimize Plugin
 
I know I don't need check connected with is_user_alive.

My question is:

!is_user_alive && is_user_connected

edon1337 07-17-2018 18:58

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604377)
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.

PurposeLessx 07-18-2018 03:28

Re: Optimize Plugin
 
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.
?

edon1337 07-18-2018 06:49

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604426)
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.

PurposeLessx 07-18-2018 08:10

Re: Optimize Plugin
 
I want to revive all dead people. If not connected, how I will revive?

Code:

Player not alive or not connected.

edon1337 07-18-2018 08:13

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604479)
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 );



PurposeLessx 07-18-2018 08:13

Re: Optimize Plugin
 
So, how can I optimize this plugin?

Spoiler

PurposeLessx 07-18-2018 08:14

Re: Optimize Plugin
 
Quote:

Originally Posted by edon1337 (Post 2604481)
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.

edon1337 07-18-2018 08:15

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604482)
So, how can I optimize this plugin?

Spoiler

It's good like that, no need to optimize

PurposeLessx 07-18-2018 08:19

Re: Optimize Plugin
 
Okay I will use it :)

The revive plugin I use; Revive Dead CTs

Spoiler

OciXCrom 07-18-2018 08:29

Re: Optimize Plugin
 
Quote:

if(!is_user_alive(Uid) && is_user_connected(Uid))
Have you even been listening for the past 4 pages?

PurposeLessx 07-18-2018 08:30

Re: Optimize Plugin
 
Yeah I am listening. I am just trying to learn. If you will not help, do not post please.

PurposeLessx 07-18-2018 08:54

Re: Optimize Plugin
 
So, while hudmessage plugin is working, server is lagging. What is the reason?

edon1337 07-18-2018 09:01

Re: Optimize Plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2604511)
So, while hudmessage plugin is working, server is lagging. What is the reason?

Either the host PC is old either your PC.

PurposeLessx 07-18-2018 09:04

Re: Optimize Plugin
 
Quote:

Originally Posted by edon1337 (Post 2604514)
Either the host PC is old either your PC.

Just 3 seconds lagging and server became normal. Really interesting.

E1_531G 07-18-2018 09:42

Re: Optimize Plugin
 
Quote:

Originally Posted by edon1337 (Post 2604367)
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.

You again? ...

Only if(!is_user_alive(id)) doesn't ensure than the player is dead AND connected.
This check will fail if the player isn't connected.
This means, this way you can't know if the player is dead OR he is simply disconnected.

edon1337 07-18-2018 09:53

Re: Optimize Plugin
 
Quote:

Originally Posted by E1_531G (Post 2604519)
You again? ...

Only if(!is_user_alive(id)) doesn't ensure than the player is dead AND connected.
This check will fail if the player isn't connected.
This means, this way you can't know if the player is dead OR he is simply disconnected.

Are you sad that you're seeing me?
Why would you check/do something on a player that isn't connected?

Using is_user_alive is enough, you're just mis-informing him.

Quote:

Originally Posted by E1_531G (Post 2604519)
if(!is_user_alive(id)) doesn't ensure than the player is dead AND connected.

It does,
PHP Code:

pPlayer->ingame && pPlayer->IsAlive() 

This would return true if player is connected and alive, then you would check
PHP Code:

if(!is_user_alive(id)) 


E1_531G 07-18-2018 10:12

Re: Optimize Plugin
 
edon1337, something wrong happens with you? Read again my first post:
Quote:

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.
Where are you seeing wrong info here? Where?

Ghosted 07-18-2018 10:25

Re: Optimize Plugin
 
Quote:

Originally Posted by E1_531G (Post 2604519)
Only if(!is_user_alive(id)) doesn't ensure than the player is dead AND connected.

Quote:

Originally Posted by edon1337 (Post 2604521)
It does


Edon you are wrong

Code:

pPlayer->ingame && pPlayer->IsAlive()
As code says if player is in-game and is alive it is returning true, otherwise always false
so you can not determine player is connected & dead or not connected & dead(huh?). :idea:

!ALIVE & !INGAME = FALSE
!ALIVE & INGAME = FALSE
ALIVE & !INGAME = FALSE
ALIVE & INGAME = TRUE


All times are GMT -4. The time now is 01:15.

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