View Single Post
Byte
Senior Member
Join Date: Jun 2010
Location: 📦 CCSPlayer
Old 04-14-2017 , 23:31   Re: Convert STEAMID to Steam Community ID
Reply With Quote #352

Don't mean to bump an oldish thread but this might save someone a tiny bit of time later....

Here is the Sourcemod adaption of YamiKaitou's code here with asherkin's tip:
https://forums.alliedmods.net/showpo...&postcount=341
https://forums.alliedmods.net/showpo...&postcount=342

So far its passed all my tests but let me know if you find any issues.

PHP Code:
stock void GetSteamId2(const char[] szSteam64char[] szSteam2int iLen)
{
  
char szBase[18] = "76561197960265728";
  
int iBorrow 0;
  
char szSteam[18];
  
char szAccount[18];
  
int iY 0;
  
int iZ 0;
  
int iTemp 0;
  
  
//Copy steamid64 Over
  
Format(szSteamsizeof(szSteam), szSteam64);
  
  
//Determine iY
  
if (intval(szSteam[16]) % == 1) {
    
iY 1;
    
szSteam[16] = strval(intval(szSteam[16]) - 1);
  }
  
  
//Determine szAccount
  
for (int k 16>= 0; --k) {
    if (
iBorrow 0) {
      
iTemp intval(szSteam[k]) - 1;
      
      if (
iTemp >= intval(szBase[k])) {
        
iBorrow 0;
        
szAccount[k] = strval(iTemp intval(szBase[k]));
      }
      else {
        
iBorrow 1;
        
szAccount[k] = strval((iTemp 10) - intval(szBase[k]));
      }
    }
    else {
      if (
intval(szSteam[k]) >= intval(szBase[k])) {
        
iBorrow 0;
        
szAccount[k] = strval(intval(szSteam[k]) - intval(szBase[k]));
      }
      else {
        
iBorrow 1;
        
szAccount[k] = strval((intval(szSteam[k]) + 10) - intval(szBase[k]));
      }
    }
  }
  
  
//Divide szAccount answer by 2
  
iZ StringToInt(szAccount) / 2;
  
  
//Construct final steam2 id
  
Format(szSteam2iLen"STEAM_1:%d:%d"iYiZ);
}

int strval(const int iNum)
{
  return 
'0' + ((iNum >= && iNum <= 9) ? iNum 0);
}

int intval(int cNum)
{
  return (
cNum >= '0' && cNum <= '9') ? (cNum '0') : 0;

__________________
STEAM: /id/invexbyte | Github: Mo Beigi | Discord: Byte#0017
Community: Invex Gaming | My Plugins: Click Me!

Byte is offline