AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Best player of the map? (https://forums.alliedmods.net/showthread.php?t=189931)

Santaaa 07-12-2012 16:10

Best player of the map?
 
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

Exolent[jNr] 07-12-2012 16:23

Re: Best player of the map?
 
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.

Santaaa 07-12-2012 16:28

Re: Best player of the map?
 
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?

Xalus 07-12-2012 16:33

Re: Best player of the map?
 
Quote:

Originally Posted by Exolent[jNr] (Post 1748955)
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 ?

Exolent[jNr] 07-12-2012 16:34

Quote:

Originally Posted by Santaaa (Post 1748956)
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 (Post 1748960)
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.

Xalus 07-12-2012 16:35

Re: Best player of the map?
 
Hm ye, my fault

Exolent[jNr] is right. (Like always)

<VeCo> 07-12-2012 16:36

Re: Best player of the map?
 
Quote:

Originally Posted by Santaaa (Post 1748956)
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.

Santaaa 07-12-2012 16:36

Re: Best player of the map?
 
So this is a correct loop?

PHP Code:

for (new 1<=get_maxplayers(); i++) 


Xalus 07-12-2012 16:37

Re: Best player of the map?
 
Quote:

Originally Posted by Santaaa (Post 1748967)
So this is a correct loop?

PHP Code:

for (new 1<=get_maxplayers(); i++) 


Gosh....
Don't you read what Exolent says? :down:


->

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

Santaaa 07-12-2012 16:38

Re: Best player of the map?
 
Well just asking to be sure :D


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

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