AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Bot Apology for TK (https://forums.alliedmods.net/showthread.php?t=85581)

fysiks 02-13-2009 00:38

Bot Apology for TK
 
7 Attachment(s)
Bot Apology for TK

Many servers that I play on have friendly fire turned on and many also "require" an apology for team kills. If you have bots, why not let them set a good example?

Description:
This plugin will make a bot apologize, in chat, for it's team kills.

Cvars:
amx_bot_apology <1|0> - Turn plugin on or off.
amx_bot_apology_prob <0-100> - The probability that the bot will apologize for a TK.
amx_bot_apology_method <0-100> - Probability that team chat will be used. (0 -> public, 100 -> team)
amx_bot_apology_delay <#> - The time between the TK and the apology (from last TK if there was another within the delay time of the previous TK).
Note: Cvar changes take effect on map change.

I only play Day of Defeat but I would assume that it would work on other Mods as it is very simple with no Mod specific code.


Thanks for feeback and suggestions:
- Vet
- Arkshine
- Exolent

Changelog:

v1.3
- Removed unnecessary(?) condition checks.
- Changed Death detection from Ham Hook to Event Hook.

v1.4
- Added is_bot global array instead of is_user_bot (set on putinserver).
- Remove task on disconnect.
- Rearranged some code.

v1.5
- Changed method for assigning is_bot values.
- Changed on/off cvar usage.

v2.0
- Added cvar to allow using team chat.

v3.0
- Added bot_apology.ini for apology phrases.
- Changed "chance" to a macro.
- Using copy for string assignment.

SnoW 02-13-2009 09:48

Re: Bot Apology for TK
 
Quote:

Originally Posted by fysiks (Post 760737)
This is supposed to be in the Server Management Category (I'm sure I selected that)

You can change the category after. Just press the button "Go advanced" on edit.

fysiks 02-13-2009 12:14

Re: Bot Apology for TK
 
Upadted: See Changelog.

fysiks 02-19-2009 18:13

Re: Bot Apology for TK
 
Updated to 1.2.

BOYSplayCS 02-19-2009 18:23

Re: Bot Apology for TK
 
Good job :)

joaquimandrade 02-19-2009 18:44

Re: Bot Apology for TK
 
random_num(0,99) should be random_num(0,100)

;)

Arkshine 02-19-2009 18:47

Re: Bot Apology for TK
 
Here some thoughts :

- g_sorry_phrases <= use const before since it's something constant and don't harcode '6', no need.
- Since it's for bots, you should not use Ham, if the bot's classname is not "player" it will not work. More appropriate to use DeathMsg event which is perfectly fine.
- Cache the value of is_user_bot(). Just save it into a var in client_putinserver().
- Doing a check if victim/killer is connected in the death function is useless here.
- Don't check if task exists, no need here, you can remove directly.
- set_task ; why did you pass the killer id ? The message will be showed only for the killer and not the victim. I think this message should be showed for all players, so using 0.
- In say_sorry() function, the check for bot is useless ; same for is_user_connected assuming you pass 0, and you engclient_cmd() should be : engclient_cmd(0,"say %s",g_sorry_phrases[random_num(0, sizeof g_sorry_phrases - 1)])

Did you test your plugin ? :s

joaquimandrade 02-19-2009 18:55

Re: Bot Apology for TK
 
Quote:

Originally Posted by arkshine (Post 764950)
Here some thoughts :

- g_sorry_phrases <= use const before since it's something constant and don't harcode '6', no need.
- Since it's for bots, you should not use Ham, if the bot's classname is not "player" it will not work. More appropriate to use DeathMsg event which is perfectly fine.
- Cache the value of is_user_bot(). Just save it into a var in client_putinserver().
- Doing a check if victim/killer is connected in the death function is useless here.
- Don't check if task exists, no need here, you can remove directly.
- set_task ; why did you pass the killer id ? The message will be showed only for the killer and not the victim. I think this message should be showed for all players, so using 0.
- In say_sorry() function, the check for bot is useless ; same for is_user_connected assuming you pass 0, and you engclient_cmd() should be : engclient_cmd(0,"say %s",g_sorry_phrases[random_num(0, sizeof g_sorry_phrases - 1)])

