PDA

View Full Version : return handle from native


mjmfighter
01-28-2012, 14:31
I am trying to return a handle from a native call, but every time i compile i get a tag mismatch warning. Will this cause problems, or should I just ignore it? or is it just not possible to return a handle from a native call?

Impact123
01-28-2012, 14:55
Post your whole code.

Yours sincerely
Impact

mjmfighter
01-28-2012, 15:00
Here ya go, line 138 gives the mismatch error

#include <sourcemod>

public Plugin:myinfo =
{
name = "VIP Base Plugin",
author = "mjmfighter",
description = "VIP Base Plugin",
version = "0.1",
url = "sntgaming.org"
};

new Handle:menu_items;
new Handle:menu_items_plugins;
new Handle:db = INVALID_HANDLE;
new bool:donator_clients[MAXPLAYERS+1] = {false,...};

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("VIP_AddMenuItem", Native_VIP_AddMenuItem);
CreateNative("VIP_RemoveMenuItem", Native_VIP_RemoveMenuItem);
CreateNative("VIP_IsDonator", Native_VIP_IsDonator);
CreateNative("VIP_GetDatabase", Native_VIP_GetDatabase);
RegPluginLibrary("VIP_Base");
return APLRes_Success;
}

public OnPluginStart()
{
RegConsoleCmd("sm_vip", VIP_CallBack);
menu_items = CreateArray(250);
menu_items_plugins = CreateArray();
SQL_TConnect(VIP_DatabaseCallback, "VIP_Database");
}

public VIP_DatabaseCallback(Handle:owner, Handle:hndl, const String:error[], any:data){
if(hndl == INVALID_HANDLE){
LogError("Database failure: %s", error);
}else{
db = hndl;
}
}

public OnClientPostAdminCheck(client){
if(db == INVALID_HANDLE)
return;
new String:steam[250];
GetClientAuthString(client, steam, sizeof(steam));
new String:query[250];
Format(query, sizeof(query), "SELECT timeleft FROM vip_donators WHERE authid='%s' AND timeleft > UNIX_TIMESTAMP()", steam);
SQL_TQuery(db, VIP_DonatorCallback, query, client);
}

public VIP_DonatorCallback(Handle:owner, Handle:hndl, const String:error[], any:data){
if(!IsClientConnected(data))
return;
LogAction(-1, -1, "Row Count: %d", SQL_GetRowCount(hndl));
if(hndl == INVALID_HANDLE || SQL_GetRowCount(hndl) < 1)
donator_clients[data] = false;
else
donator_clients[data] = true;
return;
}

public Action:VIP_CallBack(client, args){
if(!donator_clients[client]){
PrintToChat(client, "You are not a donator!");
return Plugin_Handled;
}

if(GetArraySize(menu_items) < 1){
PrintToChat(client, "ERROR: No VIP Items Avaliable!");
return Plugin_Handled;
}

new Handle:menu = CreateMenu(VIP_MenuHandler);
SetMenuTitle(menu, "VIP Menu");
for(new i=0;i<GetArraySize(menu_items);i++){
new String:info[250];
GetArrayString(menu_items, i, info, sizeof(info));
AddMenuItem(menu, info, info);
}

DisplayMenu(menu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}

public VIP_MenuHandler(Handle:menu, MenuAction:action, param1, param2){
if (action == MenuAction_Select){
new String:info[250];
GetMenuItem(menu, param2, info, sizeof(info));
for(new i=0;i<GetArraySize(menu_items);i++){
new String:menu_text[250];
GetArrayString(menu_items, i, menu_text, sizeof(menu_text));
if(strcmp(info, menu_text) == 0){
new Function:func = GetFunctionByName(GetArrayCell(menu_items_plu gins, i), "VIP_ReturnMenuHandler");
Call_StartFunction(GetArrayCell(menu_items_pl ugins, i), func);
Call_PushCell(param1);
Call_Finish();
break;
}
}
}
else if (action == MenuAction_End){
CloseHandle(menu);
}
}

public Native_VIP_AddMenuItem(Handle:plugin, numParams){
PushArrayCell(menu_items_plugins, plugin);
new String:name[250];
GetNativeString(1, name, sizeof(name));
LogAction(0, -1, name);
PushArrayString(menu_items, name);
}

public Native_VIP_RemoveMenuItem(Handle:plugin, numParams){
new String:name[250];
GetNativeString(1, name, sizeof(name));
for(new i=0;i<GetArraySize(menu_items);i++){
new String:info[250];
GetArrayString(menu_items, i, info, sizeof(info));
if(strcmp(info, name) == 0){
RemoveFromArray(menu_items, i);
RemoveFromArray(menu_items_plugins, i);
}
}
}

public Native_VIP_IsDonator(Handle:plugin, numParams){
new client = GetNativeCell(1);
return donator_clients[client];
}

public Native_VIP_GetDatabase(Handle:plugin, numParams){
return db;
}

Steell
01-28-2012, 15:02
Here ya go, line 138 gives the mismatch error

public Native_VIP_IsDonator(Handle:plugin, numParams){
new client = GetNativeCell(1);
return _:donator_clients[client];
}

public Native_VIP_GetDatabase(Handle:plugin, numParams){
return _:db;
}

mjmfighter
01-28-2012, 15:05
thanks! it works now

rodrigo286
01-18-2015, 10:28
String text works.

VIP_Base.inc


native VIP_AddMenuItem(const String:name[] = "");


But how to pass the menu handle of a plugin to the other with this function?


new Function:func = GetFunctionByName(GetArrayCell(menu_items_plu gins, i), "VIP_ReturnMenuHandler");


Thanks.