Raised This Month: $22 Target: $400
 5% 

SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-24-2011 , 19:56   SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #1



SMLIB (Function Stock Library for Sourcemod) by sourcemodplugins.org



We use Github - Code contributions are welcome! - Read more here

About SMLIB

SMLib is a collection of over 300 function stocks for sourcemod written by the basic principle that every line of code should only exist one time.
In the past I've catched myself reinventing the wheel again and again and again in every plugin I wrote. That's why I started - together with Chanz - writing on a set of stock include files, with the aim to write reusable code I can call everywhere. The code of our plugins should be as easily readable as a book.
After many months of writing dozen of sourcemod plugins and hundred of functions this is what came out.

Note: some functions have been written but not tested yet, so please report any bugs & errors here.
Protobuf support was added to the master branch on GIT (Sourcemod 1.5). If you want to support older sourcemod versions you have to put this into your plugin, or ask the people to update their Sourcemod to 1.5.

Feel free to add or suggest new functions for smlib in this thread.
I'll try to add it to smlib then.

Authors: Berni, Chanz and other Github contributors

Download:
SMLIB 0.11 BETA

License: GNU General Public License 3.0

Installation
:

Simply extract the contents of this zip file into your sourcemod folder.
Then add #include <smlib> at the top of your sm plugin file and you are done.
Documentation of the Functions can be found below or inside the .inc files, but we will also put online a dynamic Javascript API-Reference later.

How To's:


Sourcemod Web IDE:

A Web-Based IDE/Compiler is available, it is able to compile plugins that include smlib or other extensions.
It has syntax highlighting and error/warning output formatting and line highlighting, check it out

Link: http://www.sourcemodplugins.org/smwebide/


Function List (More detailed list here):
Code:

// File: arrays.inc
stock Array_FindValue(any:array[], size, any:value, start=0);
stock Array_FindString(const String:array[][], size, const String:str[], bool:caseSensitive=true, start=0);
stock Array_FindLowestValue(any:array[], size, start=0);
stock Array_FindHighestValue(any:array[], size, start=0);
stock Array_Fill(any:array[], size, any:value, start=0);
stock Array_Copy(const any:array[], any:newArray[], size);

