CSGO Chicken Entities

Please post any questions about developing your plugin here. Please use the search function before posting!
petros789
Junior Member
Posts: 6
Joined: Sun Feb 08, 2015 9:40 pm

CSGO Chicken Entities

Postby petros789 » Wed Apr 01, 2015 4:35 am

Is there any way to view the deaths of chickens in CSGO and who killed the animal?

Thanks in advance!
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Apr 01, 2015 5:26 am

Syntax: Select all

# ../chicken/chicken.py

# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python Imports
# Core
from core import PLATFORM
# Entities
from entities import TakeDamageInfo
from entities.helpers import index_from_pointer
# Memory
from memory import Convention
from memory import DataType
from memory import find_binary
from memory import get_object_pointer
from memory import make_object
from memory.hooks import PreHook
# Messages
from messages import SayText2
# Players
from players.entity import PlayerEntity


# ============================================================================
# >> GLOBAL VARIABLES
# ============================================================================
# Get the CChiken::Event_Killed function ...
CHICKEN_KILLED_FUNC = find_binary('server').find_address(
'_ZN8CChicken12Event_KilledERK15CTakeDamageInfo' if
PLATFORM == 'linux' else b'\x55\x8B\xEC\x83\xEC\x18\x56\x51\x68\x40'
).make_function(Convention.THISCALL,
(DataType.POINTER, DataType.POINTER), DataType.VOID)


# ============================================================================
# >> HOOKS
# ============================================================================
@PreHook(CHICKEN_KILLED_FUNC)
def pre_chicken_killed(arguments):
"""Pre CChiken::Event_Killed hook callback."""
# Get the CTakeDamageInfo instance...
info = make_object(TakeDamageInfo, arguments[1])

# Get the index of the chicken...
index = index_from_pointer(arguments[0])

# Get the PlayerEntity instance of the attacker...
attacker = PlayerEntity(info.attacker)

# Display a message...
SayText2(message='{0} killed a chicken (index: {1}).'.format(
attacker.name, index)).send()
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Hunting wild chickens for dinner!

Postby L'In20Cible » Wed Apr 01, 2015 5:31 am

Image
Image
petros789
Junior Member
Posts: 6
Joined: Sun Feb 08, 2015 9:40 pm

Postby petros789 » Wed Apr 01, 2015 7:16 am

This is amazing, thank you so much! I have made ideas from this haha. If it's not too much trouble may I ask how you got so many chickens spawned?
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Apr 01, 2015 8:05 am

While testing the creation code, I noticed the game is firing the following event when a chicken is dying:

Code: Select all

   "other_death"
   {
      "otherid"      "short"      // other entity ID who died         
      "othertype"      "string"      // other entity type
      "attacker"      "short"       // user ID who killed
      "weapon"      "string"    // weapon name killer used
      "weapon_itemid"   "string"   // inventory item id of weapon killer used
      "weapon_fauxitemid"   "string"   // faux item id of weapon killer used
      "weapon_originalowner_xuid"   "string"
      "headshot"      "bool"      // singals a headshot
      "penetrated"   "short"   // number of objects shot penetrated before killing target
   }

Which means we doesn't have to hook anything. The following snippet allows you to spawn chickens with "/chicken" and notify everyone when a chicken get killed.

Syntax: Select all

# ../chicken/chicken.py

# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python Imports
# Events
from events import Event
# Entities
from entities.entity import BaseEntity
from entities.helpers import create_entity
from entities.helpers import spawn_entity
# Messages
from messages import SayText2
# Players
from players.helpers import index_from_userid
from players.entity import PlayerEntity


# ============================================================================
# >> GAME EVENTS
# ============================================================================
@Event
def player_say(game_event):
"""Fired every time a player is typing something."""
# Make sure the typed text was "/chicken"...
if game_event.get_string('text') != '/chicken':
return

# Create a chicken entity...
chicken = BaseEntity(create_entity('chicken'))

# Move the chicken where the player is looking at...
chicken.origin = PlayerEntity(index_from_userid(game_event.get_int(
'userid'))).get_view_coordinates()

# Finally, spawn the chicken entity...
spawn_entity(chicken.index)


@Event
def other_death(game_event):
"""Fired when a non-player entity is dying."""

# Make sure the entity was a chicken...
if game_event.get_string('othertype') != 'chicken':
return

# Get the attacker's userid...
userid = game_event.get_int('attacker')

# Make sure the attacker was a player...
if not userid:
return

# Get a PlayerEntity instance of the attacker...
attacker = PlayerEntity(index_from_userid(game_event.get_int('attacker')))

# Display a message...
SayText2(message='{0} killed a chicken (index: {1}).'.format(
attacker.name, game_event.get_int('otherid'))).send()
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Apr 01, 2015 1:23 pm

Wow, that event just got added by the most recent update!! I still had the old server files (last attempted update would have been last week some time), and that event did not exist in the .res files.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Apr 01, 2015 1:53 pm

Glad to see I'm not crazy! I did update my test server before posting the first code and had to update it again before posting the second one and I was wondering why I did not notice this event earlier. So, it surely got added between both codes, they are listening to you, petros789!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 118 guests