Player index / userid

General discussion for off-topic subjects.
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Player index / userid

Postby Tuck » Wed Aug 08, 2012 6:07 pm

Whats the difference?

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


"player_hurt"
{
"userid" "short" // player index who was hurt
"attacker" "short" // player index who attacked
"health" "byte" // remaining health points
"armor" "byte" // remaining armor points
"weapon" "string" // weapon name attacker used, if not the world
"dmg_health" "short" // damage done to health
"dmg_armor" "byte" // damage done to armor
"hitgroup" "byte" // hitgroup that was damaged
}


A second question would be whats the difference between "player_spawned" and "player_spawn" events ??
-Tuck
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Wed Aug 08, 2012 6:24 pm

Uh, I think player_hurt still returns the userid. Might have changed in go though.

Player index: Unique index of the player entitiy in the world (1-<maxplayers> are reserved for the player entites). Once a player leaves, a new player might get his *index*
Userid: Incremental ID of the user ever since the server started. Userids are assigned on connect and will never be assigned twice
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Wed Aug 08, 2012 6:28 pm

Omega_K2 wrote:Uh, I think player_hurt still returns the userid. Might have changed in go though.

Player index: Unique index of the player entitiy in the world (1-<maxplayers> are reserved for the player entites). Once a player leaves, a new player might get his *index*
Userid: Incremental ID of the user ever since the server started. Userids are assigned on connect and will never be assigned twice


Witch would you recommend using ?
-Tuck
Absolute
Junior Member
Posts: 13
Joined: Sat Jul 07, 2012 6:48 pm

Postby Absolute » Wed Aug 08, 2012 8:43 pm

It depends on what you want to do, the cool thing with indices is that you can read out the properties of the player like you would do with any entity, the userid on the other hand will always be unique (till the server restarts).
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Aug 09, 2012 12:11 am

I'm fairly certain the userid does return the userid of the victim in both cases, but I will test to verify that in a few.

As for the player_spawned event, I am not sure. I have a script that I always have loaded, to verify which events have been used, and both of the two events have been fired. I will have to do some testing to find out when each one does fire.

Just for reference, and in case anyone else wishes to do this as well, here is the script I use:

Syntax: Select all

import os.path
from events.manager import EventRegistry

all_set = set()
used_set = set()
basepath = os.path.dirname(__file__)
datapath = os.path.join(basepath, 'data')
all_file = os.path.join(datapath, 'all.txt')
used_file = os.path.join(datapath, 'used.txt')
unused_file = os.path.join(datapath, 'unused.txt')


def load():
'''Called when the script loads'''

# Load the all file into the all set
load_set(all_set, all_file)

# Does the used file exist?
if os.path.isfile(used_file):

# Load the used file into the used set
load_set(used_set, used_file)

# Get the difference between the two sets
unused = all_set.difference(used_set)

# Loop through each value in the unused set
for event_name in unused:

# Register the event to the test function
EventRegistry.RegisterForEvent(event_name, test_function)

# Store the difference in the unused file
save_set(unused, unused_file)


def load_set(set_object, file_name):
'''Loads the given filename into the given set object'''

# Open the file
with open(file_name) as open_file:

# Read the used files lines
read_lines = open_file.readlines()

# Loop through each line
for line in read_lines:

# Strip the line of the \n character
stripped_line = line.rstrip()

# Add the line to the used set
set_object.add(stripped_line)


def save_set(set_object, file_name):
'''Saves the given set object to the given file'''

# Get a list object for the given set
list_object = list(set_object)

# Sort the list
list_object.sort()

# Open the file
with open(file_name, 'w') as open_file:

# Write the set to the file
open_file.write('\n'.join(list_object))


def test_function(game_event):
'''Called when an event has been called for the first time'''

# Get the name of the event
name = game_event.GetName()

# Print messages about adding the event
print('=======================')
print('Event Counter Adding:')
print(name)
print('=======================')

# Unregister the event
EventRegistry.UnregisterForEvent(name, test_function)

# Add the event to the used set
used_set.add(name)

# Update the used file with the new event
save_set(used_set, used_file)

# Get the difference between the two sets
unused = all_set.difference(used_set)

# Update the unused file to remove the new event
save_set(unused, unused_file)
I used IDLE to loop through the 5 *events.res files and store all of the events (only 1 instance of each if any are in multiple files) and placed that file in ../addons/source-python/mytest/data/all.txt then put "sp_load mytest" in my autoexec.cfg file. There are 211 total events in the *events.res files and so far I have been able to get 94 to fire.

Satoon

Return to “Whatever”

Who is online

Users browsing this forum: No registered users and 4 guests