AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hooking bots hurt (https://forums.alliedmods.net/showthread.php?t=105030)

Doc-Holiday 09-30-2009 11:20

Hooking bots hurt
 
Since Ham_TakeDamage only works for humans any one know a work around for bots?

i have working code for humans only... but i want to be able to make bots friendly fire variable..

so if i was to shoot a bot with an awp in the head it would only do 25% of its damage.

Example:
PHP Code:

public BotHurt
{
       if(
is_user_bot(victim)
       {
              if(
cs_get_user_team(victim) == cs_get_user_team(attacker))
              {
                   
damage dmgreduce
              
}
        }



ConnorMcLeod 09-30-2009 12:06

Re: Hooking bots hurt
 
Ham_TakeDamage works fine with podbot.

Exolent[jNr] 09-30-2009 12:10

Re: Hooking bots hurt
 
Quote:

Originally Posted by ConnorMcLeod (Post 948082)
Ham_TakeDamage works fine with podbot.

What functions don't work?
I read in some threads someone was using HamSandwich for bots and it wouldn't work.
I was under the impression that HamSandwich didn't support bots, instead of only a few functions not working.

SnoW 09-30-2009 12:10

Re: Hooking bots hurt
 
Quote:

Originally Posted by ConnorMcLeod (Post 948082)
Ham_TakeDamage works fine with podbot.

But not with CZ bots.

PHP Code:

#include <amxmodx>
#include <hamsandwich>
#define PLUGIN "Registering bots with ham"
#define VERSION "1.0"
#define AUTHOR "SnoW"
new bool:gBotsRegistered;
public 
plugin_init( )
{
     
register_pluginPLUGINVERSIONAUTHOR );
     
/*
          We are registering normal players just as an example.
     */
     
RegisterHamHam_Spawn"player""hamSpawnPlayer");
}
public 
client_authorizedid )
     if( !
gBotsRegistered && is_user_botid ) )
     {
          
/*
               The registering has to be delayed since the bot hasn't any data yet.
          */
          
set_task0.1"register_bots"id );
     }
 
public 
register_botsid )
{
     if( !
gBotsRegistered && is_user_connectedid ) )
     {
          
/*
               If registering wasn't done in the middle of the task and the bot haven't disconnected.
          */
          
RegisterHamFromEntityHam_Spawnid"hamSpawnBot");
          
gBotsRegistered true;
     }
}
public 
hamSpawnBotid )
{
     if( 
is_user_aliveid ) )
          
server_print"Bot spawn hooked correctly." );
     return 
HAM_IGNORED;
}
public 
hamSpawnPlayerid )
{
     if( 
is_user_aliveid ) )
          
server_print"Player spawn hooked correctly." );
     return 
HAM_IGNORED;


Edit: Reason below

Exolent[jNr] 09-30-2009 12:14

Re: Hooking bots hurt
 
Just so you know, 0.1 is the smallest delay you can use in set_task( ).
Code:
static cell AMX_NATIVE_CALL set_task(AMX *amx, cell *params) /* 2 param */ {     CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);     int a, iFunc;     char* stemp = get_amxstring(amx, params[2], 1, a);     if (params[5])     {         iFunc = registerSPForwardByName(amx, stemp, FP_ARRAY, FP_CELL, FP_DONE);     } else {         iFunc = registerSPForwardByName(amx, stemp, FP_CELL, FP_DONE);     }         if (iFunc == -1)     {         LogError(amx, AMX_ERR_NATIVE, "Function is not present (function \"%s\") (plugin \"%s\")", stemp, plugin->getName());         return 0;     }     float base = amx_ctof(params[1]);     if (base < 0.1f)         base = 0.1f;     char* temp = get_amxstring(amx, params[6], 0, a);     g_tasksMngr.registerTask(plugin, iFunc, UTIL_ReadFlags(temp), params[3], base, params[5], get_amxaddr(amx, params[4]), params[7]);     return 1; }

ConnorMcLeod 09-30-2009 13:06

Re: Hooking bots hurt
 
Instead of using a task, you can register/unregister UpdateClientData, will register the ham forward at next frame.

SnoW 09-30-2009 14:55

Re: Hooking bots hurt
 
I could, but I see there no advantage.

