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)

berni 01-24-2011 19:56

SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
 
https://s3.amazonaws.com/github/ribb...een_007200.png http://www.sourcemodplugins.org/bund...plugins_sm.png

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



http://berni.bcserv.eu/uploads/images/github-icon.png We use Github - Code contributions are welcome! - Read more here

http://www.sourcemodplugins.org/bund...urcemod/sm.png 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.

http://www.sourcemodplugins.org/bund...quirements.png 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.

http://www.sourcemodplugins.org/bund...od/Authors.png Authors: Berni, Chanz and other Github contributors

http://www.sourcemodplugins.org/bund.../Downloads.png Download:
SMLIB 0.11 BETA

License: GNU General Public License 3.0

http://www.sourcemodplugins.org/bund...stallation.png 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/


http://www.sourcemodplugins.org/bund...d/Features.png 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]);



http://www.sourcemodplugins.org/bund...emod/Todos.png 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.

berni 01-24-2011 20:01

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
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.

http://www.sourcemodplugins.org/bund...lib_colors.png

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)

recon0 01-24-2011 23:35

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
Very nice.

dirtyminuth 01-25-2011 00:17

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
I should not be this excited about stocks! :)

Nice work and thanks for your efforts, already learning a lot just digging through the code!

exvel 01-25-2011 11:39

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
Gj, like it :)

Peace-Maker 01-25-2011 12:33

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
Nice work! No more need for my own little library:) You're the men!

berni 01-25-2011 12:55

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
Thanks :wink:

If you guys need anything added, find a bug or have difficulties with something, just ask.

miniman 01-26-2011 02:29

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
1.
PHP Code:

stock (client,  const String:className[]); 

2. Its AWESOME

AtomicStryker 01-26-2011 03:02

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
PHP Code:

Entity_FindByName 

this one uses a classname

PHP Code:

Entity_GetName 

this one a netpropname


