Raised This Month: $51 Target: $400
 12% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
vukhacson0809
New Member
Join Date: Jul 2014
Old 07-22-2014 , 06:25   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #351

Do you know how to make people glow for all alive players like in the death cam mode? That would help even more for anti-camp plugin.

Anyway, thanks for sharing !
__________________
Thông tin đầy đủ và chi tiết nhất về dự án căn hộ Vista Verde quận 2 Capitaland trả góp , Dự án tốt nhất khu vực quận 2 hiện nay, xem chi tiết tại : http://canhovistaverdequan2.com
vukhacson0809 is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 07-29-2014 , 04:29   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #352

Here's a small thing I use.

PHP Code:
#define DOWHILE_ENTFOUND(%1,%2) %1 = -1; while ((%1 = FindEntityByClassname2(%1, %2)) != -1) 
Example:

PHP Code:
    new ent;

    
DOWHILE_ENTFOUND(ent"func_breakable")
    {
        
decl String:tName[32];
        
GetEntPropString(entProp_Data"m_iName"tNamesizeof(tName));
        if (
StrEqual(tName"medic_car_break"false))
        {
            
SetVariantInt(20000);
            
AcceptEntityInput(ent"SetHealth");
        }
        else if (
GetEntProp(entProp_Data"m_iHammerID") == 3513)
        {
            
AcceptEntityInput(ent"Break");
        }
    }

    
DOWHILE_ENTFOUND(ent"item_ammopack_small")
    {
        
SetEntProp(entProp_Send"m_iTeamNum"Enabled?OtherTeam:04);
    } 
__________________

Last edited by Chdata; 07-29-2014 at 19:34.
Chdata is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-29-2014 , 18:46   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #353

Quote:
Originally Posted by Chdata View Post
Here's a small thing I use.

PHP Code:
#define DOWHILE_ENTFOUND(%1,%2) %1 = -1; while ((%1 = FindEntityByClassname2(%1, %2)) != -1) 
Can we stop this habit please?
__________________
11530 is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 07-29-2014 , 19:33   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #354

Not without any explanation of why not.
__________________
Chdata is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-29-2014 , 20:24   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #355

Quote:
Originally Posted by Chdata View Post
Not without any explanation of why not.
Since the macro is making a direct substitution, you are prone to making errors which would be avoidable had you used a standard function, or otherwise, to do the job. This could also lead to unexpected results. Take, for example, the following which I copied from an article on secure coding.

Code:
#define unsafe(i) ( (i) >= 0 ? (i) : -(i) )
Looks benign enough until you realise that calling new ans = unsafe(x++); will increment x twice, instead of once as intended. Similarly, creating a macro with an if-statement or one with multiple lines/blocks might yield syntax issues - especially with your curly brackets intentionally left out of the macro. This is forgetting the fact that there is no type-checking done in a macro and will be expanded regardless of whether or not it's syntactically correct.

Your answer may be that you'll just be super careful and won't do these things but it's better to prevent these errors completely through prudent programming than attempt to avoid them with each use.
__________________
11530 is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 07-30-2014 , 02:19   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #356

Well, I use it in the same exact way every time, so as you said, I guess that's the same as saying 'I'll be super careful'.
__________________
Chdata is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 08-04-2014 , 14:37   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #357

There's something weird about Math_Min() and Math_Max() functions.

PHP Code:
/**
 * Sets the given value to min
 * if the value is smaller than the given.
 * 
 * @param value            Value
 * @param min            Min Value used as lower border
 * @return                Correct value not lower than min
 */
stock any:Math_Min(any:valueany:min)
{
    if (
value min) {
        
value min;
    }
    
    return 
value;
}

/**
 * Sets the given value to max
 * if the value is greater than the given.
 * 
 * @param value            Value
 * @param max            Max Value used as upper border
 * @return                Correct value not upper than max
 */
stock any:Math_Max(any:valueany:max)
{    
    if (
value max) {
        
value max;
    }
    
    return 
value;

They don't return the min/max value of the two parameters provided, but rather expects the 1st parameter to be the value and the 2nd the lower/upper border. So if I have an x and an y and want to get the min/max value of them, Math_Min()/Math_Max() may return the wrong value (for instance, Math_Min(16000, 5000) will return 16000).

It should work like min()/max() functions in AMXX (or hell, in C++ even), which compare the two provided parameters and return the lower/upper value.
__________________
hleV is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-04-2014 , 15:49   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #358

It's... not like min or max are difficult functions to write...

PHP Code:
new min b;
new 
max b
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 08-04-2014 , 18:34   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #359

Quote:
Originally Posted by hleV View Post
There's something weird about Math_Min() and Math_Max() functions.

PHP Code:
/**
 * Sets the given value to min
 * if the value is smaller than the given.
 * 
 * @param value            Value
 * @param min            Min Value used as lower border
 * @return                Correct value not lower than min
 */
stock any:Math_Min(any:valueany:min)
{
    if (
value min) {
        
value min;
    }
    
    return 
value;
}

/**
 * Sets the given value to max
 * if the value is greater than the given.
 * 
 * @param value            Value
 * @param max            Max Value used as upper border
 * @return                Correct value not upper than max
 */
stock any:Math_Max(any:valueany:max)
{    
    if (
value max) {
        
value max;
    }
    
    return 
value;

They don't return the min/max value of the two parameters provided, but rather expects the 1st parameter to be the value and the 2nd the lower/upper border. So if I have an x and an y and want to get the min/max value of them, Math_Min()/Math_Max() may return the wrong value (for instance, Math_Min(16000, 5000) will return 16000).

It should work like min()/max() functions in AMXX (or hell, in C++ even), which compare the two provided parameters and return the lower/upper value.
The functions are supposed to clamp the value and not return the lowest or highest.
The function names and documentation might be a bit confusing tho.
__________________
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
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 08-05-2014 , 06:37   Re: SMLIB 0.11 BETA (over 300 Function Stocks) | updated 15.07.2011
Reply With Quote #360

Just use ternary operators. That's what they are for.
a > b ? a : b

Well shit, powerlord posted the exact same thing.
Virtually all of the stuff in smlib is like this.
If you can't write the functions yourself, you probably should not be using them.
This goes for almost anything. They're there for convenience, but you should always read the include so you know it does exactly what you need. More often, you should read it's source, so you know how it works and if there are any situations i which it won't work right (undefined, unpredictable, or erroneous results).
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:37.


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