AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Max player (https://forums.alliedmods.net/showthread.php?t=254514)

Process 01-03-2015 05:45

Max player
 
Hello,

today I found a code but I did not understand well a part of the script ,

Code:
/* Plugin generated by AMXX-Studio */ #include <  amxmodx  > #include <  hamsandwich  > #define PLUGIN "Modificare Damage" #define VERSION "0.1" #define AUTHOR "hadesownage" #define IsPlayer(%0)    ( 1 <= %0 <= g_iMaxPlayers ) new g_iMaxPlayers; public plugin_init ( ) {         register_plugin ( PLUGIN, VERSION, AUTHOR );         g_iMaxPlayers = get_maxplayers ( )     RegisterHam ( Ham_TakeDamage, "player", "Player_TakeDamage" ); } public Player_TakeDamage ( iVictim, iInflictor, iAttacker, Float:fDamage ) {         if ( iInflictor == iAttacker && IsPlayer ( iAttacker ) ) {             SetHamParamFloat ( 4, fDamage * 2.0 );         return HAM_HANDLED;             }         return HAM_IGNORED;     }

this is what i didn't understand

Code:
#define IsPlayer(%0)    ( 1 <= %0 <= g_iMaxPlayers )

why its %0 can i replace it with 1 and what is <= and get_maxplayers is it take the max player from server or what !



I'm still learning ...

Arkshine 01-03-2015 06:59

Re: Max player
 
What you see is called a macro. %0, %1, up to %9. are just arguments you pass.
A macro is replaced at compilation time.

For example, if you have IsPlayer(iAttacker) in your code, it will be replaced at compilation with 1 <= iAttacker <= g_iMaxPlayers
%0 is just a way to say that macro takes one argument.

Process 01-03-2015 07:09

Re: Max player
 
Yes i understand the replace of the 'Macro' , i've already read a 'tuto'

the actually define what is it , why we need a maxplayers in this define ! ?

Arkshine 01-03-2015 07:15

Re: Max player
 
To check whether index is actually a player. If index is between 1 and maxclients (maxclients being the current server max slots), then it's a player. If your server has 16 slots, a player's index can't be 17.

It's just a fast way to filter between players and others entities. You can take damage from something other than a player. The code will work only if attacker is a player.

Process 01-03-2015 07:25

Re: Max player
 
Really thanks dude ^^'

Freezo Begin 01-03-2015 07:31

Re: Max player
 
1 return if is a less than or equal a attacker and the attacker return if is a less than or equal a maxplayers

and

for an example :

switch (a)
{
case 0 .. 50:
{
//This code will run if 0 <= a <= 50
// which is From 0 to 49
}

so

('THIS IS WRONG ITS JUST A EXAMPLE')
switch (attacker){
case 1..maxplayers
//1 <= attacker <= maxplayers
// from 1 to maxplayers if maxplayers = 16 then from 1 to 15
}


maybe this is a easy way to unders...


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

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