AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Execute function for each click (https://forums.alliedmods.net/showthread.php?t=153219)

kotinha 03-20-2011 10:23

Execute function for each click
 
Hey...
I have this in my code:
PHP Code:

public client_PreThink(id)
{
        if(
get_user_button(id) & IN_ATTACK)
        {
            
throw_kunai(id1)
        }


In game I press attack button and it works perfectly but while I'm pressing mouse1 it repeats the function throw_kunai and throw kunais like a machine gun...
How can I throw ONE kunai for each click?

EDIT: I've noticed now this isn't Scripting help -.- Move this please, and sorry ...

schmurgel1983 03-20-2011 13:03

Re: Execute function for each click
 
try it with pistol, they are not machine guns.

EDIT: and hook Ham_Weapon_PrimaryAttack

kotinha 03-20-2011 13:48

Re: Execute function for each click
 
With pistols I have to put infinite ammo and unblock pickup pistols... Since I'm a new at this it's better to make it simple :)
I tought that there was a function (or something else...) that would block it from repeat the function, if there isn't I'll just delay the process...

wrecked_ 03-20-2011 13:57

Re: Execute function for each click
 
I'd recommend using FM_CmdStart instead of PreThink, but that's off-topic and I won't go into that.

However, you should use this:
Code:
if( ( get_user_buttons( id ) & IN_ATTACK ) && !( pev( id, pev_oldbuttons ) & IN_ATTACK ) ) {     throw_kunai( id, 1 ) }

ConnorMcLeod 03-20-2011 14:10

Re: Execute function for each click
 
2 Attachment(s)
Why do you recommand CmdStart ?

For unlimited ammo you can use method of one of following plugins :

wrecked_ 03-20-2011 14:46

Re: Execute function for each click
 
I recommend it because using PreThink to hook when a player begins using IN_ATTACK is very inefficient.

ConnorMcLeod 03-20-2011 15:14

Re: Execute function for each click
 
PostThink could be more efficient than CmdStart because it saves 1 native, and also it's a multiforward, else can do the same in PreThink POST (client_impulse is the engine CmdStart multiforward but it seems to be bugged) :

PHP Code:

#define XO_PLAYER 5
#define m_afButtonPressed 246

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
}

public 
client_PostThink(id)
{
    if( 
is_user_alive(id) && get_pdata_int(idm_afButtonPressedXO_PLAYER) & IN_ATTACK )
    {
    }




All times are GMT -4. The time now is 14:40.

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