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

[TS] Client damage modification for bots


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Infest
Member
Join Date: Mar 2005
Old 09-16-2016 , 20:03   [TS] Client damage modification for bots
Reply With Quote #1

I have been struggling to find a method to modify the damage bots take.

PHP Code:
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage")
public 
hook_TakeDamage(VictimUselessAttackerFloat:damagedamagebits
You can modify damage given to players with this event, although not damage given to bots

PHP Code:
register_message(50"damage_function")
public 
damage_function(msg_idmsg_destmsg_entity)
{
    static 
victimattackerFloat:aimvelocity[3]
    
    
victim get_msg_arg_int(2)
    
attacker get_msg_arg_int(3)

Here we can learn about the attacker and victim, but not the damage dealt

PHP Code:
public client_damage(attacker,vitim,damage,wpnindex,hitplace,TA
This can detect when damage is dealt to players and bots, but cannot modify damage to my knowledge

PHP Code:
register_event("PTakeDam""event_PTakeDam""a")
public 
event_PTakeDam()
{
    new 
damage
    damage 
read_data(7// does not display correct damage dealt

I believe PTakeDam is specific to TS, although does not give me what I'm looking for. Digging into this event, arg 7 (value 18) did not measure the correct amount of damage taken.
Code:
L 09/17/2016 - 10:16:34: MessageBegin (PTakeDam "126") (Destination "PVS<4>") (Args "7") (Entity "<NULL>") (Classname "<NULL>") (Netname "<NULL>") (Origin "-87.000000 2602.000000 82.000000")
L 09/17/2016 - 10:16:34: Arg 1 (Coord "-75.002639")
L 09/17/2016 - 10:16:34: Arg 2 (Coord "2595.726318")
L 09/17/2016 - 10:16:34: Arg 3 (Coord "111.333389")
L 09/17/2016 - 10:16:34: Arg 4 (Coord "-0.901821")
L 09/17/2016 - 10:16:34: Arg 5 (Coord "0.425157")
L 09/17/2016 - 10:16:34: Arg 6 (Coord "-0.077311")
L 09/17/2016 - 10:16:34: Arg 7 (Byte "18")
L 09/17/2016 - 10:16:34: MessageEnd (PTakeDam "126")
TSHealth event does not register with bots, so I cannot use that either

Quite stuck at the moment, any help or ideas would be welcomed :)

Last edited by Infest; 09-16-2016 at 21:25.
Infest is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-17-2016 , 05:09   Re: [TS] Client damage modification for bots
Reply With Quote #2

With ham, for bots that don't have "player" classname, you need to either use amxx 1.8.3 and set specialbot param to 1 or use directly RegisterHamPlayer. For amxx < 183 use RegisterHamFromEntity and provide a bot index.
__________________

Last edited by HamletEagle; 09-17-2016 at 05:14.
HamletEagle is offline
Infest
Member
Join Date: Mar 2005
Old 09-17-2016 , 06:40   Re: [TS] Client damage modification for bots
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
With ham, for bots that don't have "player" classname, you need to either use amxx 1.8.3 and set specialbot param to 1 or use directly RegisterHamPlayer. For amxx < 183 use RegisterHamFromEntity and provide a bot index.
Updated to 1.8.3 and changed
PHP Code:
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage")
->
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage",1
Still no luck. it still only registers real players and not bots
Infest is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-17-2016 , 08:36   Re: [TS] Client damage modification for bots
Reply With Quote #4

You did not do what I told you. You simply made the hook post, which is wrong.
Quote:
native HamHook:RegisterHam(Ham:function, const EntityClass[], const Callback[], Post=0, bool:specialbot = false)
So it should be
PHP Code:
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage"0true
__________________

Last edited by HamletEagle; 09-17-2016 at 08:36.
HamletEagle is offline
Infest
Member
Join Date: Mar 2005
Old 09-17-2016 , 18:40   Re: [TS] Client damage modification for bots
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
You did not do what I told you. You simply made the hook post, which is wrong.

So it should be
PHP Code:
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage"0true
Thanks! That was my mistake, I didn't look at the function definition!

Alright, this change has given some success. Bots can now trigger this event when they attack a player, but not when a player attacks a bot. Any ideas?

Edit: I wanted to find out the classname bots are given, so I collected this information with:
PHP Code:
pev(Entpev_classnameptrclassname31
Code:
Found ent: 1 - classname:player (real player)
Found ent: 2 - classname:player (bot)
Interestingly, bots as well as real players are given the "player" classname, which confuses me a little bit, I no longer see a reason why Ham_TakeDamage won't register damage given to bots

Edit 2: I took your advice and used your 2nd solution, to prevent errors I had to use a delay on client connect:
PHP Code:
public registerBotDamage(id)
{
    
RegisterHamFromEntity(Ham_TakeDamageid"hook_TakeDamage"0)
}

public 
client_connect(id)
{
    if(
is_user_bot(id))
    {
        
set_task(10.0,"registerBotDamage",id)
        return 
PLUGIN_HANDLED
    
}

This does work, although I'm not sure if it is the most efficient place to register bot damage. Would I also need to unregister the hook if bots are kicked/disconnected?

Last edited by Infest; 09-18-2016 at 01:56.
Infest is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-18-2016 , 05:25   Re: [TS] Client damage modification for bots
Reply With Quote #6

What bots are you using?

For the second question, you got the ideea. I would use client_putinserver, not connect. Also delay can be smaller, do some test and find the right value. 1.0 should be good, if delay is needed at all, not sure.

Also, you are registering the forward again and again, every time a bot connect. Doing it only one time is enough. For that, use a bool and set it to true once you register the forward.

No, don't unregister the hook when a bot disconnect. It's not specific to that bot, it works the same as RegisterHam.
__________________

Last edited by HamletEagle; 09-18-2016 at 05:31.
HamletEagle is offline
Infest
Member
Join Date: Mar 2005
Old 09-18-2016 , 09:16   Re: [TS] Client damage modification for bots
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
What bots are you using?

For the second question, you got the ideea. I would use client_putinserver, not connect. Also delay can be smaller, do some test and find the right value. 1.0 should be good, if delay is needed at all, not sure.

Also, you are registering the forward again and again, every time a bot connect. Doing it only one time is enough. For that, use a bool and set it to true once you register the forward.

No, don't unregister the hook when a bot disconnect. It's not specific to that bot, it works the same as RegisterHam.
Thanks, I put it into client_putinserver and only execute it once, found no issue doing it that way.

I am using the command 'addcustombots' for bots in the TS dedicated server implementation.
Infest 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:36.


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