Did you test your plugin ? :s

If you want it perfect, add also enableham/disableham if there are bots or not, in the server.

Edit: arkshine, why would the classname be other than "player"?

Arkshine 02-19-2009 19:09

Re: Bot Apology for TK
 
cz bots are not "player" for example. So it's possible that others bots is not "player" though most are "player". Using DeathMsg is fine.

Quote:

If you want it perfect, add also enableham/disableham if there are bots or not, in the server.
Yep, I did not mention it because I've suggested DeathMsg but I forget he could use unregister_message(). Would already fine if all the suggestions are followed. :p :

joaquimandrade 02-19-2009 19:16

Re: Bot Apology for TK
 
Quote:

Originally Posted by arkshine (Post 764960)
cz bots are not "player" for example. So it's possible that others bots is not "player" though most are "player". Using DeathMsg is fine.



Yep, but for some reasons I did not mention it. Would already fine if all the suggestions are followed. :p

Ok, i never played cz. You're right then. :)

Edit:

Can you unregister events with "unregister_message"?

fysiks 02-20-2009 01:58

Re: Bot Apology for TK
 
Quote:

Originally Posted by joaquimandrade (Post 764948)
random_num(0,99) should be random_num(0,100)

Incorrect. I thought this over hard. Checked my boundaries and I need 99. If I set the cvar to 100 and random_num() returns 100 --> 100 !> 100 and therefore would execute the command even though it should 100% of the time. Also, 0 to 100 is 101 numbers.

If I use "<=" I can use 1 to 100.

Quote:

Originally Posted by arkshine (Post 764950)
- g_sorry_phrases <= use const before since it's something constant and don't harcode '6', no need.

Will do.

Quote:

Originally Posted by arkshine (Post 764950)
- Since it's for bots, you should not use Ham, if the bot's classname is not "player" it will not work. More appropriate to use DeathMsg event which is perfectly fine.

Once I had a taste of the HamSandwich I crave it all the time :). I'll get it switched.

Quote:

Originally Posted by arkshine (Post 764950)
- Cache the value of is_user_bot(). Just save it into a var in client_putinserver().

I assume you say this because it will be faster/more efficient?

Quote:

Originally Posted by arkshine (Post 764950)
- Doing a check if victim/killer is connected in the death function is useless here.

I was trying to prevent this runtime error: (in case the victim or killer gets disconnected for some reason)
Code:

L 02/20/2009 - 00:37:07: [DODX] Invalid player 15
L 02/20/2009 - 00:37:07: [AMXX] Displaying debug trace (plugin "test.amxx")
L 02/20/2009 - 00:37:07: [AMXX] Run time error 10: native error (native "get_user_team")

Quote:

Originally Posted by arkshine (Post 764950)
- set_task ; why did you pass the killer id ? The message will be showed only for the killer and not the victim. I think this message should be showed for all players, so using 0.

It's not a print_chat message. It's emulating the user(bot) saying something in chat. And therefore will be shown to everyone.

Using zero gives this:
Code:

|RIP| Fysiks |mR killed his teammate Sgt.EVILswede with garand
|RIP| Fysiks |mR: sorry
Sgt.Dayglow_abortions: sorry
Sgt.ObiWan: sorry
Sgt.Polymorph: sorry
Sgt.KristineKochanski: sorry
Sgt.QuagaarWarrior: sorry
Sgt.Gilderk_the_Minotaur: sorry
Sgt.EVILcommando: sorry
...

Quote:

Originally Posted by arkshine (Post 764950)
- In say_sorry() function, the check for bot is useless ; same for is_user_connected assuming you pass 0, and you engclient_cmd() should be : engclient_cmd(0,"say %s",g_sorry_phrases[random_num(0, sizeof g_sorry_phrases - 1)])

I check if it's a bot because in 3 seconds time (or what ever time set with the cvar) the bot could leave and a real player enters. I don't want the real player to say sorry for that which he has not done.
I check is_user_connected because the bot could leave (and not be replaced) in the time set with the delay cvar.

