Raised This Month: $ Target: $400
 0% 

Using Clamp Function


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 10:01.


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