AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How do I determine when a bullet is fired? (https://forums.alliedmods.net/showthread.php?t=8906)

Geesu 12-30-2004 16:47

How do I determine when a bullet is fired?
 
All I want to know is when someone presses the trigger. Now I could catch CurWeapon, except that is called while changing weapons.

I could also catch IN_ATTACK but that could register when someone is pressing attack but bullets aren't fired (i.e. while reloading).

Is there any for-sure way of determining this?

syphilis 12-30-2004 16:51

Maybe try catching IN_ATTACK in client_PreThink(), saveing the client's clip ammount to a variable, and then in client_PostThink() check if the client's clip is 1 less than the variable from earlier.

That's just speculation, hopefully it'll give you some more ideas for solving the problem.

Geesu 12-30-2004 19:18

brilliant :) That'll work perfect, now I need to determine how to get the user's clip from an amxmodx module :P

jtp10181 12-30-2004 21:24

its easier to just use CurWeapon and save the clip ammount in a global variable, if the clip ammount is less than the last time it got checked they just fired a bullet.

Code:

new lastclip[33]
new lastweap[33]

public curweapon(id)
{
        new wpnid = read_data(2)
        new clip = read_data(3)

        if (lastweap[id] != wpnid){
                //Changed weapons
        }
        else if ( lastclip[id] > clip ) {
                if (wpnid != CSW_C4 && wpnid != CSW_HEGRENADE && wpnid != CSW_FLASHBANG && wpnid != CSW_SMOKEGRENADE && wpnid != CSW_KNIFE) {
                        //Fired a Bullet
                }
        }

        lastclip[id] = clip
        lastweap[id] = wpnid
}


Geesu 12-30-2004 22:08

Yea it's just not so easy to get that data in an amxx module. At least I'm not very good at it :/

Timmi the savage 12-31-2004 08:16

hmmm.. maybe this isnt the best way but...

Code:

new oldclip[33]
new weapon[33]

public spent_ammo(id)  {
  new clip
  new weapon
  new reservetemp
  get_user_ammo(id, weapon, clip, reservetemp)
  if (weapon[id] != weapon) {
    weapon[id] = weapon
    return PLUGIN_CONTINUE
    }
  if (oldclip[id] == clip) return PLUGIN_CONTINUE
  if (oldclip[id] != clip) {
  oldclip[id] = clip
  do_what_ever_you_want_to_do_here()
  }
  return PLUGIN_CONTINUE
}

You could set this as a task or link it to | Damage |
or even make it return if ammo changed or not.

Perhaps this is what you mean??

Timmi the savage 12-31-2004 08:42

Also if you make either of these ways to run as a task....

Put

if ( read_data(2) ) {

first thing after the function then it will only execute if someone gets hurt.

And even link it from Damage event.

Or both ... o.O

Geesu 12-31-2004 12:19

thanks but you don't have read_data in an amxx module... I think I'm good now, but I don't think I"ll be able to do this how I want to. B/c I'll have to compare gpGlobals->time and I don't know how great of an option that is.

(I need to execute code in FN_Traceline based on if the user is firing)

jtp10181 12-31-2004 14:38

Quote:

Originally Posted by Geesu
Yea it's just not so easy to get that data in an amxx module. At least I'm not very good at it :/

you are trying to write a module?

XxAvalanchexX 12-31-2004 15:46

Quote:

Originally Posted by jtp10181
you are trying to write a module?

Quote:

Originally Posted by Geesu
brilliant :) That'll work perfect, now I need to determine how to get the user's clip from an amxmodx module :P

Quote:

Originally Posted by Geesu
Yea it's just not so easy to get that data in an amxx module. At least I'm not very good at it :/

Quote:

Originally Posted by Geesu
thanks but you don't have read_data in an amxx module... I think I'm good now, but I don't think I"ll be able to do this how I want to. B/c I'll have to compare gpGlobals->time and I don't know how great of an option that is.

(I need to execute code in FN_Traceline based on if the user is firing)



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

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