// File: clients.inc
stock Client_SetHideHud(client, flags);
stock bool:Client_IsValid(client, bool:checkConnected=true);
stock bool:Client_IsIngame(client);
stock bool:Client_IsIngameAuthorized(client);
stock Client_FindBySteamId(const String:auth[]);
stock Client_FindByName(const String:name[], bool:partOfName=true, bool:caseSensitive=false);
stock Obs_Mode:Client_GetObserverMode(client);
stock bool:Client_SetObserverMode(client, Obs_Mode:mode, bool:updateMoveType=true);
stock Obs_mode:Client_GetObserverLastMode(client);
stock Client_SetObserverLastMode(client, Obs_Mode:mode);
stock Client_GetViewOffset(client, Float:vec[3]);
stock Client_SetViewOffset(client, Float:vec[3]);
stock Client_GetObserverTarget(client);
stock Client_SetObserverTarget(client, entity, bool:resetFOV=true);
stock Client_GetFOV(client);
stock Client_SetFOV(client, value);
stock bool:Client_DrawViewModel(client);
stock Client_SetDrawViewModel(client, bool:drawViewModel);
stock Client_SetThirdPersonMode(client, enable=true);
stock Client_IsInThirdPersonMode(client);
stock bool:Client_ScreenFade(client, duration, mode, holdtime=-1, r=0, g=0, b=0, a=255, bool:reliable=true);
stock Client_GetClones(client, cloneList[]);
stock bool:Client_IsOnLadder(client);
stock Water_Level:Client_GetWaterLevel(client);
stock Float:Client_GetSuitSprintPower(client);
stock Client_SetSuitSprintPower(client, Float:power);
stock Client_GetCount(bool:countInGameOnly=true, bool:countFakeClients=true);
stock Client_GetFakePing(client, bool:goldSource=true);
stock Client_GetClosestToClient(client);
stock Client_GetLastPlaceName(client, String:buffer[], size);
stock Client_GetScore(client);
stock Client_SetScore(client, value);
stock Client_GetDeaths(client);
stock Client_SetDeaths(client, value);
stock Client_GetArmor(client);
stock Client_SetArmor(client, value);
stock Float:Client_GetSuitPower(client);
stock Client_SetSuitPower(client, Float:value);
stock Client_GetActiveDevices(client);
stock Float:Client_GetNextDecalTime(client);
stock bool:Client_CanSprayDecal(client);
stock Client_GetVehicle(client);
stock bool:Client_IsInVehicle(client);
stock Client_RemoveAllDecals(client);
stock bool:Client_ExitVehicle(client);
stock bool:Client_RawAudio(client, const emitter, const String:soundfile[], Float:length = 0.0, pitch = 100);
stock bool:Client_RawAudioToAll(const emitter, const String:soundfile[], Float:length = 0.0, pitch = 100);
stock Client_Impulse(client, value);
stock Client_GetWeaponsOffset(client);
stock Client_GetActiveWeapon(client);
stock Client_GetActiveWeaponName(client, String:buffer[], size);
stock Client_SetActiveWeapon(client, weapon);
stock bool:Client_ChangeWeapon(client, const String:className[]);
stock Client_ChangeToLastWeapon(client);
stock Client_GetLastActiveWeapon(client);
stock bool:Client_GetLastActiveWeaponName(client, String:buffer[], size);
stock Client_SetLastActiveWeapon(client, weapon);
stock Client_EquipWeapon(client, weapon, bool:switchTo=false);
stock bool:Client_DetachWeapon(client, weapon);
stock Client_GiveWeapon(client, const String:className[], bool:switchTo=true);
stock Client_GiveWeaponAndAmmo(client, const String:className[], bool:switchTo=true, primaryAmmo=-1, secondaryAmmo=-1, primaryClip=-1, secondaryClip=-1);
stock bool:Client_RemoveWeapon(client, const String:className[], bool:firstOnly=true, bool:clearAmmo=false);
stock Client_RemoveAllWeapons(client, const String:exclude[]="", bool:clearAmmo=false);
stock Client_HasWeapon(client, const String:className[]);
stock Client_GetWeapon(client, const String:className[]);
stock Client_GetWeaponBySlot(client, slot);
stock Client_GetDefaultWeapon(client);
stock bool:Client_GetDefaultWeaponName(client, String:buffer[], size);
stock Client_GetFirstWeapon(client);
stock Client_GetWeaponCount(client);
stock bool:Client_IsReloading(client);
stock bool:Client_SetWeaponClipAmmo(client, const String:className[], primaryClip=-1, secondoaryClip=-1);
stock bool:Client_GetWeaponPlayerAmmo(client, const String:className[], &primaryAmmo=-1, &secondaryAmmo=-1);
stock bool:Client_SetWeaponPlayerAmmo(client, const String:className[], primaryAmmo=-1, secondaryAmmo=-1);
stock Client_SetWeaponPlayerAmmoEx(client, weapon, primaryAmmo=-1, secondaryAmmo=-1);
stock Client_SetWeaponAmmo(client, const String:className[], primaryAmmo=-1, secondaryAmmo=-1, primaryClip=-1, secondaryClip=-1);
stock Client_GetNextWeapon(client, &index = 0);
stock bool:Client_PrintHintText(client, const String:format[], any:...);
stock Client_PrintHintTextToAll(const String:format[], any:...);
stock bool:Client_PrintKeyHintText(client, const String:format[], any:...);
stock Client_PrintKeyHintTextToAll(const String:format[], any:...);
stock Client_PrintToChatRaw(client, const String:message[], subject=0, bool:isChat=false);
stock Client_PrintToChat(client, bool:isChat, const String:format[], any:...);
stock Client_PrintToChatExclude(client);
stock Client_PrintToChatAll(bool:isChat, const String:format[], any:...);
stock Client_PrintToChatEx(clients[], numClients, bool:isChat, const String:format[], any:...);
stock Client_PrintToConsole(client, const String:format[], any:...);
stock Client_Print(client, ClientHudPrint:destination, const String:format[], any:...);
stock Client_Reply(client, const String:format[], any:...);
stock bool:Client_Shake(client, command=SHAKE_START, Float:amplitude=50.0, Float:frequency=150.0, Float:duration=3.0);
stock bool:Client_IsAdmin(client);
stock bool:Client_HasAdminFlags(client, flags=ADMFLAG_GENERIC);
stock bool:Client_IsInAdminGroup(client, const String:groupName[], bool:caseSensitive=true);
stock bool:Client_IsLookingAtWall(client, Float:distance=40.0);
stock Client_GetClass(client);
stock Client_SetClass(client, class, bool:persistant=false);
stock Client_GetButtons(client);
stock Client_SetButtons(client, buttons);
stock Client_AddButtons(client, buttons);
stock Client_RemoveButtons(client, buttons);
stock Client_ClearButtons(client);
stock bool:Client_HasButtons(client, buttons);
stock Client_GetChangedButtons(client);
stock Client_SetMaxSpeed(client, Float:value);
stock Client_SetScreenOverlay(client, const String:path[]);
stock Client_SetScreenOverlayForAll(const String:path[]);
stock Client_Mute(client);
stock Client_UnMute(client);
stock bool:Client_IsMuted(client);
stock bool:Client_MatchesFilter(client, flags);
stock Client_Get(clients[], flags=CLIENTFILTER_ALL);
stock Client_GetRandom(flags=CLIENTFILTER_ALL);
stock Client_GetNext(flags, start=1);
stock Float:Client_GetMapTime(client);

