native void SBPP_BanPlayer(int iAdmin, int iTarget, int iTime, const char[] sReason, Handle pack = null);
Implementation:
PHP Code:
public Native_SBBanPlayer(Handle plugin, int numParams) { int client = GetNativeCell(1); int target = GetNativeCell(2); int time = GetNativeCell(3); DataPack pack = view_as<DataPack>(GetNativeCell(5)); pack.Reset(); char reason[128]; GetNativeString(4, reason, 128);
if (reason[0] == '\0') strcopy(reason, sizeof(reason), "Banned by SourceBans");
if (client && IsClientInGame(client)) { AdminId aid = GetUserAdmin(client); if (aid == INVALID_ADMIN_ID) { ThrowNativeError(SP_ERROR_NATIVE, "Ban Error: Player is not an admin."); return 0; }
if (!GetAdminFlag(aid, Admin_Ban)) { ThrowNativeError(SP_ERROR_NATIVE, "Ban Error: Player does not have BAN flag."); return 0; } }
PrepareBan(client, target, time, reason, sizeof(reason), pack); return true; }
When pack.Reset() is called I get this error:
Quote:
L 02/06/2019 - 10:52:35: [SM] Exception reported: Invalid data pack handle 12f00f4 (error 5)
L 02/06/2019 - 10:52:35: [SM] Blaming: sbpp_main.smx
L 02/06/2019 - 10:52:35: [SM] Call stack trace:
L 02/06/2019 - 10:52:35: [SM] [0] DataPack.Reset
L 02/06/2019 - 10:52:35: [SM] [1] Line 2291, sbpp_main.sp::Native_SBBanPlayer
L 02/06/2019 - 10:52:35: [SM] [3] SBPP_BanPlayer
L 02/06/2019 - 10:52:35: [SM] [4] Line 168, disconnect_ban.sp::SQL_SelectSeconds
Powerlord, optional argument not assume change of params count. I think these changes will be overkill.
CliptonHeist, Here is only one thing that i see for now, you don't have check for null handle.
And in this case you definitely pass null. You don't set param -> you default param value -> pass null.