Raised This Month: $ Target: $400
 0% 

some scripting questions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-15-2013 , 11:42   some scripting questions
Reply With Quote #1

Hi all!

I am new in amxmodx scripting and I don't know a lot about it.So, I have some question about some the scripting?

  1. What is "enum"?What is it for?What does it do?What does it include
  2. What does <<= 1 means?
  3. What is "lvl,cid" parameters?What are they for?What do they do?
  4. Is there any post about amxmodx complete functions and their parameter's define?
  5. Why we add i or sz to begining of some variables, arrays and strings?
  6. What is "%d" and "%s"?How can I make them work correctly in functions?
  7. What are function' flags?What they do?What type they have?
  8. What is PLMENU_OBEY_IMMUNITY, PLMENU_ALLOW_SELF,PLMENU_ONLY_ALIVE and PLMENU_NOBOTS?What are they for?Where we use them?
  9. What is Authid?
Please, answer to my questions and help me!
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-15-2013 , 12:26   Re: some scripting questions
Reply With Quote #2

1. http://forums.alliedmods.net/showthread.php?t=140103


2. http://forums.alliedmods.net/showthread.php?t=90507


3. lvl and cid are parameters that contain information from the function registering.
They should be used in combination with cmd_acess() found in amxmisc.inc.

level is used to determine if you have access to the command. A better way than just using "flags & ADMIN_FLAG".

cid stands for command id, it's used in various functions that are rarely used. In cmd_acess it's used to retreive the fourth parameter used when registering the command. If the number of arguments fewer than defined in cmd_access() it will display this string as a guide on how the command should be used.


4. Check out the .inc-files included in the default AMXX package. They supply a lot of information. There was an online function but it's broken as it doesn't show all functions.


5. Personal preference. sz basically stands for "string zero" which could be translated into "string of characters terminated by null(zero)". This is how strings in pawn works. Functions loop strings until it hits 0(null). It doesn't mean you have to use sz as a prefix.

In pawn there are only 3 types of variables. Integer, float and boolean.
Integers hold one integer value (I don't know the range of it).
Float holds a decimal number.
Boolean holds only true or false.
An array is basically just a row of any of the 3 above.
Strings are integer arrays with the exception of leaving the last cell unused for the null-termination.

In other programming languages there are a lot more variable types to keep track of. Using these prefixes will make it easier to look into larger functions without going back and forth to check what the variable was initialized as.


6. These are placeholders to be replaced with a number/string or float.

%d or %i is used to display an integer.
%f is used to display a float.
%s is used to display a string.
%c is used to display a character.

They are used like this:
Code:
server_print("Random number: %d". random_num(1, 9))
This will replace %d with whatever is returned by the function random_num().

When printing floats you will get 6 decimals. You can limit this using %.2f for example. This will only print 2 decimals. You can limit strings in the same way.


7. I'm not following. What do you mean by function flags?


8. They look like flags used to filter a player menu. I can't find them in my includes, might be specific to a certain plugin.


9. SteamID.

There is better information to be found on most subjects here. Search and you will find.
__________________

Last edited by Black Rose; 09-15-2013 at 12:45.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-15-2013 , 13:48   Re: some scripting questions
Reply With Quote #3

Quote:
Originally Posted by Dark_Siders View Post
Why we add i or sz to begining of some variables, arrays and strings?
Hungarian notation.
__________________
fysiks is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-16-2013 , 02:19   Re: some scripting questions
Reply With Quote #4

Quote:
Originally Posted by Black Rose View Post
7. I'm not following. What do you mean by function flags?
I mean that we use some flags like "k" in function's parameters.For example:
Code:
if ( ( iPlayer = find_player("k", str_to_num( szUserId) )
What are they?

And 2 new question:
  1. szFlags[++iNum] = 'a'.What is this for? what is 'a' in this code?
  2. How does this looping works?
Code:
for ( --iNum; iNum >= 0; iNum--)
{
      iPlayer = iPlayers[iNum]
}
Quote:
Originally Posted by fysiks View Post
Hungarian notation.
What do you mean by this?
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********

Last edited by Dark_Siders; 09-16-2013 at 02:25.
Dark_Siders is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 09-16-2013 , 11:54   Re: some scripting questions
Reply With Quote #5

1. In this case it finds a player by his/her #userid
PHP Code:
/* Find player.
* Flags:
* "a" - with given name.
* "b" - with given part of name.
* "c" - with given authid.
* "d" - with given ip.
* "e" - with given team name.
* "f" - don't look in dead players.
* "g" - don't look in alive players.
* "h" - skip bots.
* "i" - skip real players.
* "j" - return index of last found player. 
* "k" - with given userid.
* "l" - ignore case sensitivity. */
native find_player(const flags[], ... ); 
They are different for every native. Check their library (in this case amxmodx.inc), there is always some explanation.

2. 'a' is used as a character. Strings are composed from characters too, but here it is only one, so it isn't needed to make a whole array.

3. That's a loop using the get_players native for finding players and executing something on them.

iNum is the number of total players.
In this loop, it starts as iNum-1 and continues to decrease till it reaches zero (If the players are 6, it will start from 5 and go down to 0).
Then the corresponding player index from the iPlayers array is saved in iPlayer variable for more convinient work.

It's also common to see this loop using another variable, like this):
PHP Code:
for( new num i++ )
{
iPlayer iPlayers[i]

(starting from 0 and increasing till it reaches the max number of players)
..But the code you showed is more efficient (better to use), because it uses directly the iNum variable, instead of making a new one.


4. Hungarian notation is something that some scripters use to make their code look more readable for them and other people. You can find more info about it here: http://forums.alliedmods.net/showthread.php?t=85274 (section "Global Variables and Type Prefixing")
__________________

Last edited by <VeCo>; 09-16-2013 at 12:00.
<VeCo> is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-16-2013 , 13:05   Re: some scripting questions
Reply With Quote #6

Thank you!

what editor do you use?
, how do you put colored codes in the posts?
And what does this error means when compiling:"loosed indentation"?
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********

Last edited by Dark_Siders; 09-16-2013 at 13:08.
Dark_Siders is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 09-16-2013 , 13:39   Re: some scripting questions
Reply With Quote #7

1. AMXX Studio, doesn't really matter actually
2. [PHP][ /PHP] bb code
3. It means that the code isn't properly indented. On some line you have more/less spaces in front of it, differently to the previous one. It's not something serious.
__________________
<VeCo> is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-16-2013 , 13:59   Re: some scripting questions
Reply With Quote #8

thanks!

I write a code in AMXX Studio and copy it and paste it in forum.But it looses it's properties.So, what can I do?
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
dark_style
Senior Member
Join Date: Jul 2009
Location: Bulgaria
Old 09-16-2013 , 14:10   Re: some scripting questions
Reply With Quote #9

Quote:
Originally Posted by Dark_Siders View Post
thanks!

I write a code in AMXX Studio and copy it and paste it in forum.But it looses it's properties.So, what can I do?
Explain what do you mean by this.
__________________



dark_style is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-16-2013 , 14:22   Re: some scripting questions
Reply With Quote #10

Quote:
Originally Posted by dark_style View Post
Explain what do you mean by this.
for example I write this code in amxx studio and copy it and pastes it in the editor of forum.But, it loses it properties like color.What can I do to keep this properties in the code when I am putting it in the post?

Example:
PHP Code:
public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Add your code here...

__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders 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 19:13.


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