Raised This Month: $ Target: $400
 0% 

Best player of the map?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Santaaa
BANNED
Join Date: May 2012
Old 07-12-2012 , 16:10   Best player of the map?
Reply With Quote #1

Hello there,

I've tryed to catch the best player of the map by using plugin_end, and another action by that. Ill show you guys what i've tried and what the problem is.

PHP Code:
public plugin_end()
{
    for (new 
i<get_maxplayers(); i++)
    {
        if (
Quest[i] == 10)
        {
            
Checktopplayer(i)
        }
    }
}

public 
Checktopplayer(id)
{
    new 
name[32]
    
get_user_name(idname31)
    
    for (new 
i<get_maxplayers(); i++)
    {
        if (
get_user_frags(id) > get_user_frags(i))
        {
            
client_cmd(0"spk %s"Sound)
            
            
Quest[id]++
            
ColorChat(0GREY"%s ^4%s^1 has ^4unlocked^1 a new quest! ^3(%i / 15)"PrefixnameQuest[id])
        }
    }

The problem is, it doesnt work. And it doesnt continue changing the map it just stays at Time left: 0:00
Santaaa is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-12-2012 , 16:23   Re: Best player of the map?
Reply With Quote #2

PHP Code:
for (new i<get_maxplayers(); i++) 
Stop doing that!

1. Cache get_maxplayers() in plugin init:
Code:
new g_iMaxPlayers; public plugin_init( ) {     g_iMaxPlayers = get_maxplayers( ); }

2. Players are 1 to maxplayers, not 0 to maxplayers - 1.
Code:
for( new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) {     // Player loop }

Also, your message won't be seen in plugin_end() since the map is changing and it is called right before clients are disconnected and reconnected to the changed map.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Santaaa
BANNED
Join Date: May 2012
Old 07-12-2012 , 16:28   Re: Best player of the map?
Reply With Quote #3

Hmm, then how would I check if its the end of the map ?:O

EDIT: So if my loop is wrong, why does it work on other actions?

Last edited by Santaaa; 07-12-2012 at 16:30.
Santaaa is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 07-12-2012 , 16:33   Re: Best player of the map?
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
PHP Code:
for (new i<get_maxplayers(); i++) 
Stop doing that!

1. Cache get_maxplayers() in plugin init:
Code:
new g_iMaxPlayers; public plugin_init( ) {     g_iMaxPlayers = get_maxplayers( ); }

2. Players are 1 to maxplayers, not 0 to maxplayers - 1.
Code:
for( new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) {     // Player loop }

Also, your message won't be seen in plugin_end() since the map is changing and it is called right before clients are disconnected and reconnected to the changed map.
Doesnt need to make a global g_iMaxPlayers for that

in the plugin

PHP Code:
new iMaxPlayers get_maxplayers()
for(new 
1<= iMaxPlayersi++)
{


Should be enough, because it only gets "called" once ?
__________________
Retired.

Last edited by Xalus; 07-12-2012 at 16:34.
Xalus is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-12-2012 , 16:34  
Reply With Quote #5

Quote:
Originally Posted by Santaaa View Post
Hmm, then how would I check if its the end of the map ?:O

EDIT: So if my loop is wrong, why does it work on other actions?
It works because you probably never tested with a full server.
Your incorrect loop only works on the first (maxplayers - 1) players (so 32 slot server only works on first 31 players).
Also, your incorrect loop starts at player id 0, which is no player so you should get a lot of runtime errors saying invalid player id if you are not checking if player exists (like your frag comparison loop).

EDIT:

Quote:
Originally Posted by Xalus View Post
Doesnt need to make a global g_iMaxPlayers for that

in the plugin

PHP Code:
new iMaxPlayers get_maxplayers()
for(new 
1<= iMaxPlayersi++)
{


Should be enough, because it only gets "called" once ?
Of course if it is only called once then it doesn't need to be global.
However, his code shows get_maxplayers() called from 2 separate places.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 07-12-2012 at 16:35.
Exolent[jNr] is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 07-12-2012 , 16:35   Re: Best player of the map?
Reply With Quote #6

Hm ye, my fault

Exolent[jNr] is right. (Like always)
__________________
Retired.

Last edited by Xalus; 07-12-2012 at 16:36.
Xalus is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 07-12-2012 , 16:36   Re: Best player of the map?
Reply With Quote #7

Quote:
Originally Posted by Santaaa View Post
Hmm, then how would I check if its the end of the map ?:O
You can try event "30" /intermission/ - it is called when the scoreboard is shown in the end of the map.
__________________
<VeCo> is offline
Santaaa
BANNED
Join Date: May 2012
Old 07-12-2012 , 16:36   Re: Best player of the map?
Reply With Quote #8

So this is a correct loop?

PHP Code:
for (new 1<=get_maxplayers(); i++) 
Santaaa is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 07-12-2012 , 16:37   Re: Best player of the map?
Reply With Quote #9

Quote:
Originally Posted by Santaaa View Post
So this is a correct loop?

PHP Code:
for (new 1<=get_maxplayers(); i++) 
Gosh....
Don't you read what Exolent says?


->

If you do like that, every time it needs to take the get_maxplayers() (every number from 1 to maxplayers)
__________________
Retired.

Last edited by Xalus; 07-12-2012 at 16:39.
Xalus is offline
Santaaa
BANNED
Join Date: May 2012
Old 07-12-2012 , 16:38   Re: Best player of the map?
Reply With Quote #10

Well just asking to be sure
Santaaa 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 15:08.


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