AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Executing code right before a bullet is shot. (https://forums.alliedmods.net/showthread.php?t=10944)

TotalNoobScripter 03-05-2005 16:38

Executing code right before a bullet is shot.
 
Is there a way I can *launch* a function right when a user clicks their mouse button, before the recoil and bullets launch?

xeroblood 03-05-2005 17:37

I haven't tested this but you could try:

Code:
public client_PreThink( id ) {     if( get_user_button(id) & IN_ATTACK )     {         // do stuff here..     }     return PLUGIN_CONTINUE }

TotalNoobScripter 03-05-2005 21:49

couldnt prethink be executed many times before a bullet is launched?
or does prethink execute the same speed as how fast the bullets fire from the gun at full-auto?

If it was faster than the full-auto rate, then my code will be acting as if someone shot 2 bullets instead of 1.

TotalNoobScripter 03-07-2005 14:59

bumpzorz

XxAvalanchexX 03-07-2005 16:27

That if statement will be called many many times during the time he is shooting, much faster than the rate at which the bullets are being shot. It could also be called while he is reloading or drawing his weapon.

xeroblood 03-07-2005 16:41

Quote:

Originally Posted by TotalNoobScripter
couldnt prethink be executed many times before a bullet is launched?
or does prethink execute the same speed as how fast the bullets fire from the gun at full-auto?

If it was faster than the full-auto rate, then my code will be acting as if someone shot 2 bullets instead of 1.

Didn't you at least try what I mentioned?? Maybe it will work!! :P

If it doesnt work, as Avalanche stated, try this:

Code:
#define MAX_PLAYERS 32 // Tracks players Shots-Fired: [0]=WeaponID, [1]=Ammo new g_nCurWeapon[MAX_PLAYERS][2] public plugin_init() {     register_event( "CurWeapon", "Event_ShotFired",  "b" ) } public Event_ShotFired( id ) {     // Players current weapon data..     new weaponID = read_data( 2 )     new wAmmo = read_data( 3 )     if( g_nCurWeapon[id-1][0] != weaponID ) // User Changed Weapons..     {         g_nCurWeapon[id-1][0] = weaponID         g_nCurWeapon[id-1][1] = wAmmo         return PLUGIN_CONTINUE     }     if( g_nCurWeapon[id-1][1] < wAmmo ) // User Reloaded..     {         g_nCurWeapon[id-1][1] = wAmmo         return PLUGIN_CONTINUE     }     if( g_nCurWeapon[id-1][1] == wAmmo ) // User did something else, but didn't shoot..         return PLUGIN_CONTINUE         // This far means user shot his/her gun..     // Save new weapon data..     g_nCurWeapon[id-1][1] = wAmmo     g_nCurWeapon[id-1][0] = weaponID     // Now you can do stuff, like:     // Get the origin of weapon hit-point     new nPoint[3]     get_user_origin( id, nPoint, 3 )     // blah blah blah...     return PLUGIN_CONTINUE }


I used that method in my Proximity Mines Plugin...

Or, even still, you could simply Flag the First method I mentioned (with client_prethink) and essentially track how many times it is actually called, then just use some simple logic to execute code on the first occurence only..

TotalNoobScripter 03-07-2005 16:50

so it will get the origin of where a bullet hit when it was fired? (That is assuming this is called before recoil...)

xeroblood 03-07-2005 16:57

Well, ya, and more.. but I don't know if it is before recoil or not..

TotalNoobScripter 03-07-2005 17:25

well if it was after recoil, it would get the origin of the next bullet hit :p

BioHazardousWaste 04-25-2005 23:00

talk about bumping an old post.... sorry, but why is everything id - 1?


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

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