// File: colors.inc
stock Color_ChatSetSubject(client);
stock Color_ChatClearSubject();
stock Color_ParseChatText(const String:str[], String:buffer[], size);
stock Color_TagToCode(const String:tag[], &subject=-1);
stock Color_StripFromChatText(const String:input[], String:output[], size);

// File: concommands.inc
stock bool:ConCommand_HasFlags(const String:command[], const flags);
stock ConCommand_AddFlags(const String:command[], const flags);
stock ConCommand_RemoveFlags(const String:command[], const flags);

// File: convars.inc
stock bool:Convar_HasFlags(Handle:convar, flags);
stock Convar_AddFlags(Handle:convar, flags);
stock Convar_RemoveFlags(Handle:convar, flags);
stock bool:Convar_IsValidName(const String:name[]);

// File: crypt.inc
stock Crypt_Base64Encode(const String:sString[], String:sResult[], len, sourcelen=0);
stock Crypt_Base64Decode(const String:sString[], String:sResult[], len);
stock Crypt_Base64MimeToUrl(const String:sString[], String:sResult[], len);
stock Crypt_Base64UrlToMime(const String:sString[], String:sResult[], len);
stock Crypt_MD5(const String:str[], String:output[], maxlen);
stock Crypt_RC4Encode(const String:input[], const String:pwd[], String:output[], maxlen);
stock Crypt_RC4EncodeBinary(const String:input[], str_len, const String:pwd[], String:output[], maxlen);

// File: debug.inc
stock Debug_FloatArray(const Float:array[], size=3);

// File: dynarrays.inc
stock bool:DynArray_GetBool(Handle:array, index, block=0, bool:asChar=false);

// File: edicts.inc
stock Edict_FindByName(const String:name[]);
stock Edict_FindByHammerId(hammerId);
stock Edict_GetClosest(Float:vecOrigin_center[3], bool:clientsOnly=false, ignoreEntity=-1);
stock Edict_GetClosestToEdict(edict, bool:clientsOnly=false);

// File: effects.inc
stock bool:Effect_DissolveEntity(entity, DissolveType:dissolveType=DISSOLVE_NORMAL);
stock bool:Effect_DissolvePlayerRagDoll(client, DissolveType:dissolveType=DISSOLVE_NORMAL);
stock Effect_Fade(entity, fadeOut=true, kill=false, fast=true, EffectCallback:callback=INVALID_FUNCTION, any:data=0);
stock Effect_FadeIn(entity, fast=true, EffectCallback:callback=INVALID_FUNCTION, any:data=0);
stock Effect_FadeOut(entity, kill=false, fast=true, EffectCallback:callback=INVALID_FUNCTION, any:data=0);
stock Effect_DrawBeamBoxToClient();
stock Effect_DrawBeamBoxToAll();
stock Effect_DrawBeamBox();

