SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 05/04/2017, 06:35 PM   #361
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 881
Reputation: 459
Default Re: Gamemode SDK for C/C++ (GDK)

Doing the change Wopss wrote is okay, here's the commit that introduced this.

However I'd suggest you incorporate the source of the MySQL plugin R40 or higher directly into your C++ gamemode. I've redesigned the internal API with the potential usage in a sampgdk gamemode back in my mind. Creating a connection, sending a query and processing the result is as easy as this:
Code:
CError<CHandle> handle_error;
Handle_t handle = CHandleManager::Get()->Create(
	"localhost", "root", "pass", "database",
	options, handle_error);

if (handle_error)
{
	// some error happened
	return 0;
}

Query_t query = CQuery::Create("SELECT * FROM stuff");
query->OnExecutionFinished([callback](ResultSet_t resultset)
{
	Result_t result = resultset->GetActiveResult();
	
	std::string stuff;
	result->GetRowDataByName(0, "fieldname", stuff);
	
	printf("stuff is %s\n", stuff.c_str());
});
handle->Execute(CHandle::ExecutionType::PARALLEL, query);
You basically just have to copy over (almost) all plugin source files into your project and link it with the MySQL C connector library. Oh, and your compiler should be C++11-compliant.
maddinat0r is offline   Reply With Quote
Old 09/05/2017, 02:45 AM   #362
TheRealSphinx
Little Clucker
 
TheRealSphinx's Avatar
 
Join Date: Nov 2016
Posts: 21
Reputation: 12
Default Re: Gamemode SDK for C/C++ (GDK)

Quote:
Originally Posted by WopsS View Post
Hello,

I want to leave a response here about Streamer with SAMPGDK. You can use it as xeeZ said here, but you don't need to invoke Streamer_CallbackHook since it is deprecated in version 2.7.8.

Why?
Because Incognito decided to use SAMPGDK for OnPlayerConnect and OnPlayerDisconnect.

All you need to do is to invoke CreateDynamicObject as xeeZ do in his gist.
Code:
int CreateDynamicObject(int modelid, float x, float y, float z, float rx, float ry, float rz, int worldid = -1, int interiorid = -1, int playerid = -1, float streamdistance = 200.0, float drawdistance = 0.0)
{
  static AMX_NATIVE native = sampgdk::FindNative("CreateDynamicObject");
  return sampgdk::InvokeNative(native, "iffffffiiiff", modelid, x, y, z, rx, ry, rz, worldid, interiorid, playerid, streamdistance, drawdistance);
}
And then call it.

Now, I want to know your opinion. If we want to use Streamer with SAMPGDK it is better to invoke a native (like the method above) or to combine streamer plugin with our project (which will be a pain in the a** with plugin updates and with the combination)?

By the way, can we register a Streamer's callback in our plugins?
I tried this
Code:
SAMPGDK_CALLBACK(bool, OnPlayerEditDynamicObject(int playerid, int  objectid, int  response, float x, float y, float z, float rx, float ry, float rz));
SAMPGDK_CALLBACK(bool, OnPlayerSelectDynamicObject(int playerid, int objectid, int modelid, float x, float y, float z));

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerEditDynamicObject(int playerid, int  objectid, int  response, float x, float y, float z, float rx, float ry, float rz)
{
	sampgdk::logprintf("OnPlayerEditDynamicObject: %i | %f | %f | %f", objectid, x, y, z);
	return true;
}

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerSelectDynamicObject(int playerid, int objectid, int modelid, float x, float y, float z)
{
	sampgdk::logprintf("OnPlayerSelectDynamicObject: %i | %f | %f | %f", objectid, x, y, z);
	return true;
}
And this functions aren't called, instead OnPlayerEditObject is called. If I edit an object.
Hi,

you can use this streamer version that supports direct implementation of the streamer in the gamemode.
Then you just need to call the events in your gamemode.

All needed events are listed in the header file.
https://github.com/Sphinxila/samp-pl...r/streamer.hpp

I think its self explanatory.
Feel free to use it or just ignore it ^^.

I rewrote this just for my usage cause "InvokeNative"...
It's not the point of using the SampGDK.

Kind regards
Sphinx
TheRealSphinx is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gamemode is unknown. When i connect theres no gamemode. Shannon_Brown Server Support 11 09/09/2012 09:49 AM
[GameMode] Brasil Drift Show [BDS] - Primeiro GameMode vitorzero3um PortuguÍs/Portuguese 3 29/02/2012 07:48 PM
[ENG] Ideas for new GameMode [NL] Ideeen voor nieuwe Gamemode Xtreme-Nicole Everything and Nothing 10 10/07/2011 12:20 PM
[ENG] Ideas for new GameMode [NL] Ideeen voor nieuwe GameMode Xtreme-Nicole Help Archive 2 09/07/2011 12:24 PM


All times are GMT. The time now is 11:05 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.