Raised This Month: $32 Target: $400
 8% 

Solved Identity crisis


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-01-2021 , 13:55   Identity crisis
Reply With Quote #1

INTRO:
Hello there!
I've been working on plugin that logs ingame events into a txt file for tf2 competitive purposes.
I am new to sourcemod and sourcepawn.

CONTEXT:
While programming the events I have stumbled across various ways that tf2 returns player ids as default returns in those functions.

Examples:
event player_death - > short userid //user ID who died

teamplay_capture_blocked - > byte blocker //index of the player that blocked the cap

player_extinguished - > byte victim //entindex of the player that was extinguished

killed_capping_player - > byte victim //index of the victim

Question:
Why do they differ?
How do they differ?
How do I convert each of them efficiently to SteamId64?

Bonus question:
In teamplay_point_captured there is:
string cappers //string where each character is a player index of someone that capped
It returns SMILEY FACE in server console. WHY?

OUTRO:
It has been one month with my adventure with sourcepawn. Is it the source that is so inconsistent or just the TF2 it self. I dont know, but its tough. Your help is very appreciated.

Last edited by Cieniu97; 10-02-2021 at 14:08.
Cieniu97 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-01-2021 , 20:10   Re: Identity crisis
Reply With Quote #2

here start
[TF2] Capture point message


...to convert Steamid64 ?

https://sm.alliedmods.net/new-api/cl...ientAuthString
https://sm.alliedmods.net/new-api/clients/AuthIdType

PHP Code:
char auth[MAX_NAME_LENGTH];
GetClientAuthId(clientAuthId_SteamID64authsizeof(auth)); 
*edit
Just ask more if you have difficulty.
Someone who have time to post here can help you.

Last edited by Bacardi; 10-01-2021 at 20:17.
Bacardi is offline
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-02-2021 , 06:07   Re: Identity crisis
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
Thank you! I have no idea how did you came up with that :>

Quote:
Originally Posted by Bacardi View Post
...to convert Steamid64 ?

https://sm.alliedmods.net/new-api/cl...ientAuthString
https://sm.alliedmods.net/new-api/clients/AuthIdType

PHP Code:
char auth[MAX_NAME_LENGTH];
GetClientAuthId(clientAuthId_SteamID64authsizeof(auth)); 
I am familiar with that function, but it only works with my first example with is userid. It does not work for the rest of them

I wrote this function for the userid.

PHP Code:
char[] getSteam64(int userId)
{
    
char userSteam64Id[64];
    
// This is to prevent tf2 sending inputs like -1 for no client or no user.
    // It happens for example in player_death event where there was no assister in death so tf2 sends userid as -1 which crashed the function
    
if (userId <= 0){
        
userSteam64Id "0";
        return 
userSteam64Id;
    }
    
int userRealId GetClientOfUserId(userId);
    
    
GetClientAuthId(userRealIdAuthId_SteamID64userSteam64Idsizeof(userSteam64Id), true);
    return 
userSteam64Id;

Cieniu97 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-02-2021 , 09:59   Re: Identity crisis
Reply With Quote #4

ok, good function.

But you need little bit understand more about userid's and client index's.

client index
or player index are entity index but, server allocate first numbers 1 to MaxClients for clients only.
- Those are like server slots.
Maximum number is 64 in SRCDS, it depends game and server -maxplayers setting.
TF2 game is limited to max. 32 slot.


Entity index 0 is "world" or error or server console.


Userid's other hand are like "train tickets", helps you keep track of that same person on server.
Every time when player connect to server, he get new ticket, ticket count increase by 1 every connection.
Same ticket number last as long as player not disconnect or reconnect from server.
Userid max number is 65 535, after that it rolls back to 1
status from console



- You get userids mostly from game events and you can use it for targeting specific player more easy.
Not need play with player names or steamid for simple task.

- You handle client indexs most of time in coding, because it's good use for as array index and SM functions are using as well.
And you have 64 possible options or less, to find clients.

-------------------------------------------------------------------

About byte you get in TF2 game events,
I assume it's easy way to send list of client indexs, in one event message, to all players from server.
String message works as array, using hex numbers to separate each client. \x01\x04\x0A
If you print on server console, it show as symbols of course. ASCII codes ?

What you need to do is convert char byte to integer.
PHP Code:
    char charbuffer[] = "a letter is number 97"
    
int integervariable charbuffer[0]; 

sample TF2 event, byte to int
__________________
Do not Private Message @me

Last edited by Bacardi; 10-02-2021 at 10:06. Reason: can't use sizeof() on dynamic array
Bacardi is offline
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-02-2021 , 14:08   Re: Identity crisis
Reply With Quote #5

You are the goat!
Thanks for clarification. Now I understand
It helped me dig deeper into documentation.

Summary of topic:
It turned out that in game TF2 events provide 2 types of user reference number.
First is short userid and second is user entindex. They are poorly written into documentation and names for them are inconssistant, so one can stumbble across for example: byte user index or byte victim ent index. They are named differently but they are the same user ent index.

Answering this question. How do I convert each of them efficiently to SteamId64?
I posted function that converts userid 2 post above.
Here is function that converts byte ENT INDEX into steamID64

PHP Code:
char[] getSteam64FromIndex(int index)
{
    
char userSteam64Id[64];
    
// This is to prevent tf2 sending inputs like -1 for no client or no user.
    // It happens for example in player_death event where there was no assister in death so tf2 sends userid as -1 which crashed the function
    
if (index <= 0){
        
userSteam64Id "0";
        return 
userSteam64Id;
    }
    
    
int userRealId GetClientOfUserId(GetClientUserId(index));
    
    
GetClientAuthId(userRealIdAuthId_SteamID64userSteam64Idsizeof(userSteam64Id), true);
    return 
userSteam64Id;

Function that resolves bonus question problem is posted by Bacardi.

The true mystery still remains. Why there is smiley face there
Cieniu97 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 10-03-2021 , 13:31   Re: Identity crisis
Reply With Quote #6

Quote:
Originally Posted by Cieniu97 View Post
Bonus question:
In teamplay_point_captured there is:
string cappers //string where each character is a player index of someone that capped
It returns SMILEY FACE in server console. WHY?
You were presumably the only client on the server where you tested it, so you would have been index 1, so the "string" would have been [0x01, 0x00] (if you think of it as an array) - where 0x01 was your client index and 0x00 marked the end of the string (C / SourcePawn uses null terminated strings).

Printing the "character" with the value 0x01 to the Windows console will display a smiley face.
__________________
asherkin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:00.


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