// File: entities.inc
stock Entity_IsValid(entity);
stock Entity_FindByName(const const String:name[], const String:class[]="");
stock Entity_FindByHammerId(hammerId, const String:class[]="");
stock Entity_FindByClassName(startEntity, const String:className[]);
stock bool:Entity_ClassNameMatches(entity, const String:className[], partialMatch=false);
stock bool:Entity_NameMatches(entity, const String:name[]);
stock Entity_GetName(entity, String:buffer[], size);
stock Entity_SetName(entity, const String:name[], any:...);
stock Entity_GetClassName(entity, String:buffer[], size);
stock Entity_SetClassName(entity, const String:className[]);
stock Entity_GetTargetName(entity, String:buffer[], size);
stock Entity_SetTargetName(entity, const String:name[], any:...);
stock Entity_GetGlobalName(entity, String:buffer[], size);
stock Entity_SetGlobalName(entity, const String:name[], any:...);
stock Entity_GetParentName(entity, String:buffer[], size);
stock Entity_SetParentName(entity, const String:name[], any:...);
stock Entity_GetHammerId(entity);
stock Float:Entity_GetRadius(entity);
stock Entity_SetRadius(entity, Float:radius);
stock Entity_GetMinSize(entity, Float:vec[3]);
stock Entity_SetMinSize(entity, Float:vecMins[3]);
stock Entity_GetMaxSize(entity, Float:vec[3]);
stock Entity_SetMaxSize(entity, Float:vecMaxs[3]);
stock Entity_SetMinMaxSize(entity, Float:vecMins[3], Float:vecMaxs[3]);
stock Entity_GetSpawnFlags(entity);
stock Entity_SetSpawnFlags(entity, flags);
stock Entity_AddSpawnFlags(entity, flags);
stock Entity_RemoveSpawnFlags(entity, flags);
stock Entity_ClearSpawnFlags(entity);
stock bool:Entity_HasSpawnFlags(entity, flags);
stock Entity_Flags:Entity_GetEFlags(entity);
stock Entity_SetEFlags(entity, Entity_Flags:flags);
stock Entity_AddEFlags(entity, Entity_Flags:flags);
stock Entity_RemoveEFlags(entity, Entity_Flags:flags);
stock bool:Entity_HasEFlags(entity, Entity_Flags:flags);
stock Entity_MarkSurrBoundsDirty(entity);
stock Entity_GetFlags(entity);
stock Entity_SetFlags(entity, flags);
stock Entity_AddFlags(entity, flags);
stock Entity_RemoveFlags(entity, flags);
stock Entity_ToggleFlag(entity, flag);
stock Entity_ClearFlags(entity);
stock SolidFlags_t:Entity_GetSolidFlags(entity);
stock Entity_SetSolidFlags(entity, SolidFlags_t:flags);
stock Entity_AddSolidFlags(entity, SolidFlags_t:flags);
stock Entity_RemoveSolidFlags(entity, SolidFlags_t:flags);
stock Entity_ClearSolidFlags(entity);
stock bool:Entity_SolidFlagsSet(entity, SolidFlags_t:flagMask);
stock SolidType_t:Entity_GetSolidType(entity);
stock Entity_SetSolidType(entity, SolidType_t:value);
stock bool:Entity_IsSolid(entity);
stock Entity_GetModel(entity, String:buffer[], size);
stock Entity_SetModel(entity, const String:model[]);
stock Entity_GetModelIndex(entity);
stock Entity_SetModelIndex(entity, index);
stock Entity_SetMaxSpeed(entity, Float:value);
stock Collision_Group_t:Entity_GetCollisionGroup(entity);
stock Entity_SetCollisionGroup(entity, Collision_Group_t:value);
stock Entity_GetAbsOrigin(entity, Float:vec[3]);
stock Entity_SetAbsOrigin(entity, Float:vec[3]);
stock Entity_GetAbsAngles(entity, Float:vec[3]);
stock Entity_SetAbsAngles(entity, Float:vec[3]);
stock Entity_GetLocalVelocity(entity, Float:vec[3]);
stock Entity_SetLocalVelocity(entity, const Float:vec[3]);
stock Entity_GetBaseVelocity(entity, Float:vec[3]);
stock Entity_SetBaseVelocity(entity, const Float:vec[3]);
stock Entity_GetAbsVelocity(entity, Float:vec[3]);
stock Entity_SetAbsVelocity(entity, const Float:vec[3]);
stock bool:Entity_IsLocked(entity);
stock Entity_Lock(entity);
stock Entity_UnLock(entity);
stock Entity_GetHealth(entity);
stock Entity_SetHealth(entity, value, ignoreMax=false, kill=true);
stock Entity_AddHealth(entity, value, ignoreMax=false, kill=true);
stock Entity_TakeHealth(entity, value, ignoreMax=false, kill=true);
stock Entity_GetMaxHealth(entity);
stock Entity_SetMaxHealth(entity, value);
stock Float:Entity_GetDistanceOrigin(entity, const Float:vec[3]);
stock Float:Entity_GetDistance(entity, target);
stock bool:Entity_InRange(entity, target, Float:distance);
stock bool:Entity_EnableMotion(entity);
stock bool:Entity_DisableMotion(entity);
stock Entity_Freeze(entity);
stock Entity_UnFreeze(entity);
stock Entity_PointAtTarget(entity, target, const String:name[]="");
stock Entity_PointHurtAtTarget(entity, target, const String:name[]="");
stock bool:Entity_IsPlayer(entity);
stock Entity_Create(const String:className[], ForceEdictIndex=-1);
stock bool:Entity_Kill(kenny);
stock Entity_KillAllByClassName(const String:className[]);
stock Entity_GetOwner(entity);
stock Entity_SetOwner(entity, newOwner);
stock Entity_GetGroundEntity(entity);
stock bool:Entity_Hurt(entity, damage, attacker=0, damageType=DMG_GENERIC, const String:fakeClassName[]="");
stock Entity_GetParent(entity);
stock Entity_RemoveParent(entity);
stock Entity_SetParent(entity, parentEntity);

