Raised This Month: $51 Target: $400
 12% 

A request to adapt the code to the new syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
szogun
Senior Member
Join Date: Apr 2016
Old 09-29-2018 , 08:28   A request to adapt the code to the new syntax
Reply With Quote #1

Hello
I need help to adapt the snippet of code to the new syntax, but unfortunately I do not know much about it and I am trying to make updates to the plugin which is slightly modified

HTML Code:
public Action:CMD_RankRank(client,args){
	if(!g_bEnabled || client == 0 || !IsClientInGame(client))
		return Plugin_Handled;

	new String:arg1[5];
	GetCmdArg(1,arg1,sizeof(arg1));
	if(!StrEqual(arg1,"") && StringToInt(arg1) != 0){
		ShowTopRank(client,StringToInt(arg1));
	}	else {
		ShowTopRank(client,0);
	}
	return Plugin_Handled;
}

ShowTopRank(client,at){
	if(client == 0 || !IsClientInGame(client))
		return;
	new Handle:Datapack= CreateDataPack();
	
	WritePackCell(Datapack,client);
	
	if(at>0){
		WritePackCell(Datapack,at-1);
	}	else {
		WritePackCell(Datapack,0);
		at = 1; // For not needing to build twice the query. (for at > 0 and at <= 0)
	}
	new String:query[2000];
	MakeSelectQuery(query,sizeof(query));
	Format(query,sizeof(query),"%s ORDER BY rank DESC, score DESC LIMIT %i, 10",query,at-1);
		
	SQL_TQuery(g_hStatsDb,SQL_TopRankCallback,query,Datapack);

}