Also, you don't actually have a "FindEntityByNetpropName" function, maybe add that.
(netpropname is m_iName .. i don't know what better to call it)

asherkin 01-26-2011 05:36

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

Originally Posted by AtomicStryker (Post 1399624)
(netpropname is m_iName .. i don't know what better to call it)

targetname

berni 01-26-2011 08:08

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

Originally Posted by miniman (Post 1399610)
1.
PHP Code:

stock (client,  const String:className[]); 


There has been a space between the return type and the functionname, the .inc parser doesn't seeem to like that :)

Quote:

Originally Posted by AtomicStryker (Post 1399624)
PHP Code:

Entity_FindByName 

this one uses a classname

PHP Code:

Entity_GetName 

this one a netpropname

Also, you don't actually have a "FindEntityByNetpropName" function, maybe add that.
(netpropname is m_iName .. i don't know what better to call it)

Entity_FindByName takes classname and name. Reason is that Sourcemod currently provides no way iterating over the whole entity list (including none-edict ents) without knowing the classname (FindEntityByClassname).

However there is also Edict_FindByName, that doesn't need a classname to be specified, which searches for edicts only, edicts are all entities with index < 2048, it should be what you need :)

name == m_iName == targetname, it's all the same.
I don't why Valve has chosen such a weird keyvalue name for the entity name, but the keyvalue targetname is just an alias for m_iName.
But don't mix this with the entity's classname, that are different functions.

AtomicStryker 01-26-2011 08:42

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

Originally Posted by asherkin (Post 1399682)
targetname


The issue i could see with just calling it that (i know its the same) is that he HAS functions for targetnames.

I realize he is just extending the Valve confusion about this, but while he's writing wrappers, could he not add one that loops all entities AND the non-ent edicts for a "name" without classname.

Also he should name the function i quoted Entity_FindByClassName

berni 01-26-2011 08:51

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
No, you got it wrong.

Entity_FindByName searches for a name, not classname, but it needs the classname to be specified, otherwise it has no way of finding none-edicts (serverside, logical or brush entities).
It's not possible to write a "wrapper" that searches for ALL entities without specifying a classname, it's a Sourcemod Limit. ok nvm, psychonic forces me to use dirty haxx to iterate over all entities without classnames :twisted: I will consider adding it to the next smlib version.

But I would say if you want to get an entity by it's name, you know its classname mostly too, otherwise use Edict_FindByName().

I don't extend Valve's confusion, I escape it by naming it correctly.

FaTony 01-26-2011 15:51

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
What? It's simple to iterate all entities to find the matching targetname.

zeroibis 01-27-2011 01:11

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
This is great, just read over the entire list. I am going to start using this on the very next plugin I make!

naris 01-27-2011 16:48

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
This function must not be correct :?

I would think that "connectspectate.phrases" should be replaced with path and "translations/connectspectate.phrases.txt" with szTranslationsPath.

PHP Code:

stock File_LoadTranslations(const String:path[])
{
    new 
String:szTranslationsPath[PLATFORM_MAX_PATH];

    
Format(szTranslationsPath,sizeof(szTranslationsPath),"translations/%s",path);
    
BuildPath(Path_SMszTranslationsPathsizeof(szTranslationsPath), "translations/connectspectate.phrases.txt");
    
    if (
FileExists(szTranslationsPath)){
        
LoadTranslations("connectspectate.phrases");
    } 
    else {
        
SetFailState("[%s] Unable to locate translation file (%s).",g_sPlugin_Name,szTranslationsPath);
    } 


naris 01-27-2011 16:56

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
This function really should have and use the maxlen parameter mentioned in the comment, that is not present in the actual function, instead of the literal 2147483647!

PHP Code:

/**
 * Removes a list of strings from a string.
 *
 * @param buffer            Input/Ourput buffer.
 * @param maxlen            Max size of buffer.
 * @param removeList        A list of strings which should be removed from buffer.
 * @param size                Number of Strings in the List.
 * @noreturn
 */
stock String_RemoveList(String:buffer[], String:removeList[][], sizebool:caseSensitive=false)
{    
    for (new 
i=0sizei++) {
        
ReplaceString(buffer2147483647removeList[i], ""caseSensitive);
    }



berni 01-27-2011 21:12

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

Originally Posted by naris (Post 1401052)
This function must not be correct :?

I would think that "connectspectate.phrases" should be replaced with path and "translations/connectspectate.phrases.txt" with szTranslationsPath.


Thanks we just fixed that and will release a new smlib version shortly.

Quote:

Originally Posted by naris (Post 1401059)
This function really should have and use the maxlen parameter mentioned in the comment, that is not present in the actual function, instead of the literal 2147483647!

hehe, not that easy to understand :wink:
the function is actually right, the comment is just wrong.
A size parameter isn't needed, since we we would never make the string bigger, it can only get shorter, that's why we take the max value of an unsigned integer.

zeroibis 01-27-2011 23:31

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
I noticed that when using:
Client_SetActiveWeapon(client, weapon);
if you set it to knife you do not see it until you fire.

berni 01-27-2011 23:39

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
I'll try to reproduce this on my testserver, but I think I know already know what is wrong, thx.

Peace-Maker 01-28-2011 03:49

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
When using
PHP Code:

stock bool:Effect_DissolvePlayerRagDoll(client

on player_death i get an error pointing out, that the netprop "dissolvetype" doesn't extist on that entity. You may change it to "m_nDissolveType" or use AcceptEntityInput.
I'm testing in CS:S.

I also often use psychonic's improved GetURandomIntRange(min, max) stock you may want to include?

berni 01-28-2011 11:34

Re: SMLIB 0.9 BETA (266 Function Stocks)
 
New smlib update available: smlib 0.9.2 beta

Compatibility breaks: none

Changes:

Quote:

Made the argument classname of the Function Entity_FindByName() optional.
Added Function Entity_FindByHammerId()
Added Function Entity_FindByClassName() for completion.
Added Function Math_IsInBounds()
Fixed Function File_LoadTranslations()
Fixed Effect_DissolveEntity() (it used a wrong netprop).
Added parameter dissolveType to Effect_DissolveEntity() and Effect_DissolvePlayerRagDoll()
Fixed some comments.
Added a few missing comments.
Download here.

Quote:

Originally Posted by zeroibis (Post 1401345)
I noticed that when using:
Client_SetActiveWeapon(client, weapon);
if you set it to knife you do not see it until you fire.

I couldn't reproduce this behavior, it's working fine for me.
Can you post some example code ? thanks.

naris 01-28-2011 13:28

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

Originally Posted by berni (Post 1401243)
hehe, not that easy to understand :wink:
the function is actually right, the comment is just wrong.
A size parameter isn't needed, since we we would never make the string bigger, it can only get shorter, that's why we take the max value of an unsigned integer.

Oh, I understand it, but it still makes me cringe. It is a bit of a bad practice. However I do see the point of not having another parameter that isn't really needed.

naris 01-28-2011 13:39

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
It would be a lot better if "#include <smlib>" was omitted from the includes, especially since most of them don't require anything from the others. It would also be better if those that do require other includes included only the one they specifically need.

That was you could include only those headers that you want to actually use without having to include all 266+ stocks. Even if they don't get used they will still increase compile times.

berni 01-28-2011 15:55

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
Quote:

Originally Posted by naris (Post 1401742)
It would be a lot better if "#include <smlib>" was omitted from the includes, especially since most of them don't require anything from the others. It would also be better if those that do require other includes included only the one they specifically need.

That was you could include only those headers that you want to actually use without having to include all 266+ stocks. Even if they don't get used they will still increase compile times.

They are there because otherwise the IDE / Pawnstudio wouldn't be aware of the other functions and not syntax-highlight them. This does not increase compile time since we are using #define checks to make sure every include file gets only compiled one time.

Quote:

Originally Posted by Peace-Maker (Post 1401424)
I also often use psychonic's improved GetURandomIntRange(min, max) stock you may want to include?

Thanks, will include this, but a rewritten version, since this one doesn't work 100%.

berni 01-28-2011 16:39

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
New smlib update available: smlib 0.9.3 beta

Compatibility breaks: none

Changes:

Quote:

  • Added Function String_StripChatColors() (Original code by Psychonic, thanks)
  • Added Functions Math_GetRandomInt() and Math_GetRandomFloat()
  • Added Functions Math_GetPercentage() and Math_GetPercentageFloat()

Download here.

naris 01-28-2011 22:31

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
Quote:

Originally Posted by berni (Post 1401834)
They are there because otherwise the IDE / Pawnstudio wouldn't be aware of the other functions and not syntax-highlight them. This does not increase compile time since we are using #define checks to make sure every include file gets only compiled one time.

Actually it DOES increase compile time as it take longer to open, read and compile 274+ stocks in 18 files than it would to compile say, 10 of them in 1 single file, especially if you are compiling a large system. The #define checking just ensure that it does compile and prevents it from parsing and compiling, but not reading, the file multiple times and causing duplicate definition errors.

Why are you concerned about syntax-highlighting function that are not referenced in the file?

Including all of the includes in all of the files is an extremely bad practice. I would never allow anything that does that into our production systems at VW and neither would any of my co-workers.

FaTony 01-29-2011 00:11

Re: SMLIB 0.9.2 BETA (274 Function Stocks) | updated 28.01.2011
 
Reminds me of windows.h.

berni 01-29-2011 00:41

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
Quote:

Originally Posted by naris (Post 1401999)
Actually it DOES increase compile time as it take longer to open, read and compile 274+ stocks in 18 files than it would to compile say, 10 of them in 1 single file, especially if you are compiling a large system. The #define checking just ensure that it does compile and prevents it from parsing and compiling, but not reading, the file multiple times and causing duplicate definition errors.

Did you actually test it or do you just think so ?

I just tried it out for you:

Compile time with includes: 1.00 seconds
Compile time without: 1.00 seconds

It doesn't really read all files in every include, it just reads smlib.inc and cancels at the second line:

PHP Code:

#if defined _smlib_included
    #endinput
#endif 

Quote:

Why are you concerned about syntax-highlighting function that are not referenced in the file?
Also wrong, Functions of <sourcemod> and <sdktools> (fake included in smlib.inc) are used in almost every include file.
Again, they aren't really included for the compiler as it will cancel before in smlib.inc.

Quote:

Including all of the includes in all of the files is an extremely bad practice. I would never allow anything that does that into our production systems at VW and neither would any of my co-workers.
Oh, does VW also use SourcePawn & Pawnstudio ? lol

Believe me, I wouldn't do it if there would be a more beautiful way,
but SourcePawn just isn't C++, so we have to take what we get.
And Syntax Highlighting and Autocompletion makes the Development of smlib just way easier.

berni 01-29-2011 01:06

Re: SMLIB 0.9.2 BETA (274 Function Stocks) | updated 28.01.2011
 
Woops, I think I'm already too long awake lol.
I'll rethink this tomorrow when I'm well-rested again.

Actually it could work when we only include the headers when we are working on the include file.

Peace-Maker 01-29-2011 09:53

Re: SMLIB 0.9.2 BETA (274 Function Stocks) | updated 28.01.2011
 
PHP Code:

stock bool:Weapon_IsReloading(weapon

is missing an "return".

zeroibis 01-30-2011 18:54

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
So I am guessing these new random value functions are more random than stock ones like: GetRandomInt() or GetRandomFloat()

Also the math_clamp does actually redefine the value to min or max if it is out of bounds right?

berni 01-30-2011 19:09

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
Quote:

Originally Posted by zeroibis (Post 1403449)
So I am guessing these new random value functions are more random than stock ones like: GetRandomInt() or GetRandomFloat()

That's right, it's 100% random and uniform.
I tried psychonic's function first, but that wasn't completely random,
so I rewrote it and made some tests to make sure each value has the same chance of being returned.

Quote:

Originally Posted by zeroibis (Post 1403449)
Also the math_clamp does actually redefine the value to min or max if it is out of bounds right?

yes, it makes sure the value doesn't go below min or higher than max and corrects it if neccessary.

smlib 0.9.4 will be released today.

FaTony 01-31-2011 01:00

Re: SMLIB 0.9.2 BETA (269 Function Stocks) | updated 28.01.2011
 
Quote:

Originally Posted by berni (Post 1403457)
That's right, it's 100% random and uniform.

Heresy! You will have to use nuclear decay sensors or something like that to achieve 100% randomness and it's results still may be debated on a philosophical level.

berni 01-31-2011 01:07

Re: SMLIB 0.9.4 BETA (278 Function Stocks) | updated 31.01.2011
 
FaTony, your trolling slowly becomes annoying.
We all know that 100% randomness doesn't exist in the universe (chaos theory).
it's as random as it can be now in a sourcemod, and from a relative point of view that's 100%, not gonna debate this further.

berni 01-31-2011 01:10

Re: SMLIB 0.9.4 BETA (278 Function Stocks) | updated 31.01.2011
 
New smlib update available: smlib 0.9.4 beta

Compatibility breaks: Removed argument of Effect_FadeIn()

Changes:

Quote:

  • Added Entity_GetParent()
  • Added Entity_RemoveParent()
  • Added Entity_SetParent()
  • Added Math_MoveVector()
  • Removed unnecessary parameter kill in Function Effect_FadeIn()
  • Fixed missing any: type at "..." parameters
  • Added missing return in Function Weapon_IsReloading(), thanks to Peace-Maker!
  • Redesigned the smlib includes to allow including of single smlib includes and save some milli seconds.

Download here.

FaTony 01-31-2011 01:24

Re: SMLIB 0.9.4 BETA (278 Function Stocks) | updated 31.01.2011
 
Quote:

Originally Posted by berni (Post 1403565)
FaTony, your trolling slowly becomes annoying.
We all know that 100% randomness doesn't exist in the universe (chaos theory).
it's as random as it can be now in a sourcemod, and from a relative point of view that's 100%, not gonna debate this further.

You are scientifically incorrect. I guess SourcePawn is Turing complete, therefore it is possible to write the algorithm of infinite complexity in SourcePawn, so it'll be infinitely more random than yours. Your function is neither 100% random nor as random as possible in SourcePawn.

zeroibis 01-31-2011 02:30

Re: SMLIB 0.9.4 BETA (278 Function Stocks) | updated 31.01.2011
 
If it is random enough to give equal chance to all values in a few thousand runs that is a lot better than what we had before.

Also he said "random as it can be now" in that it is as random as it can be given the time. In order to achieve true randomness you will need to wait for an infinite duration for the now to apply for infinite randomness. So after infinite time is spent creating an infinity random random generator you can then evaluate if it is truly random. (I will try to be placed in suspended animation prior to death to await your results)

On another note I was wondering about effectiveness of the float version when used with decimal percentage values. For example: Math_GetRandomFloat(0.0,1.0)<=0.23

Is this fine, totally wrong or should I be saying 0.00,1.00 or something to improve accuracy?

FaTony 01-31-2011 03:16

Re: SMLIB 0.9.4 BETA (278 Function Stocks) | updated 31.01.2011
 
Infinite pseudo randomness =/= true randomness to me.

berni 01-31-2011 11:51

Re: SMLIB 0.9.4 BETA (278 Function Stocks) | updated 31.01.2011
 
Quote:

Originally Posted by zeroibis (Post 1403591)
On another note I was wondering about effectiveness of the float version when used with decimal percentage values. For example: Math_GetRandomFloat(0.0,1.0)<=0.23

Is this fine, totally wrong or should I be saying 0.00,1.00 or something to improve accuracy?

you can add as many 0's as you want, it will stay the same number :3
I don't know what exactly you mean, it will always have the same effectiveness.


All times are GMT -4. The time now is 20:16.

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