// File: files.inc
stock bool:File_GetBaseName(const String:path[], String:buffer[], size);
stock bool:File_GetDirName(const String:path[], String:buffer[], size);
stock bool:File_GetFileName(const String:path[], String:buffer[], size);
stock File_GetExtension(const String:path[], String:buffer[], size);
stock File_AddToDownloadsTable(const String:path[], bool:recursive=true, const String:ignoreExts[][]=_smlib_empty_twodimstring_array, size=0);
stock File_ReadDownloadList(const String:path[]);
stock File_LoadTranslations(const String:file[]);
stock File_ToString(const String:path[], String:buffer[], size);
stock bool:File_StringToFile(const String:path[], String:str[]);
stock bool:File_Copy(const String:source[], const String:destination[]);
stock bool:File_CopyRecursive(const String:path[], const String:destination[], bool:stop_on_error=false, dirMode=493);

// File: game.inc
stock bool:Game_End();
stock bool:Game_EndRound(team=0, bool:forceMapReset=false, bool:switchTeams=false);

// File: general.inc
stock PrecacheMaterial(const String:material[]);
stock bool:IsMaterialPrecached(const String:material[]);
stock PrecacheParticleSystem(const String:particleSystem[]);
stock bool:IsParticleSystemPrecached(const String:particleSystem[]);
stock FindStringIndexByTableName(const String:table[], const String:str[]);
stock FindStringIndex2(tableidx, const String:str[]);
stock LongToIP(ip, String:buffer[], size);
stock IPToLong(const String:ip[]);
stock bool:IsIPLocal(ip);

// File: math.inc
stock any:Math_Abs(any:number);
stock bool:Math_VectorsEqual(Float:vec1[3], Float:vec2[3], Float:tolerance=0.0);
stock any:Math_Min(any:value, any:min);
stock any:Math_Max(any:value, any:max);
stock any:Math_Clamp(any:value, any:min, any:max);
stock bool:Math_IsInBounds(any:value, any:min, any:max);
stock any:Math_Overflow(any:value, any:min, any:max);
stock Math_GetRandomInt(min, max);
stock Float:Math_GetRandomFloat(Float:min, Float:max);
stock Math_GetPercentage(value, all);
stock Float:Math_GetPercentageFloat(Float:value, Float:all);
stock Math_MoveVector(const Float:start[3], const Float:end[3], Float:scale, Float:output[3]);
stock Float:Math_UnitsToMeters(Float:units);
stock Float:Math_UnitsToFeet(Float:units);

// File: server.inc
stock Server_GetIP(bool:public_=true);
stock bool:Server_GetIPString(String:buffer[], size, bool:public_=true);
stock Server_GetPort();
stock bool:Server_GetHostName(String:buffer[], size);

// File: sql.inc
stock SQL_TQueryF(Handle:database, SQLTCallback:callback, any:data, DBPriority:priority=DBPrio_Normal, const String:format[], any:...);
stock SQL_FetchIntByName(Handle:query, String:fieldName[], &DBResult:result=DBVal_Error);
stock bool:SQL_FetchBoolByName(Handle:query, String:fieldName[], &DBResult:result=DBVal_Error);
stock Float:SQL_FetchFloatByName(Handle:query, String:fieldName[], &DBResult:result=DBVal_Error);
stock SQL_FetchStringByName(Handle:query, String:fieldName[], String:buffer[], maxlength, &DBResult:result=DBVal_Error);