public SQL_TopRankCallback(Handle:owner, Handle:hndl, const String:error[], any:Datapack){
	if(hndl == INVALID_HANDLE)
	{
		LogError("[RankMe] Query Fail: %s", error);
		PrintToServer(error);
		return;
	}
	ResetPack(Datapack);
	new i;
	new client = ReadPackCell(Datapack);
	if(client == 0 || !IsClientInGame(client))
		return;
	new at = ReadPackCell(Datapack);
	CloseHandle(Datapack);
	if(!SQL_HasResultSet(hndl) || SQL_GetRowCount(hndl) ==0){
		ShowTopRank(client,g_TotalPlayers-9);
		return;
	}
	new String:name[256];
	new String:temp[500];
	
	new Handle:menu = CreateMenuEx(GetMenuStyleHandle(MenuStyle:MenuStyle_Radio),MenuHandler_Rank);
	
	Format(temp,sizeof(temp)," %T\n","Showing",client,at+1,at+10,g_TotalPlayers);
	SetMenuTitle(menu,"[#TOP] Nick - Ranga - Punkty");
	new String:sBuffer[200];
	while(SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
	{
		
		i++;
		
		SQL_FetchString(hndl,2,name,sizeof(name));
			
		
	
		Format(sBuffer,sizeof(sBuffer),"#%d - %s - %s - [%d]\n",i+at,name, g_sRanksNames[SQL_FetchInt(hndl,78)],SQL_FetchInt(hndl,4));
		
		if(strlen(temp)+strlen(sBuffer) < MAX_LENGTH_MENU){
			Format(temp,sizeof(temp),"%s%s",temp,sBuffer);
			sBuffer="\0";
		}
	} 
	Format(temp,sizeof(temp),"%s\n ",temp);
	AddMenuItem(menu,temp,temp);
	
	
	IntToString(at+i,temp,sizeof(temp));
	new String:temp1[20];
	Format(temp1,sizeof(temp1),"%T","Next",client);
	if(i>9)
		AddMenuItem(menu,temp,temp1);
	IntToString(at-i,temp,sizeof(temp));
	Format(temp1,sizeof(temp1),"%T","Back",client);
	if(at+i-1 >9)
		AddMenuItem(menu,temp,temp1);

	DisplayMenuAtItem(menu,client,at,MENU_TIME_FOREVER);
}

public Action:CMD_RankScore(client,args){
	if(!g_bEnabled || client == 0 || !IsClientInGame(client))
		return Plugin_Handled;

	new String:arg1[5];
	GetCmdArg(1,arg1,sizeof(arg1));
	if(!StrEqual(arg1,"") && StringToInt(arg1) != 0){
		ShowTopScore(client,StringToInt(arg1));
	}	else {
		ShowTopScore(client,0);
	}
	return Plugin_Handled;
}

ShowTopScore(client,at){
	if(client == 0 || !IsClientInGame(client))
		return;
	new Handle:Datapack= CreateDataPack();
	
	WritePackCell(Datapack,client);
	
	if(at>0){
		WritePackCell(Datapack,at-1);
	}	else {
		WritePackCell(Datapack,0);
		at = 1; // For not needing to build twice the query. (for at > 0 and at <= 0)
	}
	new String:query[2000];
	MakeSelectQuery(query,sizeof(query));
	Format(query,sizeof(query),"%s ORDER BY score DESC LIMIT %i, 10",query,at-1);
		
	SQL_TQuery(g_hStatsDb,SQL_TopScoreCallback,query,Datapack);

}

public SQL_TopScoreCallback(Handle:owner, Handle:hndl, const String:error[], any:Datapack){
	if(hndl == INVALID_HANDLE)
	{
		LogError("[RankMe] Query Fail: %s", error);
		PrintToServer(error);
		return;
	}
	ResetPack(Datapack);
	new i;
	new client = ReadPackCell(Datapack);
	if(client == 0 || !IsClientInGame(client))
		return;
	new at = ReadPackCell(Datapack);
	CloseHandle(Datapack);
	if(!SQL_HasResultSet(hndl) || SQL_GetRowCount(hndl) ==0){
		ShowTopScore(client,g_TotalPlayers-9);
		return;
	}
	new String:name[256];
	new String:temp[500];
	
	new Handle:menu = CreateMenuEx(GetMenuStyleHandle(MenuStyle:MenuStyle_Radio),MenuHandler_ScoreKills);
	
	Format(temp,sizeof(temp)," %T\n","Showing",client,at+1,at+10,g_TotalPlayers);
	SetMenuTitle(menu,"[#TOP] Nick - Ranga - Punkty");
	new String:sBuffer[200];
	while(SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
	{
		
		i++;
		
		SQL_FetchString(hndl,2,name,sizeof(name));
			
		
	
		Format(sBuffer,sizeof(sBuffer),"#%d - %s - %s - [%d]\n",i+at,name, g_sRanksNames[SQL_FetchInt(hndl,78)],SQL_FetchInt(hndl,4));
		
		if(strlen(temp)+strlen(sBuffer) < MAX_LENGTH_MENU){
			Format(temp,sizeof(temp),"%s%s",temp,sBuffer);
			sBuffer="\0";
		}
	} 
	Format(temp,sizeof(temp),"%s\n ",temp);
	AddMenuItem(menu,temp,temp);
	
	
	IntToString(at+i,temp,sizeof(temp));
	new String:temp1[20];
	Format(temp1,sizeof(temp1),"%T","Next",client);
	if(i>9)
		AddMenuItem(menu,temp,temp1);
	IntToString(at-i,temp,sizeof(temp));
	Format(temp1,sizeof(temp1),"%T","Back",client);
	if(at+i-1 >9)
		AddMenuItem(menu,temp,temp1);

	DisplayMenuAtItem(menu,client,at,MENU_TIME_FOREVER);
}
szogun is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 09-29-2018 , 09:31   Re: A request to adapt the code to the new syntax
Reply With Quote #2

try this
https://forums.alliedmods.net/showthread.php?t=290805
__________________
8guawong is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 09-29-2018 , 12:00   Re: A request to adapt the code to the new syntax
Reply With Quote #3

PHP Code:
public Action CMD_RankRank(int clientint args){
    if(!
g_bEnabled || client == || !IsClientInGame(client))
        return 
Plugin_Handled;

    
char arg1[5];
    
GetCmdArg(1,arg1,sizeof(arg1));
    if(!
StrEqual(arg1,"") && StringToInt(arg1) != 0){
        
ShowTopRank(client,StringToInt(arg1));
    }    else {
        
ShowTopRank(client,0);
    }
    return 
Plugin_Handled;
}

ShowTopRank(int clientint at){
    if(
client == || !IsClientInGame(client))
        return;
    
DataPack pk= new DataPack();
    
    
pk.WriteCell(client);
    
    if(
at>0){
        
pk.WriteCell(at 1);
    }    else {
        
pk.WriteCell(0);
        
at 1// For not needing to build twice the query. (for at > 0 and at <= 0)
    
}
    
char query[2000];
    
MakeSelectQuery(query,sizeof(query)); // ???
    
Format(query,sizeof(query),"%s ORDER BY rank DESC, score DESC LIMIT %i, 10",query,at-1);
        
    
SQL_TQuery(g_hStatsDb,SQL_TopRankCallback,query,Datapack);


so basically:

new string:asd becomes char asd[length] (like c++)
datapack has a constructor (it's a class)
in function you must specify the type of the data (int client, int args)
public Action:CMD becomes public Action CMD

if you know c++, it's very easy to write plugins in the new syntax.
use #pragma newdecls required
before or after include <sourcemod> and the compiler will tell at what line you must change the code
Ilusion9 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 09-29-2018 , 12:08   Re: A request to adapt the code to the new syntax
Reply With Quote #4

I was very bored at work, try this:
edit: Ilusion9 beat me. and he use methodmaps.
Spoiler


and take a look here: https://forums.alliedmods.net/showthread.php?t=244092
__________________
coding & free software

Last edited by shanapu; 09-29-2018 at 12:10. Reason: edit
shanapu is offline
szogun
Senior Member
Join Date: Apr 2016
Old 09-30-2018 , 06:49   Re: A request to adapt the code to the new syntax
Reply With Quote #5

Thanks, just now I can not figure out why it does not compile

HTML Code:
Handle menu = CreateMenuEx(GetMenuStyleHandle(MenuStyle MenuStyle_Radio),MenuHandler_Rank);
Quote:
// E:\Download\firefox\sourcemod-1.9.0-git6252-windows\scripting\include\kento_rankme/cmds.inc(1044) : warning 217: loose indentation
// E:\Download\firefox\sourcemod-1.9.0-git6252-windows\scripting\include\kento_rankme/cmds.inc(1044) : error 001: expected token: ",", but found "-identifier-"
// E:\Download\firefox\sourcemod-1.9.0-git6252-windows\scripting\include\kento_rankme/cmds.inc(1044) : warning 215: expression has no effect
// E:\Download\firefox\sourcemod-1.9.0-git6252-windows\scripting\include\kento_rankme/cmds.inc(1044) : error 001: expected token: ";", but found ")"
// E:\Download\firefox\sourcemod-1.9.0-git6252-windows\scripting\include\kento_rankme/cmds.inc(1044) : error 029: invalid expression, assumed zero
// E:\Download\firefox\sourcemod-1.9.0-git6252-windows\scripting\include\kento_rankme/cmds.inc(1044) : fatal error 190: too many error messages on one line

Last edited by szogun; 09-30-2018 at 06:50.
szogun is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 09-30-2018 , 09:26   Re: A request to adapt the code to the new syntax
Reply With Quote #6

PHP Code:
Menu menu = new Menu(MenuHandler_RankMENU_ACTIONS_ALL); 
https://sm.alliedmods.net/new-api/menus/Menu
Ilusion9 is offline
szogun
Senior Member
Join Date: Apr 2016
Old 09-30-2018 , 13:49   Re: A request to adapt the code to the new syntax
Reply With Quote #7

Unfortunately, I do not know how to deal with it
I tried it and I still have mistakes

Quote:
Handle menu = CreateMenuEx(GetMenuStyleHandle(MenuStyle, MenuStyle_Radio), Menu_Handler_Rank);
Code:
Handle menu = CreateMenuEx(GetMenuStyleHandle(MenuStyle_Radio),MenuHandler_Rank);

Last edited by szogun; 09-30-2018 at 13:49.
szogun is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-01-2018 , 06:33   Re: A request to adapt the code to the new syntax
Reply With Quote #8

Quote:
Originally Posted by szogun View Post
Unfortunately, I do not know how to deal with it
I tried it and I still have mistakes



Code:
Handle menu = CreateMenuEx(GetMenuStyleHandle(MenuStyle_Radio),MenuHandler_Rank);
because Handle menu is old syntax. the type of menus is Menu, not Handle.
Ilusion9 is offline
Reply



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 17:24.


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