Raised This Month: $51 Target: $400
 12% 

Some things I wonder about.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 08-21-2012 , 17:36   Some things I wonder about.
Reply With Quote #1

Hello there, I am in the intro tutorial but I didn't understand this

PHP Code:
public cmd_hp(idlevelcid)
{
     if (!
cmd_access(idlevelcid3))
        return 
PLUGIN_HANDLED
 
     
new Arg1[24]
     new 
Arg2[4]
 
     
//Get the command arguments from the console
     
read_argv(1Arg123)
     
read_argv(2Arg23)
 
     
//Convert the health from a string to a number
     
new Health str_to_num(Arg2)
 
     
//Is the first character the @ symbol?
     
if (Arg1[0] == '@')
     {
          new 
Team 0
          
if (equali(Arg1[1], "CT"))
          {
               
Team 2
          
} else if (equali(Arg1[1], "T")) {
               
Team 1
          
}
          new 
players[32], num
          get_players
(playersnum)
          new 
i
          
for (i=0i<numi++)
          {
               if (!
Team)
               {
                    
set_user_health(players[i], Health)
               } else {
                    if (
get_user_team(players[i]) == Team)
                    {
                         
set_user_health(players[i], Health)
                    }
               }
          }
     } else {
          new 
player cmd_target(idArg11)
          if (!
player)
          {
               
console_print(id"Sorry, player %s could not be found or targetted!"Arg1)
               return 
PLUGIN_HANDLED
          
} else {
               
set_user_health(playerHealth)
          }
     }
 
     return 
PLUGIN_HANDLED

First thing is
PHP Code:
return PLUGIN_HANDLED 
why did he used PLUGIN_HANDLED exactly. and what if I put it without return PLUGIN_HANDLED, or retrun PLUGIN_CONTINUE or even return % what will happen ?

2nd thing
PHP Code:
     read_argv(1Arg123)
     
read_argv(2Arg23
I realize the number 1,2 the arguments number but which I didn't understand is 23,3 I think they're the ID of the operation but how to get the id or it should be specific numbers depends on the operation ?

also this one
PHP Code:
          new players[32], num 
What is 32 ? I saw in many threads that It's player index id, but what is player index id ?

Last edited by Moody92; 08-21-2012 at 17:37.
Moody92 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-21-2012 , 18:34   Re: Some things I wonder about.
Reply With Quote #2

2nd thing: the 23 and 3 are charsmaxes from the arrays you've declared.
For example, you have
Arg1[24], Arg2[4]
read_argv(1, Arg1, charsmax(Arg1))
read_argv(2, Arg2, charsmax(Arg2))

This would just be the same

3rd thing,

It's very hard to explain, but how much players can there be max in a server? 32, how many characters can a STEAM ID have? This is still being complained about, but it's just the size of the array you want it to be.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 08-21-2012 , 18:38   Re: Some things I wonder about.
Reply With Quote #3

Quote:
Originally Posted by Moody92 View Post
Hello there, I am in the intro tutorial but I didn't understand this

First thing is
PHP Code:
return PLUGIN_HANDLED 
why did he used PLUGIN_HANDLED exactly. and what if I put it without return PLUGIN_HANDLED, or retrun PLUGIN_CONTINUE or even return % what will happen ?
Quote:
Originally Posted by wiki.alliedmods.net
PLUGIN_CONTINUE generally means "continue with normal operation", and PLUGIN_HANDLED means "block further operation". The differences are subtle but important. For example, when binding a command, you should never return PLUGIN_CONTINUE. But if you return PLUGIN_HANDLED while binding to the "say" command, it will block the player's text from ever appearing.
So clearly, he used return PLUGIN_HANDLED to block any further functions from working (Stop the command from working to make it simpler)

Quote:
Originally Posted by Moody92 View Post
2nd thing
PHP Code:
     read_argv(1Arg123)
     
read_argv(2Arg23
I realize the number 1,2 the arguments number but which I didn't understand is 23,3 I think they're the ID of the operation but how to get the id or it should be specific numbers depends on the operation ?
Actully, your wrong.
The last argument in the function(s) (23, 3) are the len.
Len is max characters that can be stored in Arg1, Arg2.
Just to make sure you understood,
PHP Code:
new szString1[35]     // Here, max characters that can be stored 34, but len can be 1,2,3,4,5,6,7.......34
// So,
charsmax(szString// == 34 
Quote:
Originally Posted by Moody92 View Post
also this one
PHP Code:
          new players[32], num 
What is 32 ? I saw in many threads that It's player index id, but what is player index id ?
Player index is the player's unique id, defined by amxx or half life engine (I don't really know).
Player index ranges from 1 to 32 (Thats why we created an array with 32 rows), but when you use this
PHP Code:
get_players(playersnum
All players indexes will be stored in players like this: (BTW, count is the number of the players)
PHP Code:
// You need to read arrays to understand this

// If count == 5  (Note that == is used for checking, = is used for assigning)
players[0] = 1
players
[1] = 2
players
[2] = 3
players
[3] = 4
players
[4] = 5

// If count == 10 (Players connected are 10)
players[0] = 1
players
[1] = 2
players
[2] = 3
players
[3] = 4
players
[4] = 5
players
[5] = 6
players
[6] = 7
players
[7] = 8
players
[8] = 9
players
[9] = 10
// Etc 
Also, as I know, ids (Players indexes) are assigned depending on who connects first, so if the server had 0 players, and you connected, players count will change to 1, also your index will be 1

Let's say that there were 3 players connected, and players[32] was like this
PHP Code:
players[0] = 1      // Player 1
players[1] = 2      // Player 2
players[2] = 3      // Player 3 
And then suddenly, player with index 2 has disconnected, so who will get index 2?
players are shifted automatically to fill the empty index
so players[32] will be like this:
PHP Code:
players[0] = 1      // Player 1
players[1] = 2      // Player 3 
That's all.

I too at the first didn't understand much about indexes, but then I started reading and testing till I understood it.
I think you should do that too.

Hopefully, you understood everything.
Regards.

EDIT: LOOOOL!
After I wrote all this post, I looked in the forum just to waste sometime, then I found this:
http://forums.alliedmods.net/showthread.php?t=181629
My idea about indexes was just a thought, I only understood it from get_players as I got confused in it, but it turned out that my thought is true! LOL!
PS: Only read the top of that post, you will get confused about other things.
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 08-21-2012 at 18:53.
pokemonmaster is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 08-22-2012 , 04:23   Re: Some things I wonder about.
Reply With Quote #4

I think I've understood about player indexes, so we need to put it [32] always to avoid mixing up with their numbers
Moody92 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-22-2012 , 04:34   Re: Some things I wonder about.
Reply With Quote #5

Each cell may store a value.

PHP Code:
new c] = { 'a''b''c' }; // three
new a] = { 'a''x' }; // two
new d] = { 123}; // four

/*
  So, d[ 0 ] = 1, d[ 1 ] = 2, d[ 2 ] = 3, d[ 3 ] = 4.

  c = "abc";
  c[ 0 ] = 'a', c[ 1 ] = 'b', c[ 2 ] = 'c';
*/ 
You have to define 32 cells for all players. From 0 to 31 inclusive.
If you want to use the cells from 1 to 32 inclusive, you have to define 33 cells.

Last edited by claudiuhks; 08-22-2012 at 04:34.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 08-22-2012 , 05:05   Re: Some things I wonder about.
Reply With Quote #6

Quote:
Originally Posted by Moody92 View Post
I think I've understood about player indexes, so we need to put it [32] always to avoid mixing up with their numbers
PHP Code:
// As I said before, player indexes ranges from 1 two 32
// Lets say you made a new array with 32 rows
new iArray[32]
// and id = 32
// Now if you did this it will give you an error (Index out of bounds)
iArray[id] = 5
server_print
("%d"iArray[id])// And this function won't work
// What happened here that it gave an error because there is no such a row with the number 32 in Array
// Arrays ranges from 0 to (Whatever you assign the array with) - 1


// So to make it correct, you must declare the array with 33 rows (last row is 32)
new iArray[33]
iArray[id] = 5
server_print
("%d"iArray[id])    // This would print in server console 5 
You just declare the array (that you are going to use with get_players) with 32 rows, because that's how the function works
PHP Code:
new players[32], count
get_players
(playerscount)

/* 
if count == 5
Then players will look like this
players[0] = 1
players[1] = 2
players[2] = 3
players[3] = 4
players[4] = 5
*/ 
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 08-22-2012 at 05:11.
pokemonmaster is offline
dark_style
Senior Member
Join Date: Jul 2009
Location: Bulgaria
Old 08-22-2012 , 05:20   Re: Some things I wonder about.
Reply With Quote #7

Note that if he uses get_maxplayers(), he should use it like that:

PHP Code:
new i_MaxPlayers get_maxplayers();
for( new 
id 1id <= i_MaxPlayersid++ ) 

Last edited by dark_style; 08-22-2012 at 05:42.
dark_style is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 08-23-2012 , 16:09   Re: Some things I wonder about.
Reply With Quote #8

Quote:
Originally Posted by pokemonmaster View Post
PHP Code:
new iArray[32]
// and id = 32
iArray[id] = 5
server_print
("%d"iArray[id])// And this function won't work
// WRONG ^^

// THE RIGHT ONE
new iArray[33]
iArray[id] = 5
server_print
("%d"iArray[id]) 
PHP Code:
new players[32], count
get_players
(playerscount)

/* 
if count == 5
Then players will look like this
players[0] = 1
players[1] = 2
players[2] = 3
players[3] = 4
players[4] = 5
*/ 
I got it now so to make it simple we just need to declare the array to 33 but the server will consider it as 32, and if we make it less than 33 there will be an issue.

HTML Code:
(Index out of bounds)
Correct me if I am wrong.


Last edited by Moody92; 08-23-2012 at 16:12.
Moody92 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-23-2012 , 16:13   Re: Some things I wonder about.
Reply With Quote #9

Quote:
Originally Posted by dark_style View Post
Note that if he uses get_maxplayers(), he should use it like that:

PHP Code:
new i_MaxPlayers get_maxplayers();
for( new 
id 1id <= i_MaxPlayersid++ ) 
This is a bad way, get_players should always be used, so you directly get a list (filled in players[32] array) of connected players.
With the other method, on each iteration you need to check if the player is connected, which is bad for performances.
Also get_players lets you add the "a" flag to retrieve only alive player that improve performances in the same way that having to put is_user_alive on each iteration.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
dark_style
Senior Member
Join Date: Jul 2009
Location: Bulgaria
Old 08-24-2012 , 01:28   Re: Some things I wonder about.
Reply With Quote #10

Connor what I have meant was if he wants to use get_maxplayers, he should put 1 for starting value, I didn't mean he should use get_maxplayers.
dark_style 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 17:22.


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