AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get player hold key time in sec. (https://forums.alliedmods.net/showthread.php?t=92670)

One 05-18-2009 05:34

get player hold key time in sec.
 
tittle & how long player dont press the key?!

One 05-21-2009 18:41

Re: get player hold key time in sec.
 
mini bump :( sry but its important.

almcaeobtac 05-21-2009 19:00

Re: get player hold key time in sec.
 
On a game frame, GetClientButtons, then if a certain one is held down, start a very small timer, and keep doing that til it stops, then return the time.

One 05-21-2009 19:01

Re: get player hold key time in sec.
 
Quote:

Originally Posted by almcaeobtac (Post 831999)
On a game frame, GetClientButtons, then if a certain one is held down, start a very small timer, and keep doing that til it stops, then return the time.

omgggg........ ok. let try :D

ot_207 05-21-2009 19:07

Re: get player hold key time in sec.
 
Quote:

Originally Posted by almcaeobtac (Post 831999)
On a game frame, GetClientButtons, then if a certain one is held down, start a very small timer, and keep doing that til it stops, then return the time.

Better on cmdstart ;).

PHP Code:

new Float:gametime_when_press[33] = {0.0, ...}
// plugin_init
register_forward(FM_CmdStart"fw_cmdstart")

public 
fw_cmdstart(iduc_handleseed)
{
 if (!
is_user_alive(id))
 {
  
gametime_when_press[id] = 0.0
  
return FMRES_IGNORED
 
}
 
 if (
gametime_when_press[id] != 0.0)
 {
   if (!(
get_uc(uc_handleUC_Buttons) & IN_USE))
   {
     
gametime_when_press[id] = 0.0
     
return FMRES_IGNORED
   
}
   if (
get_gametime() >= gametime_when_press[id] + 1.0)
   {
     
//  WOHOO
   
}
 }
 else
 {
   if (
get_uc(uc_handleUC_Buttons) & IN_USE))
   {
     
gametime_when_press[id] = get_gametime()
   }
 }
 
 return 
FMRES_IGNORED


I wrote it here so it is not tested!

ConnorMcLeod 05-21-2009 19:08

Re: get player hold key time in sec.
 
Witch buttons ?
All buttons ?
One specific button ?

Basically you hook FM_CmdStart.
For a specific button :

For first press : get_uc(uc, UC_Button) & IN_YOURBUTTON && !(entity_get_int(id, EV_INT_oldbutons) & IN_YOURBUTTON)
At this time store get_gametime()

Last press : !(get_uc(uc, UC_Button) & IN_YOURBUTTON) && entity_get_int(id, EV_INT_oldbutons) & IN_YOURBUTTON
Then do get_gametime() - storetime.

ot_207 05-21-2009 19:09

Re: get player hold key time in sec.
 
Quote:

Originally Posted by ConnorMcLeod (Post 832004)
Witch buttons ?
All buttons ?
One specific button ?

I think he wants a specific example.
Edit: ...

One 05-21-2009 19:18

Re: get player hold key time in sec.
 
nop i wannt IN_FORWARD
IN_BACK

i wannt to add sound

for example :

if player hold the forward key >= 1 && <= 10. play the engine sound 1.

if hold the forward >= 10.1 && <= 20, play the engine sound 2.

like a real engine sound.
but when the player less the key for 0.00001 sec. & press this again the sound willbe played again.

omg its realy complicated :((

ot_207 05-21-2009 19:21

Re: get player hold key time in sec.
 
Quote:

Originally Posted by One (Post 832010)
nop i wannt IN_FORWARD
IN_BACK

i wannt to add sound

for example :

if player hold the forward key >= 1 && <= 10. play the engine sound 1.

if hold the forward >= 10.1 && <= 20, play the engine sound 2.

like a real engine sound.
but when the player less the key for 0.00001 sec. & press this again the sound willbe played again.

omg its realy complicated :((

1.Replace in what I've posted IN_USE with IN_FORWARD. Normally it should work! I told you, I wrote it in a hurry without testing it! So you need to make the proper corrections!
2. For >= 1 && <= 10 then you need to change the conditions!

One 05-21-2009 19:23

Re: get player hold key time in sec.
 
sure i know how to change the key. i have another problem.

PHP Code:

speed vector_length(velocity)
        
        new 
Float:real_drehzahl
        
if( speed == 0.0)
        {
            
//emit_sound( 0 ,CHAN_ITEM, "rally/drehzahl.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH);
            
client_cmd(0,"spk rally/drehzahl")
            
gang 0
            drehzahl 
1000.0 
            
if(g_y >= 5.0)
            {
                
real_drehzahl 1000.0 g_y
            
}
            else
            {
                
real_drehzahl 1000.0 g_y
            
}
        }
        if( 
speed >= 0.1 && speed <= 100.0)
        {
            
gang 1
            drehzahl 
1000.0 
            
            
if(speed >= 1.0 && speed <= 10.0)
            {
                
real_drehzahl drehzahl 130
            
}
            else if(
speed >=11.0 && speed <= 20.0)
            {
                
real_drehzahl drehzahl 260
            
}
            else if(
speed >=21.0 && speed <= 30.0)
            {
                
real_drehzahl drehzahl 308
            
}
            else if(
speed >=31.0 && speed <= 40.0)
            {
                
real_drehzahl drehzahl 405
            
}
            else if(
speed >=41.0 && speed <= 50.0)
            {
                
real_drehzahl drehzahl 540
            
}
            else if(
speed >=51.0 && speed <= 60.0)
            {
                
real_drehzahl drehzahl 680
            
}
            else if(
speed >=61.0 && speed <= 70.0)
            {
                
real_drehzahl drehzahl 701
            
}
            else if(
speed >=71.0 && speed <= 80.0)
            {
                
real_drehzahl drehzahl 803
            
}
            else if(
speed >=81.0 && speed <= 90.0)
            {
                
real_drehzahl drehzahl 909
            
}
            else if(
speed >=91.0 && speed <= 100.0)
            {
                
real_drehzahl drehzahl 1050
            
}
        }
        else if( 
speed >= 101.0 && speed <= 200.0)
        {
            
gang 2
            drehzahl 
2000.0
            
if(g_y >= 5.0)
            {
                
real_drehzahl 2000.0 g_y
            
}
            else
            {
                
real_drehzahl 2000.0 g_y
            
}
            if(
speed >= 101.0 && speed <= 100.0)
            {
                
real_drehzahl drehzahl 130
            
}
            else if(
speed >=110.0 && speed <= 120.0)
            {
                
real_drehzahl drehzahl 260
            
}
            else if(
speed >=121.0 && speed <= 130.0)
            {
                
real_drehzahl drehzahl 308
            
}
            else if(
speed >=131.0 && speed <= 140.0)
            {
                
real_drehzahl drehzahl 405
            
}
            else if(
speed >=141.0 && speed <= 150.0)
            {
                
real_drehzahl drehzahl 540
            
}
            else if(
speed >=151.0 && speed <= 160.0)
            {
                
real_drehzahl drehzahl 680
            
}
            else if(
speed >=161.0 && speed <= 170.0)
            {
                
real_drehzahl drehzahl 701
            
}
            else if(
speed >=171.0 && speed <= 180.0)
            {
                
real_drehzahl drehzahl 803
            
}
            else if(
speed >=181.0 && speed <= 190.0)
            {
                
real_drehzahl drehzahl 909
            
}
            else if(
speed >=191.0 && speed <= 200.0)
            {
                
real_drehzahl drehzahl 1050
            
}
        }
        else if( 
speed >= 201.0 && speed <= 300.0)
        {
            
gang 3
            drehzahl 
3000.0
            
if(g_y >= 5.0)
            {
                
real_drehzahl 3000.0 g_y
            
}
            else
            {
                
real_drehzahl 3000.0 g_y
            
}
            if(
speed >= 201.0 && speed <= 210.0)
            {
                
real_drehzahl drehzahl 130
            
}
            else if(
speed >=211.0 && speed <= 220.0)
            {
                
real_drehzahl drehzahl 260
            
}
            else if(
speed >=221.0 && speed <= 230.0)
            {
                
real_drehzahl drehzahl 308
            
}
            else if(
speed >=231.0 && speed <= 240.0)
            {
                
real_drehzahl drehzahl 405
            
}
            else if(
speed >=241.0 && speed <= 250.0)
            {
                
real_drehzahl drehzahl 540
            
}
            else if(
speed >=251.0 && speed <= 260.0)
            {
                
real_drehzahl drehzahl 680
            
}
            else if(
speed >=261.0 && speed <= 270.0)
            {
                
real_drehzahl drehzahl 701
            
}
            else if(
speed >=271.0 && speed <= 280.0)
            {
                
real_drehzahl drehzahl 803
            
}
            else if(
speed >=281.0 && speed <= 290.0)
            {
                
real_drehzahl drehzahl 909
            
}
            else if(
speed >=291.0 && speed <= 300.0)
            {
                
real_drehzahl drehzahl 1050
            
}
        }
        else if( 
speed >= 301.0 && speed <= 400.0)
        {
            
gang 4
            drehzahl 
4000.0
            
if(g_y >= 5.0)
            {
                
real_drehzahl 4000.0 g_y
            
}
            else
            {
                
real_drehzahl 4000.0 g_y
            
}
            if(
speed >= 301.0 && speed <= 310.0)
            {
                
real_drehzahl drehzahl 130
            
}
            else if(
speed >=311.0 && speed <= 320.0)
            {
                
real_drehzahl drehzahl 260
            
}
            else if(
speed >=321.0 && speed <= 330.0)
            {
                
real_drehzahl drehzahl 308
            
}
            else if(
speed >=331.0 && speed <= 340.0)
            {
                
real_drehzahl drehzahl 405
            
}
            else if(
speed >=341.0 && speed <= 350.0)
            {
                
real_drehzahl drehzahl 540
            
}
            else if(
speed >=351.0 && speed <= 360.0)
            {
                
real_drehzahl drehzahl 680
            
}
            else if(
speed >=361.0 && speed <= 370.0)
            {
                
real_drehzahl drehzahl 701
            
}
            else if(
speed >=371.0 && speed <= 380.0)
            {
                
real_drehzahl drehzahl 803
            
}
            else if(
speed >=381.0 && speed <= 390.0)
            {
                
real_drehzahl drehzahl 909
            
}
            else if(
speed >=391.0 && speed <= 400.0)
            {
                
real_drehzahl drehzahl 1050
            
}
        }
        else if( 
speed >= 401.0 && speed <= 600.0)
        {
            
gang 5
            drehzahl 
5000.0
            
if(g_y >= 5.0)
            {
                
real_drehzahl 5000.0 g_y
            
}
            else
            {
                
real_drehzahl 5000.0 g_y
            
}
            if(
speed >= 401.0 && speed <= 420.0)
            {
                
real_drehzahl drehzahl 130
            
}
            else if(
speed >=421.0 && speed <= 440.0)
            {
                
real_drehzahl drehzahl 260
            
}
            else if(
speed >=441.0 && speed <= 460.0)
            {
                
real_drehzahl drehzahl 308
            
}
            else if(
speed >=461.0 && speed <= 480.0)
            {
                
real_drehzahl drehzahl 405
            
}
            else if(
speed >=481.0 && speed <= 500.0)
            {
                
real_drehzahl drehzahl 540
            
}
            else if(
speed >=501.0 && speed <= 520.0)
            {
                
real_drehzahl drehzahl 680
            
}
            else if(
speed >=521.0 && speed <= 540.0)
            {
                
real_drehzahl drehzahl 701
            
}
            else if(
speed >=541.0 && speed <= 560.0)
            {
                
real_drehzahl drehzahl 803
            
}
            else if(
speed >=561.0 && speed <= 480.0)
            {
                
real_drehzahl drehzahl 909
            
}
            else if(
speed >=581.0 && speed <= 600.0)
            {
                
real_drehzahl drehzahl 1050
            
}
        }
        else if( 
speed >= 601.0 )
        {
            
gang 6
            drehzahl 
6000.0
            
if(g_y >= 5.0)
            {
                
real_drehzahl 6000.0 g_y
            
}
            else
            {
                
real_drehzahl 6000.0 g_y
            
}
            if(
speed >= 601.0 && speed <= 620.0)
            {
                
real_drehzahl drehzahl 130
            
}
            else if(
speed >=621.0 && speed <= 640.0)
            {
                
real_drehzahl drehzahl 260
            
}
            else if(
speed >=641.0 && speed <= 660.0)
            {
                
real_drehzahl drehzahl 308
            
}
            else if(
speed >=661.0 && speed <= 680.0)
            {
                
real_drehzahl drehzahl 405
            
}
            else if(
speed >=681.0 && speed <= 700.0)
            {
                
real_drehzahl drehzahl 540
            
}
            else if(
speed >=701.0 && speed <= 720.0)
            {
                
real_drehzahl drehzahl 680
            
}
            else if(
speed >=721.0 && speed <= 740.0)
            {
                
real_drehzahl drehzahl 701
            
}
            else if(
speed >=741.0 && speed <= 760.0)
            {
                
real_drehzahl drehzahl 803
            
}
            else if(
speed >=761.0 && speed <= 780.0)
            {
                
real_drehzahl drehzahl 909
            
}
            else if(
speed >=781.0 && speed <= 800.0)
            {
                
real_drehzahl drehzahl 1050
            
}
            else if(
speed >= 801)
            {
                
real_drehzahl drehzahl 1203
            
}
            
            
        }
        
set_hudmessage(255255255, -1.00.700.0FREQ0.010.0)
        
speed speed 5.5
        ShowSyncHudMsg
(iSyncHud"%2.1f KMH^n%d^n %3.1f DREHZAHL"speedgang,real_drehzahl)
        
set_user_health(ifloatroundspeed ) + 1)
        
        
set_user_armor(igang); 
    }


the sound must be changed every sec. / by every speed up & in my code by every rehzahl up.


All times are GMT -4. The time now is 01:29.

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