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

Using Clamp Function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RAW_192
Senior Member
Join Date: Feb 2017
Old 08-04-2017 , 07:13   Using Clamp Function
Reply With Quote #1

Like in jctf when users use a adrenaline it shows a hud

x of 100 adrenaline used

where x is the amount of adrenaline left ..

And as soon as x=0 the adrenaline ends

Here's the code

PHP Code:
public player_adrenalineDrain(id)
{
    
id += TASK_ADRENALINE

    
if(!g_bAlive[id] || !g_iAdrenalineUse[id] || !(TEAM_RED <= g_iTeam[id] <= TEAM_BLUE))
    {
        
g_iAdrenaline[id] = 0
        
return
    }

    if(
g_iAdrenaline[id] > 0)
    {
        new 
iDrain = (player_hasFlag(id) ? 1)

        
g_iAdrenaline[id] = clamp(g_iAdrenaline[id] - (g_iAdrenalineUse[id] == ADRENALINE_REGENERATE iDrain iDrain 2), 0100)

        switch(
g_iAdrenalineUse[id])
        {
            case 
ADRENALINE_REGENERATE:
            {
                new 
iHealth get_user_health(id)

                if(
iHealth < (g_iMaxHealth[id] + REGENERATE_EXTRAHP))
                    
set_user_health(idiHealth 1)

                else
                {
                    new 
CsArmorType:ArmorType
                    
new iArmor cs_get_user_armor(idArmorType)

                    if(
iArmor g_iMaxArmor[id])
                        
cs_set_user_armor(idiArmor 1ArmorType)
                }

                
player_healingEffect(id)
            }
        }

        
task_set(0.25"player_adrenalineDrain"id TASK_ADRENALINE)
    }
    else
    {
        new 
iUsed g_iAdrenalineUse[id]

        
g_iAdrenaline[id] = 0
        g_iAdrenalineUse
[id] = /* to allow player_updateSpeed() to work correctly */

        
switch(iUsed)
        {
            case 
ADRENALINE_SPEED:
            {
                
player_updateSpeed(id)

                
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
                
write_byte(TE_KILLBEAM)
                
write_short(id)
                
message_end()
            }

            case 
ADRENALINE_BERSERKADRENALINE_INVISIBILITYplayer_updateRender(id)
        }
    }

    
player_hudAdrenaline(id)

I want to use a same drain function ..

For example if i buy a power for 100 money

then it would show a hud with .. of 100 money left

and as its 0 it would end ...


Any helps please ?
RAW_192 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-04-2017 , 09:48   Re: Using Clamp Function
Reply With Quote #2

So, what is you question about using clamp()?
__________________
fysiks is offline
RAW_192
Senior Member
Join Date: Feb 2017
Old 08-04-2017 , 10:34   Re: Using Clamp Function
Reply With Quote #3

Yeah .. I mean can this thing can be done by any other way too ? or just clamp?

If by clamp then how ?
RAW_192 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-04-2017 , 20:23   Re: Using Clamp Function
Reply With Quote #4

clamp() is a straightforward function. It simply coerces a value to be within the provided range. If clamp() works for your situation then use it, if it doesn't work for you then don't use it.

Other than that I have no clue what you are talking about.
__________________
fysiks 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 06:16.


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