AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Master Reset (https://forums.alliedmods.net/showthread.php?t=188050)

Waleed 06-21-2012 14:37

Master Reset
 
Hey there,
I added a small "reset" and "master reset" function in my plugin that resets user deaths and frags,
Reset system is working,Changing the deaths and frags to zero;

PHP Code:

public cmd_reset(id)
{
    
cs_set_user_deaths(id0)
    
set_user_frags(id0)



But,"Master Reset" is not working;

PHP Code:

public cmd_mreset(id)
{
    
cs_set_user_deaths(00
    
set_user_frags(00)



I thought that changing the index to zero means every player :) but its not working and giving console errors

  • L 06/21/2012 - 23:15:38: [CSTRIKE] Player out of range (0)
  • L 06/21/2012 - 23:15:38: [AMXX] Run time error 10: native error (native "cs_set_user_deaths")

I know these errors are because of that O zero index,But I don't know how to do trigger it for all players.
Note: Master Reset will be used by admins,I will add admins checks later on.

ConnorMcLeod 06-21-2012 14:38

Re: Master Reset
 
Use get_players with flag "h" and loop though the list.

Liverwiz 06-21-2012 14:40

Re: Master Reset
 
loop through the players. not using id as 0.

Because you're learning...i throw you a bone. get_players(players, num, "h")

Waleed 06-21-2012 14:49

Re: Master Reset
 
I searched wiki about get_players,
Tell me why to use num?
and "h" will skip HLTV,What is HLTV why to skip it?

By the way,I haven't done looping yet since beginning(by myself),Can you explain me?
I have read tutorials about it,But need little more about looping.
I know,I am asking allot about these,I am sure you will help,Thanks!

Liverwiz 06-21-2012 15:10

Re: Master Reset
 
Haven't we already told you to read the documentation?

http://www.amxmodx.org/doc/index.htm...g%2Fprimer.htm
Learn before you ask again. We get grouchy when you ask stupid, remedial, basic questions.

pokemonmaster 06-21-2012 15:31

Re: Master Reset
 
Here is an example of looping (from my experience xD):
PHP Code:

public cmd_mreset(id)
{
    new 
players[32], count
    get_players
(playerscounth)

    for(new 
ii<counti++)
    {
        
cs_set_user_deaths(i0)  
        
set_user_frags(i0)          // This as I know needs the fun include
    
}



Liverwiz 06-21-2012 15:35

Re: Master Reset
 
Quote:

Originally Posted by pokemonmaster (Post 1733382)
Here is an example of looping (from my experience xD):
PHP Code:

public cmd_mreset(id) {

          new 
players[32], count
          get_players
(playerscounth)

          for(new 
ii<counti++) {
                     
cs_set_user_deaths(i0)  
                     
set_user_frags(i0)          // This as I know needs the fun include
                     
}



two things wrong.
1. h needs to be in quotes. its passed as a string
2. i is an index of the players array (you're iterating through it), not playerID. players is an array of valid playerIDs.

EDIT: did you guys read the wiki at all!? It tells you THIS EXACT CODE on the page. GO!

pokemonmaster 06-21-2012 15:54

Re: Master Reset
 
Quote:

Originally Posted by Liverwiz
two things wrong.
1. h needs to be in quotes. its passed as a string

So that's why it was giving me errors. LOL

Quote:

Originally Posted by Liverwiz
2. i is an index of the players array (you're iterating through it), not playerID. players is an array of valid playerIDs.

So the correct one will be this?
PHP Code:

public cmd_mreset(id)
{
    new 
players[32], count
    get_players
(playerscount"h")

    for(new 
ii<counti++)
    {
        
cs_set_user_deaths(players[i], 0)  
        
set_user_frags(players[i], 0)
    }



Liverwiz 06-21-2012 16:00

Re: Master Reset
 
Quote:

Originally Posted by pokemonmaster (Post 1733393)
So the correct one will be this?
PHP Code:

public cmd_mreset(id)
{
    new 
players[32], count
    get_players
(playerscount"h")

    for(new 
ii<counti++)
    {
        
cs_set_user_deaths(players[i], 0)  
        
set_user_frags(players[i], 0)
    }



yes.
and to make it even faster....
Code:

new player = players[i]
and use player instead of players[i]

Exolent[jNr] 06-21-2012 16:01

Re: Master Reset
 
Quote:

Originally Posted by Liverwiz (Post 1733397)
yes.
and to make it even faster....
Code:

new player = players[i]
and use player instead of players[i]

Be sure the variable is created outside the loop and assigned to the player id inside the loop.


All times are GMT -4. The time now is 06:14.

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