AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011 (https://forums.alliedmods.net/showthread.php?t=148387)

zeroibis 02-11-2011 15:53

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
1 Attachment(s)
Was wondering if your php script at: http://www.sourcemodplugins.org/smlibfunctions.php

Could be used to make it easier to read other include files like the one attached?

berni 02-11-2011 16:03

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
This was just a quick & dirty thing.
I have written a much more powerful Pawn Parser that I maybe will release together with the dynamic API documention, don't know yet :3

zeroibis 02-11-2011 19:33

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Ah, cool. Yea I have been trying to find a better way to see the list of natives and descriptions for that mod so that I and others can have an easier time writing programs for it.

bl4nk 02-25-2011 00:08

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Handles to convars don't need to be closed, as you're not making a new one when you find a convar.

berni 02-25-2011 07:22

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by bl4nk (Post 1423303)
Handles to convars don't need to be closed, as you're not making a new one when you find a convar.

? doesn't Sourcemod create a new Handle for each call to FindConVar ?

psychonic 02-25-2011 08:17

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by berni (Post 1423445)
? doesn't Sourcemod create a new Handle for each call to FindConVar ?

noOnly if SM did not already have a handle for that convar, but there will still only be one handle at most per convar.

Citation: http://hg.alliedmods.net/sourcemod-c...nager.cpp#l451

berni 02-25-2011 08:21

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by psychonic (Post 1423460)
noOnly if SM did not already have a handle for that convar, but there will still only be one handle at most per convar.

ok thx then, I will also cache the handle, since calls to FindConVar are very expensive, I have also added caching to the team edict functions already.

If I get everything done I have in my head, I will make a bigger release today, including extensive chat color support.

bl4nk 02-25-2011 16:33

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by berni (Post 1423463)
ok thx then, I will also cache the handle, since calls to FindConVar are very expensive, I have also added caching to the team edict functions already.

SM already does this (see the link psychonic posted), so there's no reason for you to do it in Pawn, which is slower than C++.

berni 02-25-2011 16:39

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by bl4nk (Post 1423620)
SM already does this (see the link psychonic posted), so there's no reason for you to do it in Pawn, which is slower than C++.

In my tests this was not the case, I called FindConVar on a srcds convar 100.000 times and the profiling time was significantly higher than when it was cached.

psychonic 02-25-2011 17:35

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by bl4nk (Post 1423620)
SM already does this (see the link psychonic posted), so there's no reason for you to do it in Pawn, which is slower than C++.

Quote:

Originally Posted by berni (Post 1423625)
In my tests this was not the case, I called FindConVar on a srcds convar 100.000 times and the profiling time was significantly higher than when it was cached.

Creating the handle to the convar isn't the slow part; finding the var is.

SM calls FindVar to first make sure the convar exists before looking to see if it already has a handle to it. FindVar iterates through all cvars and commands, doing string compares.

This is why it is slow even if SM already has a handle to it, and thus, why you should still cache the handle.

KyleS 02-26-2011 04:27

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by psychonic (Post 1423665)
Creating the handle to the convar isn't the slow part; finding the var is.

SM calls FindVar to first make sure the convar exists before looking to see if it already has a handle to it. FindVar iterates through all cvars and commands, doing string compares.

This is why it is slow even if SM already has a handle to it, and thus, why you should still cache the handle.

Do we need to FindConVar every map change? or will once suffice (storing it for the plugins lifetime)?

berni 02-26-2011 04:44

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by Kyle12 (Post 1423895)
Do we need to FindConVar every map change? or will once suffice (storing it for the plugins lifetime)?

one time is enough, it's not something that changes on mapchange.

berni 02-26-2011 11:13

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
New smlib update available: smlib 0.10.0 beta
Compatibility breaks: yes

This is a very big release with a powerful chat color parser, allows you to
print colored text message to the chat, it basically works like exvel
' colors.inc, but it is more flexible, faster and supports more colors.
Those are the color tags you can use in eg. Client_PrintToChat() (see colors.inc in the meanwhile):


{N}, {O}, {R}, {RB}, {B}, {BR}, {T}, {L}, {GRA}, {G}, {OG}, {BLA}


More Info on Colors:
Click Me!

Changes:

Quote:

  • Renamed Function Client_SetMaxSpeed() to Entity_SetMaxSpeed()
  • Added Function Client_SetMaxSpeed()
  • Changed Client_GetActiveWeaponName() returns now the weapons entity index.
  • Fixed Weapon_SetPrimaryAmmoCount() setting the wrong property.
  • Fixed Weapon_GetPrimaryAmmoCount() getting the wrong property.
  • Added Function Convar_IsValidName(), suggested by FaTony
  • Added File colors.inc
  • Added Function Color_ChatSetSubject()
  • Added Function Color_ChatClearSubject()
  • Added Function Color_ParseChatText()
  • Added Function Color_TagToCode()
  • Added Function Color_GetChatColorInfo()
  • Added Function Color_StripFromChatText()
  • Added Function Client_PrintToChatRaw()
  • Added Function Client_PrintToChat()
  • Added Function Client_PrintToChatAll()
  • Added Function Client_HasAdminFlags()
  • Added Function Math_UnitsToMeters()
  • Added Function Math_UnitsToFeet()
  • Added Function Team_GetAnyClient()
  • Removed Function String_StripChatColors()
  • Enhanced function Team_GetEdict() (added caching)
  • Added wildcard extension suppport to File_AddToDownloadsTable()
  • Fixed some comments
  • Added check to Convar_IsValidName() if name is empty (suggested by FaTony)
  • Added File crypt.inc
  • Added Function Crypt_Base64Encode()
  • Added Function Crypt_Base64Decode()
  • Added Function Crypt_Base64MimeToUrl()
  • Added Function Crypt_Base64UrlToMime()
  • Added Function Crypt_MD5()
  • Added Function Crypt_RC4Encode()
  • Added Function Crypt_RC4EncodeBinary()
  • Added missing Comments to some functions.
  • Added ConVar Handle Caching to all functions (FindConVar is freaking expensive).
  • Updated smlib_test.sp
  • Added Function LongToIP()
  • Added Function IPToLong()
  • Added Function IsIPLocal()
  • math.inc: Fixed Functions Math_UnitsToMeters() and Math_UnitsToMeters()
  • Renamed Function Server_GetIP() to Server_GetIPString()
  • Added Function Server_GetIP (greatly enhanced the IP getting, added parameter public=true, uses the Steamtools function Steam_GetPublicIP() if available)
  • Added MAX_TEAM_NAME_LENGTH in teams.inc

Download here.

Leonardo 02-26-2011 11:25

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
Quote:

Added Function Crypt_MD5()
hurray!

also
Quote:

Renamed Function Server_GetIP() to Server_GetIP()
I don't get it o.o

bl4nk 02-26-2011 17:35

Re: SMLIB 0.9.7 BETA (295 Function Stocks) | updated 08.02.2011
 
Quote:

Originally Posted by psychonic (Post 1423665)
SM calls FindVar to first make sure the convar exists before looking to see if it already has a handle to it.

You're right. I only quickly looked over it before and thought that I saw the cache lookup before the FindVar call. My memory isn't what it use to be. :(

Chanz 02-27-2011 06:08

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
Full >90% credit goes to Berni I had have nothing little to do with it. Good job man!

berni 02-27-2011 12:18

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
Quote:

Originally Posted by Chanz (Post 1424650)
Corrected:


Also full credit goes to Berni I had have nothing to do with it. Good job man!

You actually did 4 things of the change list :wink:

and yeh, I was in a hurry yesterday, change list should be fine now 8)

FaTony 02-28-2011 14:28

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
3 more stocks:
PHP Code:

/**
 * Checks if a ConCommand has one or more flags set.
 *
 * @param    command        ConCommand name.
 * @param    flags        Flags to check.
 * @return                True if flags are set, false otherwise.
 */
stock bool:ConCommand_HasFlags(const String:command[], const flags)
{
    return 
bool:(GetCommandFlags(command) & flags);
}

/**
 * Adds one or more flags to a ConCommand.
 *
 * @param    command        ConCommand name.
 * @param    flags        Flags to add.
 * @noreturn
 */
stock ConCommand_AddFlags(const String:command[], const flags)
{
    new 
newFlags GetarFlags(command);
    
newFlags |= flags;
    
SetCommandFlags(commandnewFlags);
}

/**
 * Removes one ore more flags from a ConCommand.
 *
 * @param    command        ConCommand name.
 * @param    flags        Flags to remove
 * @noreturn
 */
stock ConCommand_RemoveFlags(const String:command[], const flags)
{
    new 
newFlags GetCommandFlags(command);
    
newFlags &= ~flags;
    
SetCommandFlags(commandnewFlags);



KawMAN 03-03-2011 05:28

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
Hi,

Please add something like Team_FindByName that return team index of team with specific name or -1 when can't find.

Also in teams.inc function Team_GetEdict(index)
PHP Code:

        if (!Entity_ClassNameMatches(entity"team_manager"true)) {
            return -
1;
        } 

instead "return -1;" should't be "continue;" ?

asherkin 03-03-2011 08:59

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
Quote:

Originally Posted by KawMAN (Post 1427000)
Please add something like Team_FindByName that return team index of team with specific name or -1 when can't find.

LOL, at least try searching.

http://docs.sourcemod.net/api/index....d=show&id=501&

berni 03-03-2011 09:24

Re: SMLIB 0.10.0 BETA (over 300 Function Stocks) | updated 26.02.2011
 
Quote:

Originally Posted by KawMAN (Post 1427000)
Hi,

Please add something like Team_FindByName that return team index of team with specific name or -1 when can't find.

Also in teams.inc function Team_GetEdict(index)
PHP Code:

        if (!Entity_ClassNameMatches(entity"team_manager"true)) {
            return -
1;
        } 

instead "return -1;" should't be "continue;" ?

It's not meant to iterate over all entities, the team entities are all sitting after MaxClients+1.

I can add Team_FindByName() for completion, but you can use FindTeamByName like asherkin said.

berni 03-06-2011 18:20

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
New smlib update available: smlib 0.10.1 beta
Compatibility breaks: yes

I added a useful documentation on how to use smlib's color API: Click Me!

Changes:

Quote:

  • Added file concommands.inc
  • Added ConCommand Functions ConCommand_HasFlags(), ConCommand_AddFlags(),
    ConCommand_RemoveFlags() (Thanks to Fatony)
  • Added support for DoD:S nickname coloring to Client_PrintToChatRaw()
  • Added Parameter isChat to all Client_PrintToChat() functions
  • Fixed a bug in color parsing code
  • Enhanced color code and gamedata support
  • Added gamedata/smlib_colors.games.txt (color overriding)

Download here.

berni 03-06-2011 19:56

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
New smlib update available: smlib 0.10.2 beta
Compatibility breaks: no

Changes:
Quote:

  • Fixed L4D2/TF2 color settings (reported in IRC)


Download here.

GoD-Tony 03-08-2011 03:54

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
I would like to see this stock in SMLIB. It's from the Zombie:Reloaded plugin (all credit to them), and I use it regularly to check if a player is in a particular group.

PHP Code:

/**
 * Returns whether a player is in a spesific group or not.
 *
 * @param client        The client index.
 * @param groupName     SourceMod group name to check.
 * @return              True if in the group, false otherwise.
 */
stock bool:Client_IsInGroup(client, const String:groupName[])
{
    new 
AdminId:id GetUserAdmin(client);
    
    
// Validate id.
    
if (id == INVALID_ADMIN_ID)
    {
        return 
false;
    }
    
    
// Get number of groups.
    
new groupnum GetAdminGroupCount(id);
    
decl String:groupname[64];
    
    
// Validate number of groups.
    
if (groupnum 0)
    {
        
// Loop through each group.
        
for (new group 0group groupnumgroup++)
        {
            
// Get group name.
            
GetAdminGroup(idgroupgroupnamesizeof(groupname));
            
            
// Compare names.
            
if (StrEqual(groupNamegroupnamefalse))
            {
                return 
true;
            }
        }
    }
    
    
// No groups or no match.
    
return false;



berni 03-08-2011 04:30

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Sure, I'm gonna add this one :)

Steell 03-09-2011 12:35

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
For some reason this code won't compile, even on your online compiler: http://p.hlxce.com/291

It keeps saying it can't find Client_HasWeapon, even though it is listed in smlib/clients.inc.

EDIT: Also, Client_HasWeapon should return a bool (you forgot the tag).

GoD-Tony 03-09-2011 14:33

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Quote:

Originally Posted by Steell (Post 1430366)
For some reason this code won't compile, even on your online compiler: http://p.hlxce.com/291

Compiles fine for me (smlib 0.10.1). Make sure your include file is in scripting/include/smlib/clients.inc.

Steell 03-09-2011 14:46

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Yep the include files are in the correct place. The weird thing is that it's also not compiling on the "web IDE" that berni posted in the OP.

Chanz 03-09-2011 15:19

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Seems like anywhere is a { or } missing/double.
Sorry can't locate it atm, but it seems its in the clients.inc since #include <smlib/clients> brings up the same error.

berni 03-09-2011 17:17

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Quote:

Originally Posted by Steell (Post 1430366)
For some reason this code won't compile, even on your online compiler: http://p.hlxce.com/291

It keeps saying it can't find Client_HasWeapon, even though it is listed in smlib/clients.inc.

EDIT: Also, Client_HasWeapon should return a bool (you forgot the tag).

That's pretty weird, it seems to work fine in th windows compiler, but on linux it just fails and I can't figure out why. Are you using the linux compiler ?

Edit: I don't know why, but somehow the linux compiler doesn't seem to like include directorys, it includes the sm clients.inc, instead of the smlib one.

Edit2: Changing <smlib/clients> to <smlib/clients.inc> seems to help, I'm gonna change all includes in the next smlib release.

gCode 03-11-2011 07:04

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Please add getting count of all players, and GetRandomPlayer(Count, team), if team 3, then script will choose player from all teams without spectators.

Chanz 03-11-2011 08:29

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
GetRandomPlayer(count, team) what does count mean?
And instead of a team index I suggest to handle it as an bitflag var and use an enum to specify the teams etc.

Team_Unassigned = 0,
Team_Spectator = 1,
Team_One = 2,
Team_Two = 4,
...
Team_Dead,
Team_Alive,
Team_All,

gCode 03-11-2011 13:28

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Count of getting players...
Nice idea. Team_All, super.
Please, add this function.

And if you can... Function of brightness map. (light controller) SetMapBrightness(Count of brigntness);
Also force round end. ForceRoundEnd(Float: Delay);

gCode 03-15-2011 13:36

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
03/15/2011 - 20:33:19: [SM] Native "GetEntPropEnt" reported: Property "m_hActiveWeapon" not found (entity 111/entityflame)
03/15/2011 - 20:33:19: [SM] Displaying call stack trace for plugin "zinfection.smx":
03/15/2011 - 20:33:19: [SM][0] Line 929, E:\scripting\include\smlib/clients.inc::Client_GetActiveWeapon()
03/15/2011 - 20:33:19: [SM][1] Line 948, E:\scripting\include\smlib/clients.inc::Client_GetActiveWeaponName()

if (IsValidEntity(attacker) && attacker > MaxClients)
{
Client_GetActiveWeaponName(attacker, ActivePlayerWeapon, 64);

wtf?!

Chanz 03-15-2011 14:00

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
attacker > MaxClients wtf!?

Please check if you really want the weapon of a non player entity...
Probably attacker is your client entity index so Client_IsValid(attacker) would be better.

berni 03-15-2011 17:21

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
it should probably be attacker <= MaxClients

Master53 03-20-2011 10:16

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
Quote:

Originally Posted by berni (Post 1398702)

is this suggesting that you can use lightgreen in hl2mp because if it did that would be awsome.

asherkin 03-20-2011 12:07

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
Quote:

Originally Posted by berni (Post 1398702)
Valid colors are:
...
"black"

D:

Quote:

Originally Posted by asherkin (Post 1369990)
\x06 is just the 'custom' colour in the OBV engine, it's specified at runtime in the client code by CBaseHudChat::SetCustomColor(const char *).
For example TF2 uses it for the item found messages, where it sets it to the colour representing the quality of the found item.
It's black before it is set in code.
Maybe it could be added with a {custom} name, just please not {black}.


Leonardo 03-20-2011 12:12

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
is there any chance to set "black"/custom color?

psychonic 03-20-2011 13:15

Re: SMLIB 0.10.1 BETA (over 300 Function Stocks) | updated 07.03.2011
 
Quote:

Originally Posted by Leonardo (Post 1436501)
is there any chance to set "black"/custom color?

Nope. It's been requested of Valve, but there is currently no way for the server to manually set a color for it.


All times are GMT -4. The time now is 21:59.

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