Also, engclient_cmd deos not work like that. "say" is the command and g_sorry_phrase[#] is arg1.

Quote:

Originally Posted by arkshine (Post 764950)
Did you test your plugin ? :s

WOW, that is quite the insult. Yes, why wouldn't I. I would not have posted it if it didn't work, I test my plugins after nearly every change in code I make. It works exactly as I expect it to. Of course I only play DOD so that is what I tested it on.

fysiks 02-20-2009 03:53

Re: Bot Apology for TK
 
Updated to 1.3.

joaquimandrade 02-20-2009 05:09

Re: Bot Apology for TK
 
Quote:

random ( max )
random - Returns a pseudo-random number in the range of 0 to max-1.
random(100) doesn't return 100

Edit: forget it. I was tought that you were using random but you are using random_num

Arkshine 02-20-2009 06:44

Re: Bot Apology for TK
 
Quote:

I assume you say this because it will be faster/more efficient?
Yep. Always better to avoid unnecessary native call. Bot will keep a bot so it's not bad to save one time the value in putinserver into a global var.

Quote:

It's not a print_chat message [...] Also, engclient_cmd deos not work like that. "say" is the command and g_sorry_phrase[#] is arg1.
You're right. I did not think that when I reviewed your plugin.

Quote:

I check if it's a bot because in 3 seconds time (or what ever time set with the cvar) the bot could leave and a real player enters. I don't want the real player to say sorry for that which he has not done.
I check is_user_connected because the bot could leave (and not be replaced) in the time set with the delay cvar.
is_user_bot, yes, but is_user_connected no because engclient_cmd() won't send if player is not in-game. There is only a check if id is not out of range.
But, anyway, you should remove the task on client_disconnect, so the check is_user_bot would be useless and also avoiding possible problems.

Quote:

WOW, that is quite the insult.
Sorry, it was not my intention. :mrgreen:


Anyway, you should avoid this way of coding, returning each time something. It will generate more code. You could do something like :

PHP Code:

public player_death ()
{
    if ( 
get_pcvar_numcvar_sorry_onoff ) )
    {
        new 
killerid read_data);
        new 
victimid read_data);
        
        if ( 
victimid != killerid && is_user_botkillerid ) && get_user_teamkillerid ) == get_user_teamvictimid ) )
        {
            
remove_taskkillerid );
            
set_taskget_pcvar_floatcvar_sorry_delay ), "say_sorry"killerid );
        }
    }


PHP Code:

public say_sorry id )
{
    if ( 
is_user_bot id ) && clampget_pcvar_numcvar_sorry_prob ), 0100 ) > random_num099 ) )
    {
        
engclient_cmdid"say"g_sorry_phrasesrandomsizeofg_sorry_phrases ) ) ] );
    }


Also you should add that attacker should be > 0, it will skip suicide and killed by world : register_event( "DeathMsg", "player_death", "a", "1>0" );

fysiks 02-20-2009 13:30

Re: Bot Apology for TK
 
Quote:

Originally Posted by arkshine (Post 765170)
Anyway, you should avoid this way of coding, returning each time something.

I was wondering about that. With ham I was having trouble with killerids > 32 causing runtime errors with the get_user_team originally so I neede to exit before executing those two natives. But with DeathMsg, I won't need to worry about that.

Also, I was thinking that if it was a bot then I wouldn't need to do the "killed self" check or the TK check by returning PLUGIN_CONTINUE first and thus minimizing the execution time when there are no bots on the server (which is the time you want it to do as little as possible). Any thoughts on this would be great.

Thanks for all your help :).

EDIT: Updated to 1.4

Arkshine 02-20-2009 19:55

Re: Bot Apology for TK
 
Not need to do that Vet. If player is a bot, it will return 1 otherwise 0. So, no need to "clear".

By the way :

Code:

if(is_user_bot(id))
{  is_bot[id] = true;        }
else
{  is_bot[id] = false;        }

=>
Code:

is_bot[id] = is_user_bot(id);
Quote:

Also, I was thinking that if it was a bot then I wouldn't need to do the "killed self" check or the TK check by returning PLUGIN_CONTINUE first and thus minimizing the execution time when there are no bots on the server (which is the time you want it to do as little as possible). Any thoughts on this would be great.
Not sure to fully understand. But it seems that you still return PLUGIN_CONTINUE, which you can avoid that, doing like I've done above. It will generate less code.

Vet 02-20-2009 20:15