Doc-Holiday 10-01-2009 04:45

Re: Hooking bots hurt
 
Quote:

Originally Posted by SnoW (Post 948088)
But not with CZ bots.

PHP Code:

#include <amxmodx>
#include <hamsandwich>
#define PLUGIN "Registering bots with ham"
#define VERSION "1.0"
#define AUTHOR "SnoW"
new bool:gBotsRegistered;
public 
plugin_init( )
{
     
register_pluginPLUGINVERSIONAUTHOR );
     
/*
          We are registering normal players just as an example.
     */
     
RegisterHamHam_Spawn"player""hamSpawnPlayer");
}
public 
client_authorizedid )
     if( !
gBotsRegistered && is_user_botid ) )
     {
          
/*
               The registering has to be delayed since the bot hasn't any data yet.
          */
          
set_task0.1"register_bots"id );
     }
 
public 
register_botsid )
{
     if( !
gBotsRegistered && is_user_connectedid ) )
     {
          
/*
               If registering wasn't done in the middle of the task and the bot haven't disconnected.
          */
          
RegisterHamFromEntityHam_Spawnid"hamSpawnBot");
          
gBotsRegistered true;
     }
}
public 
hamSpawnBotid )
{
     if( 
is_user_aliveid ) )
          
server_print"Bot spawn hooked correctly." );
     return 
HAM_IGNORED;
}
public 
hamSpawnPlayerid )
{
     if( 
is_user_aliveid ) )
          
server_print"Player spawn hooked correctly." );
     return 
HAM_IGNORED;


Edit: Reason below


So running this will allow Ham_TakeDamage to affect bots?

SnoW 10-01-2009 08:51

Re: Hooking bots hurt
 
Quote:

Originally Posted by NcB_Sav (Post 948899)
So running this will allow Ham_TakeDamage to affect bots?

No. It's an example and hooks bots' spawn.

ConnorMcLeod 10-01-2009 16:46

Re: Hooking bots hurt
 
Then, you would have to set 3 values for gBotsRegistered :

0 = not registered
1 = registering soon
2 = registered

Advantage is that you don't use any task + it's immediatly registered.

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"

new g_iFhUpdateClientDatag_iFirstBotId

public plugin_init()
{
    
register_plugin("TakeDamage"VERSION"ConnorMcLeod")

    new 
szModName[6]
    
get_modname(szModNamecharsmax(szModName))
    if( !
equal(szModName"czero") || cvar_exists("pb_version") )
    {
        
g_iFhUpdateClientData = -1
    
}

    
RegisterHam(Ham_TakeDamage"player""Player_TakeDamage")
}

public 
client_putinserverid )
{
    if( !
g_iFhUpdateClientData && is_user_bot(id) )
    {
        
g_iFirstBotId id
        g_iFhUpdateClientData 
register_forward(FM_UpdateClientData"UpdateClientData")
    }
    
}

public 
UpdateClientData(id)
{
    if( 
id == g_iFirstBotId )
    {
        
unregister_forward(FM_UpdateClientDatag_iFhUpdateClientData)
        
RegisterHamFromEntity(Ham_TakeDamageid"Player_TakeDamage")
    }
}

public 
Player_TakeDamageid iInflictor iAttackerFloat:flDamage iDamageType )
{




Exolent[jNr] 10-01-2009 17:03

Re: Hooking bots hurt
 
Quote:

Originally Posted by ConnorMcLeod (Post 949451)
PHP Code:

public plugin_putinserverid 


Omg, where'd you get that function? :D

ConnorMcLeod 10-02-2009 01:08

Re: Hooking bots hurt
 
New forward i've found while searching offsets in my kitchen garden.

Doc-Holiday 10-02-2009 03:30

Re: Hooking bots hurt
 
Quote:

Originally Posted by ConnorMcLeod (Post 949782)
New forward i've found while searching offsets in my kitchen garden.

LMFAO


so then something like this would work using your methond of hooking bots


PHP Code:

/*
* Thanks to Conor for hooking bots
* to allow for Ham_TakeDamage to work on them
*  
*/

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "1.0"

//Conors news
new g_iFhUpdateClientDatag_iFirstBotId;

//My news
new dmg_reduce

public plugin_init()
{
    
register_plugin("Variable Friendly Fire"VERSION"=(GrG)=");
    
    
dmg_reduce register_cvar("dmg_var""0.0");
    
    new 
szModName[6];
    
get_modname(szModNamecharsmax(szModName));
    if( !
equal(szModName"czero") || cvar_exists("pb_version") )
    {
        
g_iFhUpdateClientData = -1;
    }
    
    
RegisterHam(Ham_TakeDamage"player""Player_TakeDamage");
}

public 
client_putinserverid )
{
    if( !
g_iFhUpdateClientData && is_user_bot(id) )
    {
        
g_iFirstBotId id;
        
g_iFhUpdateClientData register_forward(FM_UpdateClientData"UpdateClientData");
    }
    
}

