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-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


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

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