AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using Clamp Function (https://forums.alliedmods.net/showthread.php?t=300060)

RAW_192 08-04-2017 07:13

Using Clamp Function
 
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 ?

fysiks 08-04-2017 09:48

Re: Using Clamp Function
 
So, what is you question about using clamp()?

RAW_192 08-04-2017 10:34

Re: Using Clamp Function
 
Yeah .. I mean can this thing can be done by any other way too ? or just clamp?

If by clamp then how ?

fysiks 08-04-2017 20:23

Re: Using Clamp Function
 
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.


All times are GMT -4. The time now is 23:08.

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