// File: strings.inc
stock bool:String_IsNumeric(const String:str[]);
stock String_Trim(const String:str[], String:output[], size, const String:chrs[]=" \t\r\n");
stock String_RemoveList(String:buffer[], String:removeList[][], size, bool:caseSensitive=false);
stock String_ToLower(const String:input[], String:output[], size);
stock String_ToUpper(const String:input[], String:output[], size);
stock String_GetRandom(String:buffer[], size, length=32, const String:chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234556789");

// File: teams.inc
stock bool:Team_HaveAllPlayers(bool:countFakeClients=true);
stock Team_GetClientCount(team, flags=0);
stock Team_GetClientCounts(&team1=0, &team2=0, flags=0);
stock bool:Team_GetName(index, String:str[], size);
stock bool:Team_SetName(index, const String:name[]);
stock Team_GetScore(index);
stock bool:Team_SetScore(index, score);
stock Team_EdictGetNum(edict);
stock bool:Team_IsValid(index);
stock Team_EdictIsValid(edict);
stock Team_GetEdict(index);
stock Team_GetAnyClient(index);

// File: vehicles.inc
stock Vehicle_GetDriver(vehicle);
stock bool:Vehicle_HasDriver(vehicle);
stock bool:Vehicle_ExitDriver(vehicle);
stock bool:Vehicle_TurnOn(vehicle);
stock bool:Vehicle_TurnOff(vehicle);
stock bool:Vehicle_Lock(vehicle);
stock bool:Vehicle_Unlock(vehicle);
stock bool:Vehicle_IsValid(vehicle);
stock bool:Vehicle_GetScript(vehicle, String:buffer[], size);
stock bool:Vehicle_SetScript(vehicle, String:script[]);

// File: weapons.inc
stock Weapon_GetOwner(weapon);
stock Weapon_SetOwner(weapon, entity);
stock Weapon_IsValid(weapon);
stock Weapon_Create(const String:className[], Float:absOrigin[3], Float:absAngles[3]);
stock Weapon_CreateForOwner(client, const String:className[]);
stock Weapon_GetSubType(weapon, value);
stock bool:Weapon_IsReloading(weapon);
stock Weapon_GetState(weapon);
stock bool:Weapon_FiresUnderWater(weapon);
stock Weapon_SetFiresUnderWater(weapon, bool:can=true);
stock bool:Weapon_FiresUnderWaterAlt(weapon);
stock Weapon_SetFiresUnderWaterAlt(weapon, bool:can=true);
stock Weapon_GetPrimaryAmmoType(weapon);
stock Weapon_GetSecondaryAmmoType(weapon);
stock Weapon_GetPrimaryClip(weapon);
stock Weapon_SetPrimaryClip(weapon, value);
stock Weapon_GetSecondaryClip(weapon);
stock Weapon_SetSecondaryClip(weapon, value);
stock Weapon_SetClips(weapon, primary, secondary);
stock Weapon_GetPrimaryAmmoCount(weapon);
stock Weapon_SetPrimaryAmmoCount(weapon, value);
stock Weapon_GetSecondaryAmmoCount(weapon);
stock Weapon_SetSecondaryAmmoCount(weapon, value);
stock Weapon_SetAmmoCounts(weapon, primary, secondary);
stock Weapon_GetViewModelIndex(weapon);
stock Weapon_SetViewModelIndex(weapon, index);

// File: world.inc
stock World_GetMaxs(Float:vec[3]);


Todo:

  • Add support for own include files to the Web IDE
  • Dynamic Javascript-API Page
  • Add template files for editors to smlib.
  • Add Chanz's plugin manager to smlib.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 02-10-2013 at 12:45.
berni is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-24-2011 , 20:01   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #2

SMLib Colors API

The smlib colors API is a very powerful system for coloring the chat,
written to be as flexible as possible (alternative colors, color overriding) while keeping an
eye on performance. It should be almost as fast as Sourcemod's native PrintToChat. It also
uses some caching techniques which means smlib's Client_PrintToChatAll() can be even faster than sourcemod's native.

Here are the color tags you can use with Color_ParseChatText() and all Client_PrintToChat() functions.

This table shows the default/hardcoded into smlib settings, but they
can be overriden by placing a smlib_colors.games.txt into the gamedata folder.



Legend:
Colors only available in Teamplay Mode (mp_teamplay 1)
The game automatically colors player nicknames into their team colors.


Things you should know...

  • Only one team/subject color can be used in one message, this doesn't mean you can color only one phrase, that means you can only use red or blue or green in one print.
  • The team specific subject colors (eg.: red, blue) are only used if at least one client is in that team that has the color, if not, the alternative color is used.
  • the {RB} and {BR} tags use either Red or Blue for coloring, depending on if a team has clients in it, if all teams are empty, green is used by default.
  • Colors that are unavailable are replaced with green by default.
Overriding the default color settings

File: gamedata/smlib_colors.games.txt

The color settings can be overriden with a gamedata file, while this shouldn't be necessary
for games like TF2, CS:S, HL2:DM, L4D(2), DOD:S, this can be very useful for older games or
upcoming games like Portal 2.

There comes a gamedata file with smlib that has the default settings for the games mentioned above,
if SayText2 isn't supported, smlib automatically disables team/subject colors itself.
Note that you don't have to distribute this file for colors to work in most cases.

Valid colors are:

"normal"
"orange"
"red"
"redblue"
"blue"
"bluered"
"team"
"lightgreen"
"gray"
"green"
"olivegreen"
"black"

Valid keyvalues are:

color_code Color Code (1 - 8)
color_alternative Defines the index of alternative color (see the chatColorInfo array in colors.inc)
color_supported Set to "true" if the color is supported, "false" otherwise.
color_subjecttype (see ChatColorSubjectType enum in colors.inc, any value higher than 0 defines a team color)
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 09-30-2012 at 17:13.
berni is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 03-20-2011 , 10:16   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #3

Quote:
Originally Posted by berni View Post
is this suggesting that you can use lightgreen in hl2mp because if it did that would be awsome.
__________________
Master(d)



Master53 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-20-2011 , 12:07   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #4

Quote:
Originally Posted by berni View Post
Valid colors are:
...
"black"
D:

Quote:
Originally Posted by asherkin View Post
\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}.
__________________
asherkin is offline
Ellie
Senior Member
Join Date: Apr 2013
Old 08-30-2013 , 20:17   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #5

