Raised This Month: $ Target: $400
 0% 

Executing code right before a bullet is shot.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 03-05-2005 , 16:38   Executing code right before a bullet is shot.
Reply With Quote #1

Is there a way I can *launch* a function right when a user clicks their mouse button, before the recoil and bullets launch?
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-05-2005 , 17:37  
Reply With Quote #2

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 }
xeroblood is offline
Send a message via MSN to xeroblood
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 03-05-2005 , 21:49  
Reply With Quote #3

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 is offline
Send a message via AIM to TotalNoobScripter
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 03-07-2005 , 14:59  
Reply With Quote #4

bumpzorz
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-07-2005 , 16:27  
Reply With Quote #5

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-07-2005 , 16:41  
Reply With Quote #6

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!!

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..
xeroblood is offline
Send a message via MSN to xeroblood
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 03-07-2005 , 16:50  
Reply With Quote #7

so it will get the origin of where a bullet hit when it was fired? (That is assuming this is called before recoil...)
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-07-2005 , 16:57  
Reply With Quote #8

Well, ya, and more.. but I don't know if it is before recoil or not..
xeroblood is offline
Send a message via MSN to xeroblood
TotalNoobScripter
Senior Member
Join Date: Aug 2004
Old 03-07-2005 , 17:25  
Reply With Quote #9

well if it was after recoil, it would get the origin of the next bullet hit :p
TotalNoobScripter is offline
Send a message via AIM to TotalNoobScripter
BioHazardousWaste
Senior Member
Join Date: Apr 2005
Location: Ontario, Canada =)
Old 04-25-2005 , 23:00  
Reply With Quote #10

talk about bumping an old post.... sorry, but why is everything id - 1?
__________________
"What then is truth? Truths are illusions which we have forgotten are illusions - they are metaphors that have become worn out... this (truth) is the duty to lie according to a fixed convention.

-Friedrich Nietzsche
BioHazardousWaste is offline
Send a message via MSN to BioHazardousWaste
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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