Raised This Month: $ Target: $400
 0% 

Better Way (Difference)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 04-16-2011 , 07:42   Better Way (Difference)
Reply With Quote #1

which way is better (less cpu, faster), and does anyone know even better way than this one

1.
PHP Code:
public radar_block(id
{
    new 
Players[32]
    new 
playerCountiplayer
    get_players
(PlayersplayerCount"c")
    for (
i=0i<playerCounti++)
    {
        
player Players[i
        if(
get_user_team(player) != get_user_team(id))
        {
            
emit_sound(playerCHAN_ITEM"counter_enemy.wav"1.0ATTN_NORM0PITCH_NORM);
            
cblocked[player] = true
            set_task
(15.0"remove_block"player)
        }
        else if(
get_user_team(player) == get_user_team(id))
        {
            
emit_sound(playerCHAN_ITEM"counter_friend.wav"1.0ATTN_NORM0PITCH_NORM);
        }
    }

2.
somewhere in plugin_init -> g_maxplayers = get_maxplayers();

PHP Code:
public radar_block(id
{
    for(new 
1<= g_maxplayersi++)
    {
        if(
get_user_team(i) != get_user_team(id))
        {
            
emit_sound(iCHAN_ITEM"counter_enemy.wav"1.0ATTN_NORM0PITCH_NORM);
            
cblocked[i] = true
            set_task
(15.0"remove_block"i)
        }
        else if(
get_user_team(i) == get_user_team(id))
        {
            
emit_sound(iCHAN_ITEM"counter_friend.wav"1.0ATTN_NORM0PITCH_NORM);
        }
    }


Last edited by OvidiuS; 04-16-2011 at 07:47.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
reinert
Veteran Member
Join Date: Feb 2007
Old 04-16-2011 , 08:19   Re: Better Way (Difference)
Reply With Quote #2

Well the 2nd method will give this public event to not connected or already disconnected players if the server is not full... you should use get_playersnum with second method and don't declare the playersnum in plugin_init, declare it everytime public event is hooked.
reinert is offline
Nyuszy
Senior Member
Join Date: Apr 2009
Old 04-16-2011 , 08:25   Re: Better Way (Difference)
Reply With Quote #3

you can't use playersnum, because playersnum returns the number of online players.
so for example: there are 20 players on the server. player 15 disconnects, and in the server remains 19 players. if your loop is for(new i = 1; i <= get_playersnum(); i++), it goes 1 to 19, and the 20. player won't be watched...
Nyuszy is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 04-16-2011 , 08:31   Re: Better Way (Difference)
Reply With Quote #4

PHP Code:
public radar_block(id
{
    new 
num get_playersnum()
    for(new 
1<= numi++)
    {
        if(
get_user_team(i) != get_user_team(id))
        {
            
emit_sound(iCHAN_ITEM"counter_enemy.wav"1.0ATTN_NORM0PITCH_NORM);
            
cblocked[i] = true
            set_task
(15.0"remove_block"i)
        }
        else if(
get_user_team(i) == get_user_team(id))
        {
            
emit_sound(iCHAN_ITEM"counter_friend.wav"1.0ATTN_NORM0PITCH_NORM);
        }
    }

hm you mean like this???
what's the actuall difference between new i = 1 and new i = 0?

edit: now i saw the post, so playersnum wont work
Quote:
Originally Posted by reinert View Post
Well the 2nd method will give this public event to not connected or already disconnected players if the server is not full... you should use get_playersnum with second method and don't declare the playersnum in plugin_init, declare it everytime public event is hooked.
what about this?

PHP Code:
public radar_block(id
{
   for(new 
1<= g_maxplayersi++)
   {
      if(
is_user_connected(i) && is_user_alive(i))
      {
            if(
get_user_team(i) != get_user_team(id))
            {
                
emit_sound(iCHAN_ITEM"counter_enemy.wav"1.0ATTN_NORM0PITCH_NORM);
                
cblocked[i] = true
                set_task
(15.0"remove_block"i)
            }
            else if(
get_user_team(i) == get_user_team(id))
            {
                
emit_sound(iCHAN_ITEM"counter_friend.wav"1.0ATTN_NORM0PITCH_NORM);
            }
        }
    }

don't know about disconnect

Last edited by OvidiuS; 04-16-2011 at 08:57.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
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 19:46.


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