Been using this is some plugins (though I had to edit all their sources) and seems to be working great. Many thanks. Quick question though about this:

Quote:
Originally Posted by berni View Post
Colors that are unavailable are replaced with green by default.
What do I need to change so that the unavailable color is replaced with orange instead of green?


Also, about these two:

Code:
PrintToChatAll( "%s", message );
PrintToChat(param1, "blah");
I can't get them to work. I get an argument type mismatch. How can I fix that?

Last edited by Ellie; 08-31-2013 at 06:41.
Ellie is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 08-31-2013 , 12:36   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #6

Quote:
Originally Posted by Ellie View Post
Been using this is some plugins (though I had to edit all their sources) and seems to be working great. Many thanks. Quick question though about this:



What do I need to change so that the unavailable color is replaced with orange instead of green?
You can use smlib_colors.games.txt.
Just put the it into your gamedata folder and put something like the following into the #default section:

Code:
"red_alternative"	"1" // 1 = orange in the color table (See: https://github.com/bcserv/smlib/blob/master/scripting/include/smlib/colors.inc#L78)
This should work.


Quote:
Originally Posted by Ellie View Post
Also, about these two:

Code:
PrintToChatAll( "%s", message );
PrintToChat(param1, "blah");
I can't get them to work. I get an argument type mismatch. How can I fix that?
Don't know, at first, those functions are not from smlib.
And you have to post more code so I can see how the used variables are defined.
But looks like either message is not a string or param1 not an integer cell.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Ellie
Senior Member
Join Date: Apr 2013
Old 08-31-2013 , 18:35   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #7

Quote:
Originally Posted by berni View Post
You can use smlib_colors.games.txt.
Just put the it into your gamedata folder and put something like the following into the #default section:

Code:
"red_alternative"    "1" // 1 = orange in the color table (See: https://github.com/bcserv/smlib/blob/master/scripting/include/smlib/colors.inc#L78)
This should work.

Ah thanks, I'll try it now. Originally I was editing the actual color.inc file and had changed all the greens in the "alternate column", then saving it and recompiling the plugins, but was still getting green anyway.




Quote:
Originally Posted by berni View Post
Don't know, at first, those functions are not from smlib.
And you have to post more code so I can see how the used variables are defined.
But looks like either message is not a string or param1 not an integer cell.

