Scripting questions :/

Please post any questions about developing your plugin here. Please use the search function before posting!
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Scripting questions :/

Postby Tuck » Sat Aug 04, 2012 3:26 pm

I'm in the making of a script that could iventually lag the server with effects / sql statements

I've tried once before in CSS, to use Threads but apperently sql didnt like 2 statements executed on the same time, but since im pretty sure a lot of you people on here have more experience than me i would like to hear your ideas :)

Another question would has there come some more examples that works, i would love to see some more examples for like creating a menu, cool text messages in colors and such ;)
-Tuck
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Sat Aug 04, 2012 3:51 pm

Tuck wrote:I'm in the making of a script that could iventually lag the server with effects / sql statements

I've tried once before in CSS, to use Threads but apperently sql didnt like 2 statements executed on the same time, but since im pretty sure a lot of you people on here have more experience than me i would like to hear your ideas :)

Another question would has there come some more examples that works, i would love to see some more examples for like creating a menu, cool text messages in colors and such ;)


Well to answer you question about threads, Python threads are not great because of what we call the Global Interpreter Lock (GIL). Essentially, whenever a thread drops down into Python's internal C++ code, it "locks" Python so that only that one thread can execute code. This is to prevent two threads running the same code which may cause serious problems.

Secondly, you need to make sure your code is thread safe. If you're running two write queries, one per thread on your database, you're gonna have a bad time :P

To answer your last question, we definitely plan to release examples. We're still trying to get the C++ core up and running because without that, the rest of Source.Python is useless. I plan on releasing a quick build today. I hope to write a few quick examples too.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Sat Aug 04, 2012 6:09 pm

What about multiprocessing to solve the GIL issue?

I always wanted to use it in ES, but the module was introduced in py2.6, while ES was stuck on py2.5.
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Sat Aug 04, 2012 6:15 pm

Doldol wrote:What about multiprocessing to solve the GIL issue?

I always wanted to use it in ES, but the module was introduced in py2.6, while ES was stuck on py2.5.


I've personally never used it so I can't speak to its effectiveness. It does exist with in Source.Python however as it is compiled in the build process. Feel free to experiment and let us know what you come up with!

(note: I'd experiment myself but I'm busy with writing the core and doing documentation :P)
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sat Aug 04, 2012 7:37 pm

I would look into that ;)

Or else my approach would propperly be having a process queue parralel to the main thread so the queue in the parralel thread would handle all sql statements "inherited" from main thread or something
-Tuck
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Tue Aug 07, 2012 4:42 pm

do anyone have a complete list of variables to retrieve from game events ? :/ and a quick example how to with source python, thanks in advance
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 07, 2012 5:54 pm

We are planning on adding the events to the wiki, but have not gotten around to it yet. For now, to get the events yourself, download the newest version of GCFScape and use it to open your ../Steam/steamapps/common/Counter-Strike Global Offensive/csgo/pak01_dir.vpk file. Inside there, go into the "resource" folder and look for the following files:

  • gameevents.res
  • hltvevents.res
  • modevents.res
  • replayevents.res
  • serverevents.res

You more than likely will not need to worry about the hltvevents and replayevents files, as those are specific to HLTV and the replay system. Open the other 3 up, and they will each have events with all of the event variables they return. Any events found in the modevents file will override the ones from the gameevents and serverevents files, as they basically extend the functionality of the given event. For instance, gameevents shows player_death as:

Code: Select all

   "player_death"            // a game event, name may be 32 charaters long
   {
      "userid"   "short"      // user ID who died            
      "attacker"   "short"       // user ID who killed
   }


So, if the current game (in this instance csgo) does not override this event, it will only return those 2 variables. Instead, in the modevents file, it overrides and adds quite a few event variables:

Code: Select all

   "player_death"            // a game event, name may be 32 characters long
   {
      // this extents the original player_death by a new fields
      "userid"   "short"      // user ID who died            
      "attacker"   "short"       // user ID who killed
      "assister"   "short"       // user ID who assisted in the kill
      "weapon"   "string"    // weapon name killer used
      "headshot"   "bool"      // singals a headshot
      "dominated"   "short"      // did killer dominate victim with this kill
      "revenge"   "short"      // did killer get revenge on victim with this kill
      "penetrated" "short"   // number of objects shot penetrated before killing target
   }


To use this event in Source.Python to print a HudHint message to the victim telling them the weapon they were killed with, you could use something like:

Syntax: Select all

from Source import Engine
from Source import Shared

from events.decorator import Event

# Get the GameEngine instance
GameEngine = Engine.GetEngine()

@Event
def player_death(GameEvent):
# Get the attacker's weapon
weapon = GameEvent.GetString('weapon')

# Get the victim's userid
victim = GameEvent.GetInt('userid')

# Get the player's index
# In the future, this will be much more simplified, but for now we need to do it this way

