AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Identity crisis (https://forums.alliedmods.net/showthread.php?t=334526)

Cieniu97 10-01-2021 13:55

Identity crisis
 
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.

Bacardi 10-01-2021 20:10

Re: Identity crisis
 
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.

Cieniu97 10-02-2021 06:07

Re: Identity crisis
 
Quote:

Originally Posted by Bacardi (Post 2759377)

Thank you! I have no idea how did you came up with that :>

Quote:

Originally Posted by Bacardi (Post 2759377)
...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;



Bacardi 10-02-2021 09:59

Re: Identity crisis
 
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

Cieniu97 10-02-2021 14:08

Re: Identity crisis
 
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 :)

asherkin 10-03-2021 13:31

Re: Identity crisis
 
Quote:

Originally Posted by Cieniu97 (Post 2759349)
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.


All times are GMT -4. The time now is 10:50.

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