View Single Post
Author Message
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 07-29-2016 , 19:15   [INC] Data String Parameter
Reply With Quote #1

I got tired of having to create data packs manually or convert between strings and handles to be able to pass a string through a data parameter so I made these stocks.

Note: If there's a better method of doing this that already exists, let me know as I would LOVE to know it.
Note2: I know you can convert a handle to a string which you can also do but this seems less like a disaster.

#if defined _data_string_parameter_included_
#define _data_string_parameter_included_ "1.0"

stock Handle AnyString(const char[] sBuffer)
	if (strlen(sBuffer) < 1)
		return null;
	Handle hPack = CreateDataPack();
	WritePackString(hPack, sBuffer);
	return hPack;

stock bool ReadAnyString(Handle hPack, char[] sBuffer, int size)
	if (hPack == null)
		return false;
	ReadPackString(hPack, sBuffer, size);
	return true;
#include <sourcemod>
#include <data_string_parameter>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
	name        = "",
	author      = "",
	description = "",
	version     = "0.0.0",
	url         = ""

public void OnPluginStart()
	char sBuffer[12];
	strcopy(sBuffer, sizeof(sBuffer), "Test");
	SQL_TConnect(OnSQLConnect, "default", AnyString(sBuffer));

public void OnSQLConnect(Handle owner, Handle hndl, const char[] error, any data)
	char sBuffer[12];
	ReadAnyString(data, sBuffer, sizeof(sBuffer));
Attached Files
File Type: inc (501 Bytes, 238 views)
(soon to be) Retired Sourcemod Coder
My [Dev] Website | Discord: Drixevel#5049

Last edited by Drixevel; 07-31-2016 at 13:38.
Drixevel is offline