Re: Bot Apology for TK
 
Your right ark, I realized that later and sheepishly deleted the post.

fysiks 02-21-2009 00:49

Re: Bot Apology for TK
 
Updated. I think we are close :). It's only been tested on DOD still, as far as I know.

Hawk552 02-23-2009 00:11

Re: Bot Apology for TK
 
This plugin needs testing. If anyone can report that it does or doesn't work, please post.

If you would like any information regarding possible adjustments you could make or things you could do to make this better, please feel free to post here or PM me.

Approval pending on changes.

Dr.G 02-23-2009 10:38

Re: Bot Apology for TK
 
fysiks... first you used ham to hook the death and that was good, ham is fast. so i think you should go back to ham.

why do ya do this:

Code:


public client_putinserver(id)
{
 is_bot[id] = is_user_bot(id)
}


that is not needed at all, just use is_user_bot(id). if you want something random to happen you can do something like this:

Code:


new rN = random_num(1, 100)
if (rN <= 66)
if (rN <= 33)
if (rN <= 10)

are you 100% sure that engclient_cmd works here?

i dont understand your chance thing either... and not your
Code:


if(chance(get_pcvar_num(cvar_chat_method)))

what is the chance that it will return false and use the "else" part ?? its 1 out of 100 as i see it.

if i where you i would start allover, and first thing i would do was to find how exec that say cmd on a bot, and after that find a good way to do get the random thing to happen...

if i should make the random say txt i would do like this in a function:
Code:


switch(random_num(1,6))
{
 case 1:client_cmd(id,"say Something # 1")
 case 2: client_cmd(id,"say Something # 2")
 case 3: client_cmd(id,"say Something # 3")
 case 4: client_cmd(id,"say Something # 4")     
 case 5: client_cmd(id,"say Something # 5")
 case 6: client_cmd(id,"say Something # 6")     
}

overall i think you make it way more complicated then it have to be...

cheers

Vet 02-23-2009 10:53

Re: Bot Apology for TK
 
FYI, we run this plugin on our server and it appears to do the job quite well.

Programming wise, like I always say, there's many ways to skin a cat (I prefer pliers). So unless the code is in a critical routine (like a prethink), 'to each his own'.

fysiks 02-23-2009 11:07

Re: Bot Apology for TK
 
Apparently you have not run my plugin with bots yet. :). I guaruntee it will work on DOD with Shrikebot. It's running on a public server right now.

Ham :::
I had a bit of trouble with Ham. I was required to check a alot more stuff (maybe not alot, but enough to be annoying). I was getting killerids like 59, 639, 520, . . . (59 is electric ally on dod_caen). If you are saying Ham is quicker to the draw, it doesn't matter, the response is delayed anyways. Also, if it can be done with only one include and I don't need to do anything like supercede this way is great afaik.

is_user_bot(id) :::
Go back and read arkshine's comments. (minimize native calls)

Random :::
No. For the phrases I want random (just plain random, well, pseudorandom :)).

chance(prob) :::

chance(100) returns true 100% of the time.
chance(50) returns true 50% of the time (statistically).
chance(1) returns true 1% of the time (statistically).
chance(0) returns true 0% of the time (i.e. always returns false.)

engclient_cmd() :::

You can't send a client command to a bot (i.e. can't use client_cmd) afaik. engclient_cmd sends a command to the server as if it is coming from the client and it works great!

Why would I use a case structure if I can just assign a variable and pass that variable to the command?

Quote:

overall i think you make it way more complicated then it have to be...
As far as I'm concerned this code is very simple (Once I got things straightened out).

Quote:

Did that bot just apologiz to me?

Meathead~MBG~ 03-01-2009 01:41

Re: Bot Apology for TK
 
That would be my server. Working fine.

From HLSW
Quote:

(Allies) Pvt.*LiTTleKings : sory
(Allies) Pvt.*LiTTleKings : sory
(Allies) Pvt.*naTurAlliGht : sorry
( Axis) Pvt.*mOOsEheaD : sorry
(Allies) Pvt.*naTurAlliGht : sorry!
(Allies) Pvt.*CaN : sry
( Axis) Pvt.*BoTTle : sry!
( Axis) Pvt.*st.paulyGURL : sry
(Allies) Pvt.*HEINEken : oops sorry
( Axis) Pvt.*BoTTle : sry
( Axis) Pvt.*sChLitZ : sory
(Allies) Pvt.*KEGGER : oops sorry
( Axis) Pvt.*sChLitZ : sorry!
(Allies) Pvt.*KEGGER : sory

