AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Shot event (Method) (https://forums.alliedmods.net/showthread.php?t=221873)

^SmileY 07-27-2013 10:13

Shot event (Method)
 
Hi all, i know if was this tutorial http://forums.alliedmods.net/showthread.php?t=54887
Writed by VEN.

But i see in old plugin a way to detect in other way, its counting bullets in weapon of a player.

Like this: https://forums.alliedmods.net/showthread.php?t=21342

Basically this code:

PHP Code:

#include <amxmodx>

new g_iLastWeap[33];
new 
g_iLastAmmo[33];

new 
g_iShots[33];

public 
plugin_init()
{
    
register_plugin("Fired",AMXX_VERSION_STR,"Amxx Dev Team");

    
register_event("CurWeapon","ev_CurWeapon","be","1=1","3>0");
}

public 
ev_CurWeapon(id)
{

    new 
iWeapon     read_data(2);
    new 
iAmmo     read_data(3);

    if(!
g_iLastWeap[id]) g_iLastWeap[id] = iWeapon;

    if((
g_iLastAmmo[id] > iAmmo) && (g_iLastWeap[id] == iWeapon)) g_iShots[id]++;
    
    
g_iLastAmmo[id] = iAmmo;
    
g_iLastWeap[id] = iWeapon;

    
client_print(id,print_chat,"* Shots: %d (Ammo remainder: %d) (Last Weapon: #%d)",g_iShots[id],g_iLastAmmo[id],g_iLastWeap[id]);


It is safe to used and correctly count shots fired?

EDIT: In my tests is not counting last bullet shot, Any suggestion?

Thanks.

Black Rose 07-27-2013 11:01

Re: Shot event (Method)
 
What are you trying to do?
Are you using X ammount of bullets in clip to trigger event or are you just retrieving the current bullets in clip?
You cant wrap your question in another question. You may be missing out on a good answer.

^SmileY 07-27-2013 11:30

Re: Shot event (Method)
 
Quote:

Originally Posted by Black Rose (Post 1999897)
What are you trying to do?
Are you using X ammount of bullets in clip to trigger event or are you just retrieving the current bullets in clip?
You cant wrap your question in another question. You may be missing out on a good answer.

I tried to count shots based on CurWeapon event and clips, but is not counting last shot.
I think its the 3rd paramter, used in register_event.

Black Rose 07-27-2013 11:51

Re: Shot event (Method)
 
You obviously misunderstood me. So you will get the answer you asked for, not the one you may need.
"3>0" is wrong. Parameter 3 is clip ammo. Just remove it and it will count the last shot.

Here you can read information about game events
http://wiki.amxmodx.org/Half-Life_1_...ents#CurWeapon

^SmileY 07-27-2013 12:36

Re: Shot event (Method)
 
Quote:

Originally Posted by Black Rose (Post 1999923)
You obviously misunderstood me. So you will get the answer you asked for, not the one you may need.
"3>0" is wrong. Parameter 3 is clip ammo. Just remove it and it will count the last shot.

Here you can read information about game events
http://wiki.amxmodx.org/Half-Life_1_...ents#CurWeapon

It is adding a one shot without really shot, i think its better add a 3!-1 for count zero.

:)

ConnorMcLeod 07-27-2013 18:55

Re: Shot event (Method)
 
VEN's method is ok.
You can shorten it like this : http://forums.alliedmods.net/showthr...05#post1725505

^SmileY 07-28-2013 00:19

Re: Shot event (Method)
 
Quote:

Originally Posted by ConnorMcLeod (Post 2000186)
VEN's method is ok.
You can shorten it like this : http://forums.alliedmods.net/showthr...05#post1725505

Thanks, but the given code from my first post its working, it only use the 3rd paramter with 3!-1

:)

ConnorMcLeod 07-28-2013 02:15

Re: Shot event (Method)
 
But you have more code to proceed in callback.
With VEN's method, you don't need to call any native in order to filter shots.

Difference is trivial, but there is still some ;)

^SmileY 07-28-2013 10:45

Re: Shot event (Method)
 
Quote:

Originally Posted by ConnorMcLeod (Post 2000397)
But you have more code to proceed in callback.
With VEN's method, you don't need to call any native in order to filter shots.

Difference is trivial, but there is still some ;)

Thanks for info, with this code when i scope a AWP with zoom, the curweapon its being called, because the 3rd paramter counting zero.

If i change to "3 > 0" it not count last shot (Ex. if i fired 30 bullets its only counting 29)

Its possible to resolve this small problem to use 0 ?
(It That would solve the problem of aim scope from some weapons)

ConnorMcLeod 07-28-2013 11:17

Re: Shot event (Method)
 
Should check if m_iClip != m_iClientClip but again it would add 2 native calls.

Edit :

Or change :

(g_iLastAmmo[id] > iAmmo

to

(g_iLastAmmo[id] >= iAmmo


All times are GMT -4. The time now is 15:52.

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