first upload, simply divides racetimer points by 1000 and says its your level if you dont have a clantag
This commit is contained in:
		
							parent
							
								
									a568b1b7a9
								
							
						
					
					
						commit
						0a398222ae
					
				
							
								
								
									
										101
									
								
								RaceTimer/scripting/racetimer_rank.sp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								RaceTimer/scripting/racetimer_rank.sp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,101 @@ | ||||
| #include <sourcemod> | ||||
| #include <SteamWorks> | ||||
| #include <json> | ||||
| #include <cstrike> | ||||
| 
 | ||||
| public Plugin myinfo = | ||||
| { | ||||
| 	name			= "Racetimer Rank", | ||||
| 	author			= "jenz", | ||||
| 	description		= "Give racetimer points as a level clan tag to players", | ||||
| 	version			= "1.0", | ||||
| 	url				= "" | ||||
| }; | ||||
| 
 | ||||
| public void OnPluginStart() | ||||
| { | ||||
| 	for(int client = 1; client <= MaxClients; client++) | ||||
| 	{ | ||||
| 		if(IsClientInGame(client)) | ||||
| 		{ | ||||
| 			OnClientPostAdminFilter(client); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| public void OnClientPostAdminFilter(int client) | ||||
| { | ||||
|     if(!IsClientAuthorized(client) || IsFakeClient(client) || IsClientSourceTV(client)) | ||||
|         return; | ||||
| 
 | ||||
|     if (!HasClanTag(client)) | ||||
|     { | ||||
|         check_client_racetimer_rank(client); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| public bool HasClanTag(int client) | ||||
| { | ||||
|     char sClanID[32]; | ||||
|     GetClientInfo(client, "cl_clanid", sClanID, sizeof(sClanID)); | ||||
|     return strlen(sClanID) > 1; //without a tag the len is 1. | ||||
| } | ||||
| 
 | ||||
| public void check_client_racetimer_rank(int client) | ||||
| { | ||||
|     char sSID[64]; | ||||
|     char sRequest[256]; | ||||
|     GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); | ||||
|     FormatEx(sRequest, sizeof(sRequest), "https://racebackend.unloze.com/racetimer_endpoints-1.0/api/timers/player/%s", sSID); | ||||
|      | ||||
|     Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest); | ||||
|     if (!hRequest || | ||||
|         !SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) || | ||||
|         !SteamWorks_SetHTTPRequestContextValue(hRequest, GetClientSerial(client)) || | ||||
|         !SteamWorks_SendHTTPRequest(hRequest)) | ||||
|     { | ||||
|         delete hRequest; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| public int OnTransferComplete(Handle hRequest, bool bFailure, bool bSuccessful, EHTTPStatusCode eStatusCode, int iSerial) | ||||
| { | ||||
|     int client = GetClientFromSerial(iSerial); | ||||
|     if (!client) //Player disconnected. | ||||
|     { | ||||
|         delete hRequest; | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK) | ||||
|     { | ||||
|         delete hRequest; | ||||
|         LogError("Request-Error: %d", eStatusCode); | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnTransferResponse, iSerial); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| public int OnTransferResponse(char[] sData, int iSerial) | ||||
| { | ||||
|     int client = GetClientFromSerial(iSerial); | ||||
|     if (!client) //Player disconnected. | ||||
|     { | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     JSON_Object obj = json_decode(sData); //https://github.com/clugg/sm-json | ||||
|      | ||||
|     int I_player_points = obj.GetInt("PlayerPoints") //if no endpoint for steamID default value is -1 | ||||
|     if (I_player_points < 1000) | ||||
|     { | ||||
|         I_player_points = 1000; //setting level 1 | ||||
|     } | ||||
|     char tag[64]; | ||||
|     Format(tag, sizeof(tag), "[LVL %i]", I_player_points/1000); | ||||
|     CS_SetClientClanTag(client, tag); | ||||
|     json_cleanup_and_delete(obj); | ||||
|     return 0; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user