Raised This Month: $51 Target: $400
 12% 

Ham_CS_Player_OnTouchingWeapon not exist?


Post New Thread Reply   
 
Thread Tools Display Modes
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 09-16-2016 , 08:20   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #11

And why not simply use Ham_Touch with classname "weaponbox" ?
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-16-2016 , 08:56   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #12

Quote:
Originally Posted by NiHiLaNTh View Post
And why not simply use Ham_Touch with classname "weaponbox" ?
Or better register_touch with weaponbox and player.
Here a way to emulate this event:
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta>

public plugin_init() {
    
register_touch("weaponbox""player""OnPlayerTouchingWeaponbox");
}

public 
OnPlayerTouchingWeaponbox(weaponboxplayer) {
    if (!(
pev(weaponboxpev_flags) & FL_ONGROUND)) {
        return;
    }
    if (!
is_user_alive(player)) {
        return;
    }
    const 
m_bShieldDrawn 2042;
    if (
cs_get_user_vip(player) || GetPlayerFieldBool(playerm_bShieldDrawn)) {
        return;
    }
    
OnPlayerTouchingWeapon(playerweaponbox);
}

public 
OnPlayerTouchingWeapon(playerweaponbox) {
    
client_print(playerprint_chat"!!!");
}

bool:GetPlayerFieldBool(entityIndexpdataOffset) {
    const 
playerUnixDiffInBytes 20;
    const 
intByteSize 4;
    const 
bitsInByte 8;
    new 
value get_pdata_int(entityIndexpdataOffset intByteSizeplayerUnixDiffInBytes intByteSize);
    new 
byteNumber pdataOffset intByteSize;
    new 
byteMask 0xFF << (byteNumber bitsInByte);
    return (
value byteMask) != 0;

__________________

Last edited by PRoSToTeM@; 09-16-2016 at 09:09.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-16-2016 , 09:40   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #13

Quote:
Originally Posted by KliPPy View Post
Just try it, don't question how it works amd what I did there. If it works I'll explain it to you.
Lol, don't act like that. You should explain what you did in the first place. When people understand what they are using and doing, there are less chances of error.

@Craxor, ham allows you to hook virtual functions from a table. View this table as an array, which has an unique entry for each of it's functions. You can adress this entry by it's index, which starts from the base of the class and it's incremented by one with every function.

As an example, here's the virtual table for player class(CBasePlayer):
Spoiler

Here, you can see that the index of OnTouchingWeapon is 87. What Klippy did is basically to find another ham function that has the index of 87. That is not necessary, you could simply do that:
PHP Code:
new Ham:Ham_CS_Player_OnTouchingWeapon 87 
He picked up the function CBasePlayerWeapon:: PrimaryAttack(), which is a member of CBasePlayerWeapon class. You see, both have same index, but from different classes.

I hope you get that. Anyway, I doubt it will work. Why you don't simply hook touch as per usual?
__________________

Last edited by HamletEagle; 09-16-2016 at 09:43.
HamletEagle is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-16-2016 , 11:41   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #14

Quote:
Originally Posted by KliPPy View Post
Use your original code and put the following code somewhere near the top:
PHP Code:
#if AMXX_VERSION_NUM < 183
const Ham:Ham_CS_Player_OnTouchingWeapon Ham_Weapon_PrimaryAttack;
#endif 
this should allow you to use it in lower versions than 1.8.3. Just try it, don't question how it works amd what I did there. If it works I'll explain it to you.
It won't work, because Ham requires the same argcount on Windows. (but I'm not sure about Linux)
__________________

Last edited by PRoSToTeM@; 09-16-2016 at 11:45.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-16-2016 , 12:56   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #15

Quote:
Originally Posted by HamletEagle View Post
Lol, don't act like that. You should explain what you did in the first place. When people understand what they are using and doing, there are less chances of error.
Yes, correct, but it didn't seem like he tried what I proposed and started finding reasons why it wouldn't work (even though what he said wasn't the reason).

Quote:
Originally Posted by HamletEagle View Post
That is not necessary, you could simply do that:
PHP Code:
new Ham:Ham_CS_Player_OnTouchingWeapon 87 
Ham_Weapon_PrimaryAttack's value isn't 87, it depends on hamdata.ini. You can't hook a function by its vtable index, so you have to find another function which has the same index (but for another class obviously) on the game you are running. I don't like that with Ham though, a new module (or new API for ham) that gets rid of some many hardcoded stuff would be really welcome.

Quote:
Originally Posted by PRoSToTeM@ View Post
It won't work, because Ham requires the same argcount on Windows. (but I'm not sure about Linux)
In every post I wrote "try" because I wasn't sure either if it would work. Arkshine already pointed the argcount problem to me. Thanks for mentioning here though.
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-16-2016 , 14:11   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #16

Quote:
Ham_Weapon_PrimaryAttack's value isn't 87, it depends on hamdata.ini. You can't hook a function by its vtable index, so you have to find another function which has the same index (but for another class obviously) on the game you are running. I don't like that with Ham though, a new module (or new API for ham) that gets rid of some many hardcoded stuff would be really welcome.
Forgot that ham is not working in orpheu style, my bad.
__________________

Last edited by HamletEagle; 09-16-2016 at 14:11.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-16-2016 , 17:17   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #17

I'm already use register_touch' my original question was about Ham_CS_Player_OnTouchingWeapon if is integreted in 1.8.3 or i'm doing something wrong with my code, wich arkshine give me the answer, anyway about how ham it's working i will try to read more times the hamlet answer, seems very useful

Sorry i'm still beginner but just by curiosity, where i can find a list with all classes like CBasePlayer ?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-16-2016 , 17:42   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #18

HLSDK and Wiki.
klippy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-16-2016 , 17:44   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #19

holyshit i never know about that link with hlsdk :O , thanks klippty
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-17-2016 , 05:06   Re: Ham_CS_Player_OnTouchingWeapon not exist?
Reply With Quote #20

Quote:
Originally Posted by Craxor View Post
holyshit i never know about that link with hlsdk :O , thanks klippty
Keep in mind that hlsdk has generic code, this means there are no cs specific stuff. Check ReGameDLL project on github for cs source code.
You can also get IDA and decompile cs.so/mp.dll, after you get used with it's output it's easy to find what you need.
__________________
HamletEagle 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 07:50.


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