# Loop through all player indexes (1 - 64, since 64 is the max allowed and no other entity will ever have any of these indexes)
for index in range(1, 65):

# Get the current player's entity
entity = Engine.PEntityOfEntIndex(index)

# Get the current player's userid
userid = GameEngine.GetPlayerUserId(entity)

# Is this the userid we are looking for?
if userid == victim:

# If so, break the loop here, so that the index is set to the correct value
break

# Create a RecipientFilter
Recipients = Shared.MRecipientFilter()

# Add the player to the RecipientFilter
Recipients.AddRecipient(index)

# Create the HudHint message
# The RecipientFilter is the first argument
# The UserMessage type is the second argument
# The third argument is supposed to be the name of the UserMessage type,
# but that never seems to matter, so I always just give it None
UserMessage = GameEngine.UserMessageBegin(Recipients, 24, None)

# Write the message to the HudHint
UserMessage.WriteString('You were killed by a "%s"' % weapon)

# Send the HudHint
GameEngine.MessageEnd()
Many of the parts in this example will be much easier once development of the Python API gets further along.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Wed Aug 08, 2012 8:09 pm

Thanks that really took me far :)

If you have time could you show me how to write a text message in chat with color like ES Saytext2/Saytext and maybe how to catch what a client types in console :)
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Aug 09, 2012 1:29 am

We don't have Client Command filtering yet, so we cannot hook that as of right now.

As for SayText(2), it will be easier once our messaging system is a little further along (right now I am working on a PlayerFilter/RecipientFilter system which is slowing progress of the messaging system), it will be much easier. For now, you can use something like (I am still having issues getting the first color to be the correct color all the time):

Syntax: Select all

from Source import Engine
from Source import Shared

from core.base import GameEngine
from events.decorator import Event


@Event
def player_death(GameEvent):

# Get the victim's userid
victim = GameEvent.GetInt('userid')

# Get the killer's userid
killer = GameEvent.GetInt('attacker')

# Store the indexes as None for future reference
vindex = None
kindex = None

# Loop through all possible player indexes on the server
for index in range(65):

# Get the current indexes entity
entity = Engine.PEntityOfEntIndex(index)

# Get the current indexes userid
userid = GameEngine.GetPlayerUserid(entity)

# Is this the victim's userid?
if userid == victim:

# Set the victim's index as the current one
vindex = index

# Is this the killers's userid?
if userid == killer:

# Set the victim's index as the current one
kindex = index

# Do we have both the killer's index and the victim's index?
if vindex is None or kindex is None:

# If we do not have both, simply return
return

# Get a RecipientFilter
Recipients = Shared.MRecipientFilter()

# Add the victim's index to the RecipientFilter
Recipients.AddRecipient(vindex)

# Create the SayText2 message
UserMessage = GameEngine.UserMessageBegin(Recipients, 4, 'SayText2')

# Give the killer's index to the UserMessage
UserMessage.WriteByte(kindex)

# Get the weapon used to kill
weapon = GameEvent.GetString('weapon')

# Add the string message to the UserMessage
UserMessage.WriteString('\x01You were killed by a\x04"\x03%s\x04"' % weapon)

# Send the message and clean up
GameEngine.MessageEnd()


Using a slightly similar script, I managed to test what would happen by giving a Terrorist index, CT index, 0, and -1 as the index for the SayText2 messages (using \x01 - \x07) and these are the results:



It can be difficult to tell, but these are the findings:
  • \x01 - White
  • \x02 - Dark Red
  • \x03 -
    • For T indexes is Off-White/Light Brown
    • For CT indexes is very Light Blue
    • For 0 and -1 are White (like \x01)
  • \x04 - Green
  • \x05 - Pale Green
  • \x06 - Light Green
  • \x07 - Red
I really hope that at some point they add in what was recently added to all OrangeBox games, where you can set the RGBA values yourself, and have many more combinations!!! But, I am not sure if they will do that. I would settle for them making the T and CT colors more pronounced, making 0 be more like the old #lightgreen, and making -1 Grey (like in CS:S).

Satoon
Attachments
SayText2.jpg
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Thu Aug 09, 2012 7:59 pm

satoon101 wrote:We don't have Client Command filtering yet, so we cannot hook that as of right now.


When would this be added, i'm working on a project for the cs:go release and would love the feature :P
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Thu Aug 09, 2012 8:18 pm

Tuck wrote:When would this be added, i'm working on a project for the cs:go release and would love the feature :P


We will get it working in a timely fashion.. I can't give you an ETA or anything, we have a lot on our to-do list!
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Thu Aug 23, 2012 3:00 pm

Monday wrote:We will get it working in a timely fashion.. I can't give you an ETA or anything, we have a lot on our to-do list!


Any updates on "Client Command filtering" yet?
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Thu Aug 23, 2012 3:45 pm

Tuck wrote:Any updates on "Client Command filtering" yet?


We will make an announcement when we release new functionality, until then.. sit tight and be patient.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 29 guests