public 
UpdateClientData(id)
{
    if( 
id == g_iFirstBotId )
    {
        
unregister_forward(FM_UpdateClientDatag_iFhUpdateClientData);
        
RegisterHam(Ham_TakeDamage"player""Player_TakeDamage");
    }
}

public 
Player_TakeDamageid iInflictor iAttackerFloat:fDamage iDamageType )
{
    
    if(
is_user_alive(id) && is_user_alive(iAttacker) && cs_get_user_team(id) == cs_get_user_team(iAttacker))
    {
        
SetHamParamFloat(4fDamage get_pcvar_float(dmg_reduce));
    }


This would multiply all friendly fire by the mulitplier right?

Arkshine 10-02-2009 06:24

Re: Hooking bots hurt
 
It should be RegisterHamFromEntity()

ConnorMcLeod 10-02-2009 13:16

Re: Hooking bots hurt
 
Ops :down:

Doc-Holiday 10-02-2009 18:04

Re: Hooking bots hurt
 
Quote:

Originally Posted by Arkshine (Post 949904)
It should be RegisterHamFromEntity()

whats that?

Doc-Holiday 10-05-2009 14:17

Re: Hooking bots hurt
 
By the way it still didnt work :(

vittu 10-05-2009 19:54

Re: Hooking bots hurt
 
Quote:

Originally Posted by NcB_Sav (Post 953233)
By the way it still didnt work :(

Did you fix your code in the UpdateClientData function for RegisterHamFromEntity instead of RegisterHam like was discussed above? Connor did fix his example, you may not have noticed.

ConnorMcLeod 10-06-2009 14:39

Re: Hooking bots hurt
 
And if still doesn't work, replace :

g_iFhUpdateClientData = register_forward(FM_UpdateClientData, "UpdateClientData")

with

g_iFhUpdateClientData = register_forward(FM_UpdateClientData, "UpdateClientData", 1)

WATCH_D0GS UNITED 02-27-2024 18:01

Re: Hooking bots hurt
 
Quote:

Originally Posted by ConnorMcLeod (Post 954206)
And if still doesn't work, replace :

g_iFhUpdateClientData = register_forward(FM_UpdateClientData, "UpdateClientData")

with

g_iFhUpdateClientData = register_forward(FM_UpdateClientData, "UpdateClientData", 1)

Not and will not, because you are trying to register ham for bots in a forward which is not called for bots, lol.

Jhob94 02-27-2024 18:09

Re: Hooking bots hurt
 
Quote:

Originally Posted by WATCH_D0GS UNITED (Post 2818713)
Not and will not, because you are trying to register ham for bots in a forward which is not called for bots, lol.

This thread is from 2009.
On your quote he is not registering ham, he is registering a forward with fakemeta.

WATCH_D0GS UNITED 02-27-2024 18:33

Re: Hooking bots hurt
 
Quote:

Originally Posted by Jhob94 (Post 2818714)
This thread is from 2009.
On your quote he is not registering ham, he is registering a forward with fakemeta.

It is a unsolved thread from 2009, what cares the day it was published, it could be 00/00/0000.

And We are talking about this:

Quote:

Originally Posted by ConnorMcLeod (Post 949451)
Then, you would have to set 3 values for gBotsRegistered :

0 = not registered
1 = registering soon
2 = registered

Advantage is that you don't use any task + it's immediatly registered.

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"

new g_iFhUpdateClientDatag_iFirstBotId

public plugin_init()
{
    
register_plugin("TakeDamage"VERSION"ConnorMcLeod")

    new 
szModName[6]
    
get_modname(szModNamecharsmax(szModName))
    if( !
equal(szModName"czero") || cvar_exists("pb_version") )
    {
        
g_iFhUpdateClientData = -1
    
}

    
RegisterHam(Ham_TakeDamage"player""Player_TakeDamage")
}

public 
client_putinserverid )
{
    if( !
g_iFhUpdateClientData && is_user_bot(id) )
    {
        
g_iFirstBotId id
        g_iFhUpdateClientData 
register_forward(FM_UpdateClientData"UpdateClientData")
    }
    
}

public 
UpdateClientData(id)
{
    if( 
id == g_iFirstBotId )
    {
        
unregister_forward(FM_UpdateClientDatag_iFhUpdateClientData)
        
RegisterHamFromEntity(Ham_TakeDamageid"Player_TakeDamage")
    }
}

public 
Player_TakeDamageid iInflictor iAttackerFloat:flDamage iDamageType )
{




PHP Code:

public UpdateClientData(id)
{
    if( 
id == g_iFirstBotId )
    {
        
unregister_forward(FM_UpdateClientDatag_iFhUpdateClientData)
        
RegisterHamFromEntity(Ham_TakeDamageid"Player_TakeDamage")
    }



Jhob94 02-28-2024 04:04

Re: Hooking bots hurt
 
Back in 2009 threads didn’t have solved/unsolved feature.

I can’t be 100% sure because i never used bots in my life but that’s how you register takedamage from an entity (taking damage from a npc for example). So it probably also works with bots.

WATCH_D0GS UNITED 02-28-2024 07:26

Re: Hooking bots hurt
 
Quote:

Originally Posted by Jhob94 (Post 2818727)
Back in 2009 threads didn’t have solved/unsolved feature.

I can’t be 100% sure because i never used bots in my life but that’s how you register takedamage from an entity (taking damage from a npc for example). So it probably also works with bots.

That's the way you register ham from entity, but he tried to make this in a function which is not called for bots.

This means the 'id' he is passing is always from a human player. You need to register ham for bots with a bot id for it to work.

-

Jhob94 02-28-2024 11:39

Re: Hooking bots hurt
 
Since he uses bot id he is not passing a real player id. The only thing that could happen would be the code not work if updateclientdata ignores bots.

Code:

void UpdateClientData(const struct edict_s *ent, int sendweapons, struct clientdata_s *cd)
{
        g_cd_hook = cd;
        FM_ENG_HANDLE(FM_UpdateClientData, (Engine[FM_UpdateClientData].at(i), (cell)ENTINDEX(ent), (cell)sendweapons, (cell)cd));
        RETURN_META(mswi(lastFmRes));
}

void UpdateClientData_post(const struct edict_s *ent, int sendweapons, struct clientdata_s *cd)
{
        g_cd_hook = cd;
        FM_ENG_HANDLE_POST(FM_UpdateClientData, (EnginePost[FM_UpdateClientData].at(i), (cell)ENTINDEX(ent), (cell)sendweapons, (cell)cd));
        RETURN_META(MRES_IGNORED);
}

I am on mobile phone so i couldn’t search much about it. From what i found it should work with bots.
I don’t have the opportunity to test it today, maybe you can.

WATCH_D0GS UNITED 02-28-2024 13:46

Re: Hooking bots hurt
 
Quote:

Originally Posted by Jhob94 (Post 2818743)
Since he uses bot id he is not passing a real player id. The only thing that could happen would be the code not work if updateclientdata ignores bots.

As We have tried to say since the beginning, FM_UpdateClientData is not called for bots, which means his code below will always return false.

PHP Code:

 if( id == g_iFirstBotId 


Jhob94 02-28-2024 15:11

Re: Hooking bots hurt
 
Well if it doesn’t it ain’t a problem. Just register ham from entity on bot connection. Problem solved.

But are you sure it is not called for bots?

WATCH_D0GS UNITED 02-28-2024 21:32

Re: Hooking bots hurt
 
Quote:

Originally Posted by Jhob94 (Post 2818752)
But are you sure it is not called for bots?

If you are expecting a bot to have framerate.


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

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