Raised This Month: $32 Target: $400
 8% 

[HowTo] Properly catch shot event in CS


Post New Thread Reply   
 
Thread Tools Display Modes
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 09-19-2008 , 12:52   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #21

Quote:
Originally Posted by arkshine View Post
Don't forget that it passes the weapon entity index, so to retrieve the player's id, you have to use pev_owner.
Already thought about that. ;) Thanks again!
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
LagParty
Junior Member
Join Date: Jul 2008
Old 10-16-2008 , 15:03   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #22

how can i know if the bullet that was shot hit an alive player or anything else? (im only using awp/scout for this)
__________________
[IMG]http://img153.**************/img153/8005/pacohq7.gif[/IMG][IMG]http://img120.**************/img120/9215/chwlagpartyrh8.png[/IMG][IMG]http://img153.**************/img153/8005/pacohq7.gif[/IMG]
LagParty is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 10-16-2008 , 17:01   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #23

Quote:
Originally Posted by LagParty View Post
how can i know if the bullet that was shot hit an alive player or anything else? (im only using awp/scout for this)
Look at ham_const.inc for Ham_TraceAttack.
danielkza is offline
LagParty
Junior Member
Join Date: Jul 2008
Old 12-21-2008 , 00:52   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #24

Took about 2 months to guess what "this" meant, lol. I'm still a noob with hamsandwich and ham_traceattack returns 5 results with the search engine on the forum (also, the ham_const just gives basic info).

I believe that i need to give the attacked entity instead of the attacker, so i'd need to executeham on every player and compare the attacker id with the "invoker" of the gun fire event. I think there should be another (more efficient) way of doing what i want. I don't need to know the id of the player nor the aim origin or angles, just a true for you_hit_a_player and a false for you_hit_nothing. Maybe fakemeta is enough for the task?

Thanks.
__________________
[IMG]http://img153.**************/img153/8005/pacohq7.gif[/IMG][IMG]http://img120.**************/img120/9215/chwlagpartyrh8.png[/IMG][IMG]http://img153.**************/img153/8005/pacohq7.gif[/IMG]
LagParty is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-21-2008 , 04:13   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #25

Just register Ham_TraceAttack with entity "player", then, when the forward is called, check if idattacker is alive and then if idattacker weapon is a scout/awp.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
LagParty
Junior Member
Join Date: Jul 2008
Old 12-21-2008 , 13:18   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #26

I was just about to ask for more help but then i said to myself "come on, think harder" So i started doing tests until i came up with a solution using the ham_traceattack and the forward for weapon fire.

I found that ham_traceattack gets called first, so i store the player id on a value and then on the other forward i check if the id is the same or not. I'll post the code for anyone that might find it helpful.

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new g_fwidg_guns_eventids_bitsum
new player_shots[33], tmpattacker

new const g_guns_events[][] = {
    
"events/awp.sc",
    
"events/scout.sc"
}
public 
plugin_precache() {
    
g_fwid register_forward(FM_PrecacheEvent,"fwPrecacheEvent",1)
}
public 
fwPrecacheEvent(type, const name[]) {
    for (new 
0sizeof g_guns_events; ++i) {
        if (
equal(g_guns_events[i], name)) {
            
g_guns_eventids_bitsum |= (1<<get_orig_retval())
            return 
FMRES_HANDLED
        
}
    }
    return 
FMRES_IGNORED
}
public 
plugin_init() {
    
register_plugin("This is","a","Test")
    
    
unregister_forward(FM_PrecacheEventg_fwid1)
    
register_forward(FM_PlaybackEvent"fwPlaybackEvent")
    
    
RegisterHam(Ham_TraceAttack,"player","fwd_Ham_TraceAttack")
    
register_event("DeathMsg""player_dies","a")
}
public 
fwd_Ham_TraceAttack(this,idattacker,Float:damage,Float:direction[3],traceresult,damagebits) {
    if(
is_user_alive(idattacker)) {
        static 
wpn wpn get_user_weapon(idattacker)
        if(
wpn==CSW_AWP||wpn==CSW_SCOUT) {
            
player_shots[idattacker] ++
            
tmpattacker idattacker
            
//Testing pruposes
            
client_print(0,print_chat,"HAM: id = %d score = %d",idattacker,player_shots[idattacker])
        }
    }
}
public 
fwPlaybackEvent(flagsinvokereventid) {
    if (!(
g_guns_eventids_bitsum & (1<<eventid))||!(is_user_alive(invoker))) {
        return 
FMRES_IGNORED
    
}
    if(
invoker!=tmpattacker) {
        
player_shots[invoker] = 0
        
//Testtesttest
        
client_print(0,print_chat,"id = %d score %d",invoker,player_shots[invoker])
    }
    
tmpattacker 0
    
return FMRES_HANDLED
}
public 
player_dies() {
    static 
player player read_data(2)
    if(
is_user_connected(player)) {
        
player_shots[player] = 0
    
}
}
public 
client_disconnect(id) {
    
player_shots[id] = 0

The fun part comes next, because if the player gets a score of 2 or more points, i'll play a "impressive" quake3 sound and show the icon over the player's head.

Thanks conorr and danielkza (and ven of course for making the base).
__________________
[IMG]http://img153.**************/img153/8005/pacohq7.gif[/IMG][IMG]http://img120.**************/img120/9215/chwlagpartyrh8.png[/IMG][IMG]http://img153.**************/img153/8005/pacohq7.gif[/IMG]
LagParty is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 06-11-2010 , 10:55   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #27

This is extremely useful. Bump for the great justice.
Seta00 is offline
shuttle_wave
Veteran Member
Join Date: Apr 2009
Location: New Zealand
Old 06-13-2010 , 07:13   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #28

GJ
__________________
JailBreak Mod with Plugin API ( 90% ) Public
shuttle_wave is offline
Old 06-28-2010, 23:55
qt0416
This message has been deleted by YamiKaitou. Reason: spambot
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 08-10-2010 , 01:28   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #29

Is this method still the best way?
Doc-Holiday is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-10-2010 , 05:25   Re: [HowTo] Properly catch shot event in CS
Reply With Quote #30

All is depending your need, but it you need to catch each shot and nothing else, yes.
__________________
Arkshine is offline
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 18:44.


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