Sure, those is particular are from the connect announce plugin. This is the code:
Code:
PrintFormattedMessageToAll( String:rawmsg[301], client )
{
    decl String:message[301];
    
    GetFormattedMessage( rawmsg, client, message, sizeof(message) );
    
    PrintToChatAll( "%s", message );
}
Code:
public MenuHandler_Vote(Handle:menu, MenuAction:action, param1, param2)
{
    if (action == MenuAction_End)
    {
        CloseHandle(menu);
    }
    else if (action == MenuAction_Select)
    {
        decl String:info[32], String:name[32];
        new target;
        
        GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
        target = StringToInt(info);

        if (target == 0)
        {
           PrintToChat(param1, "[SM] %s", "Player no longer available");
        }
        else
        {
            DisplayVoteMuteMenu(param1, target);
        }
    }
}
Hope I didn't miss anything.

Edit:
Just cam across another plugin, I having a bit of trouble with. It uses this StatsPrintToChat2. Guess I can't use SMLib for that huh?

Last edited by Ellie; 08-31-2013 at 19:29.
Ellie is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 09-01-2013 , 06:48   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #8

Quote:
Originally Posted by Ellie View Post
Ah thanks, I'll try it now. Originally I was editing the actual color.inc file and had changed all the greens in the "alternate column", then saving it and recompiling the plugins, but was still getting green anyway.
Not sure, should work.

Quote:
Originally Posted by Ellie View Post
Sure, those is particular are from the connect announce plugin. This is the code:
I'm not getting the errors your posted, are you sure those errors occur in that code ?

Quote:
Originally Posted by Ellie View Post
Edit:
Just cam across another plugin, I having a bit of trouble with. It uses this StatsPrintToChat2. Guess I can't use SMLib for that huh?[URL="http://forums.alliedmods.net/showthread.php?t=115965"]
You mean with colors ? why not ? simply replace the line 11491 with that:

PHP Code:
Client_PrintToChat(Clientfalse"\x04[\x03RANK\x04] \x01%s"Message); 
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 09-01-2013 at 06:49.
berni is offline
Ellie
Senior Member
Join Date: Apr 2013
Old 03-15-2014 , 02:58   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #9

Quote:
Originally Posted by berni View Post

Been using this with TF2 and out of the 12 color tags, {O} and {GRA} don't work at all. Orange always comes out the default color for me (it doesn't even give me the alternate color which is suppose to be green). I'm thinking that color chart above is wrong about having orange available for TF2 because in colors.inc it doesn't mention orange in TF2 at all (which you can see in this image). The color gray doesn't work for me even if someone is on the spectator team. Anyone get gray working with this in TF2? Also tried this with L4D2 and all the 11 color tags mentioned in your chart for L4D2 work fine. But oddly enough the {GRA} tag works even if there isn't anyone on the spectator team. How can that be? I though team colors only worked if there was at least one person on the team. In L4D2s case, the blue color tags always work because there is always someone (or bot) on the blue team, which is not the case for the red and gray teams. But gray works even when I was the only person on the server and I was on the blue team. Maybe what is done with L4D2 gray tag can be done for all colors for all games?

Last edited by Ellie; 03-15-2014 at 03:19.
Ellie is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-16-2014 , 10:51   Re: SMLIB 0.9 BETA (266 Function Stocks)
Reply With Quote #10

Quote:
Originally Posted by Ellie View Post
Been using this with TF2 and out of the 12 color tags, {O} and {GRA} don't work at all. Orange always comes out the default color for me (it doesn't even give me the alternate color which is suppose to be green). I'm thinking that color chart above is wrong about having orange available for TF2 because in colors.inc it doesn't mention orange in TF2 at all (which you can see in this image). The color gray doesn't work for me even if someone is on the spectator team. Anyone get gray working with this in TF2? Also tried this with L4D2 and all the 11 color tags mentioned in your chart for L4D2 work fine. But oddly enough the {GRA} tag works even if there isn't anyone on the spectator team. How can that be? I though team colors only worked if there was at least one person on the team. In L4D2s case, the blue color tags always work because there is always someone (or bot) on the blue team, which is not the case for the red and gray teams. But gray works even when I was the only person on the server and I was on the blue team. Maybe what is done with L4D2 gray tag can be done for all colors for all games?
You need to start with a tag and then use another in some cases.
For tf2, just use hex directly in print to chat, and don't use this at all. You get more colors that way anyways.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply


Thread Tools
Display Modes

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 12:05.


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