Kill a player

Please post any questions about developing your plugin here. Please use the search function before posting!
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Kill a player

Postby Jerome69 » Thu Mar 17, 2016 9:26 am

Hello,

I would like to be able to kill a human player, but the command doesn't work. Can you help me please?

This is the code I'm using :

Syntax: Select all

from engines.server import engine_server

[...]player_list = PagedMenu(title='Liste des joueurs', select_callback=joueurselect)
for player in PlayerIter('human'):
player_list.append(PagedOption(player.name, player.name))

main_menu.close()
player_list.send(index)

def joueurselect(menu, player_index, option):
engine.server.server_command('kill ' + option.value)


And this is the message :
The attachment Command.jpg is no longer available


Is it a bad using of "kill" command?

Thanks for your help
Attachments
Command.jpg
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Mar 17, 2016 10:29 am

The problem is this line:

Syntax: Select all

engine.server.server_command('kill ' + option.value)

It should look like this:

Syntax: Select all

engine_server.server_command('kill ' + option.value)


However, since I'm not sure if there is a "kill" server command, I would simply use the built-in functionality.

Syntax: Select all

from players.entity import Player

player_list = PagedMenu(title='Liste des joueurs', select_callback=joueurselect)
for player in PlayerIter('human'):
player_list.append(PagedOption(player.name, player.index))

player_list.send(index)

def joueurselect(menu, player_index, option):
selected_player = Player(option.value)
selected_player.slay()
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Thu Mar 17, 2016 12:05 pm

I added the code but I have this error :

The attachment Sans titre.jpg is no longer available


[EDIT] I didn't see all the change you have done, so i didn't do them. I'll tell you when it will be done :)
Attachments
Sans titre.jpg
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Mar 17, 2016 12:48 pm

I guess you are still passing player.name to PagedOption as the second parameter. That's why option.value contains a string.
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Mon Mar 21, 2016 12:07 pm

Ok it works fine.

But I see when I kill a player, he has "-1" to his result. Is it possible to don't give him -1 to his result?

Thanks
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Mon Mar 21, 2016 2:08 pm

Well, I guess you can make it up by

Syntax: Select all

player.increment_frag_count(1)
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Mar 21, 2016 2:13 pm

Or even:

Syntax: Select all

player.kills += 1
Image
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Mon Mar 21, 2016 2:24 pm

Yep, but I looked the code up and thought that calling increment_frag_count would be better in this case. Because otherwise I don't see a reason to call it ever at all, and using .kills shortcut still calls this function but also requires m_iFrags property.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Mar 21, 2016 2:31 pm

It only calls it for CS:GO. And, the only reason for that is this issue. Also, if Valve ever updates the signature of increment_frag_count, that functionality will be broken until we update our data. Whereas, we get the m_iFrags value directly from the DataMap, so it will never be broken. And, currently increment_frag_count only is implemented for the OrangeBox and CS:GO engines, so making a plugin cross-engine/game compatible would be limited.

*Edit: and, to me, using <Player>.kills += <value> just looks a whole lot better.
Image
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Mon Mar 21, 2016 2:35 pm

I get it. I remember that issue but didn't look up the commit which closed it. Plus I missed that it was GO-only implementation.

Edit: Especially <Player>.kills -= <value>
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Tue Mar 22, 2016 10:49 am

satoon101 wrote:Or even:

Syntax: Select all

player.kills += 1


It works fine, thanks :)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 94 guests