Exolent[jNr] 03-29-2009 15:34

Re: Bot Apology for TK
 
1. Would be better to have a .ini file so they could put their own apology messages.

2.
Code:
new chat_method[9] // chat_method = chance(get_pcvar_num(cvar_chat_method)) ? "say_team" : "say"; // Does not work :(; runtime error 5:memory access; line 90,72 if(chance(get_pcvar_num(cvar_chat_method))) // Is it said in public or team chat? {   chat_method = "say_team"; } else {   chat_method = "say"; }
Use copy() instead.

3.
Code:
// Given the probability, does it happen? bool:chance(probability) {     // return ( clamp(probability,0,100) > random_num(0,99) )     return ( probability > random_num(0,99) )  // Faster without pointless native call. }
If it is something like this that can be made with one line, it's better to make it a define and place it at the top of the plugin.
Also, random numbers should be 1-100
Code:
#define chance(%1) ( probability >= random_num(1, 100) )

Approval pending upon changes.

fysiks 03-29-2009 15:56

Re: Bot Apology for TK
 
I greatly appreciate your input.

ini file: Should I use dynamic arrays for retrieving the apology messages or should I hard code a cap (max) (with a #define probably)?

Chance: If using '>=' you must use 1-100 but if using only the '>' 0-99 is correct.

I'll get to work on this.

Exolent[jNr] 03-29-2009 15:59

Re: Bot Apology for TK
 
I would suggest dynamic arrays, but it's however you wish.

As for the chance calculation, you are correct. I just use 1-100 because it's more readable.

fysiks 03-29-2009 16:56

Re: Bot Apology for TK
 
Updated. Let me know if I can improve it anymore. I will look into using dynamic arrays for phrases sometime in the near future.

I have a max of 10 phrases (this can be changed in the code: "SORRYS_MAX").

Thanks everybody.

joaquimandrade 03-29-2009 18:19

Re: Bot Apology for TK
 
Quote:

Originally Posted by fysiks (Post 792649)
Updated. Let me know if I can improve it anymore. I will look into using dynamic arrays for phrases sometime in the near future.

I have a max or 10 phrases (this can be changed in the code: "SORRYS_MAX").

Thanks everybody.

Congratulations fysiks.

Vet 03-29-2009 21:54

Re: Bot Apology for TK
 
GJ my man

fysiks 03-30-2009 19:06

Re: Bot Apology for TK
 
Wahooo! Thanks guys.

Empowers 03-31-2009 11:55

Re: Bot Apology for TK
 
Wow really nice idea :)

thx Fysiks

cs1.7 06-26-2009 23:04

Re: Bot Apology for TK
 
great plugin could you add a cvar that makes bots also apologize in TA?

like

amx_bot_apology_ta

fysiks 06-27-2009 00:42

Re: Bot Apology for TK
 
Quote:

Originally Posted by cs1.7 (Post 858160)
great plugin could you add a cvar that makes bots also apologize in TA?

like

amx_bot_apology_ta

I can look into it. I don't know if that would make it Mod dependent. I will make a custom one for you. I guess I should assume you are playing CS :).

cs1.7 06-27-2009 00:47

Re: Bot Apology for TK
 
Quote:

Originally Posted by fysiks (Post 858191)
I guess I should assume you are playing CS :).

yup! :)

lol gonna be funny

fysiks 06-27-2009 01:08

Re: Bot Apology for TK
 
1 Attachment(s)
Try this. If it doesn't work I will see what I can do, but hopefully there is no problem :)

Cvar: amx_bot_apology_ta "1"


-

cs1.7 06-27-2009 01:29

Re: Bot Apology for TK
 
installed it..dunno if it works. join !!!!

edit

seems it works! nice plugin m8! :D

Empowers 02-14-2010 12:34

Re: Bot Apology for TK
 
Oh my god, that bot have just apologized me = ))


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

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