Gamemode SDK for C/C++ (GDK)

I know this topic is about GDK, but this is kinda related to.


I was trying to find out how multidimentional arrays works in the interation pawn/(c++ || c). All i got now, is the code below, which is not working for some reason.



Any help is appreciated,Thanks.


pawn
PHP код:
native Test(string[][],size sizeof string,size2 sizeof string[]);
main()
{
    new 
id[2][2];
    
printf("Pawn");
    for(new 
0sizeof id; ++i)
    {
        for(new 
0sizeof id[]; ++k)
        {
            
printf("id[%d][%d]= %d",i,k,k);
            
id[i][k] = k;
        }
    }
    
printf("End Pawn");
    
Test(id);

c++
PHP код:
cell AMX_NATIVE_CALL Test(AMXamxcellparams)
{
    
logprintf((char*)"c++");
    
cell *addr;
    
int extra 4;
 
    
amx_GetAddr(amxparams[1], &addr);
    
    for(
int i 0params[2]; i++)
    {
        for(
int k 0params[3]; ++k)
        { 
            
logprintf((char*)"Array[%d]=%d",i, *(addr extra));
            
extra += 4;
        }
    }
    
logprintf((char*)"End");
    return 
1;

Reply

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
I know this topic is about GDK, but this is kinda related to.


I was trying to find out how multidimentional arrays works in the interation pawn/(c++ || c). All i got now, is the code below, which is not working for some reason.



Any help is appreciated,Thanks.
It's returned as a pointer to first element of array

MyArray = DataType [Row1..Row2][Column1..Column2];
Addr( MyArray, Row, Column) = ((Row2-Row1) * (Column2-Column1)) * SizeOf(DataType) + (Column - Column1) * SizeOf(DataType)

http://en.wikipedia.org/wiki/Array_d...nsional_arrays
Reply

Thank you, LeaveMe. But, i already knew that c/c++ uses row-major order and already tried to make it work, but it won't. That's why in my implementation above, there is a variable named "Extra". I had thought that the interation was something by the size of its cells(4), in some sense, i was in the right path, lol.


Now, i've just find why i was wrong:Pawn Implementer Guide, page 56/57.
Reply

I have reported a small bug on github but since Zeex didn't ave enough time to fix it I'll also post it here.

If you set public hook and Kick or Ban the player then OnPlayerDisconnect is NOT called.
You have to call OnPlayerDisconnect before you do Kick or Ban until the bug is fixed.
Reply

Hello!

C + + to write the game mode is the faster it will run as a pawn in?
Reply

A question, version 3.7 works for SA-MP 0.3z? because i want to call a function from it, for example can i do?

pawn Код:
PLUGIN_EXPORT int PLUGIN_CALL OnPlayerWeaponShot(int playerid, int weaponid, int hittype, int hitid, float fx, float fy,float fz)
{
return 1;
}
Reply

I would like to ask you a few things have already been written in C + + for game mode!

If you have a lot of cycles, and timing, and is repeated at short intervals, wrote a pawn in game mode is not running at its best.

Now if I am writing in C + + with a game mod, you have several cycles, I use a timer so that it will not lagging?
Reply

Quote:
Originally Posted by d711728
Посмотреть сообщение
I would like to ask you a few things have already been written in C + + for game mode!

If you have a lot of cycles, and timing, and is repeated at short intervals, wrote a pawn in game mode is not running at its best.

Now if I am writing in C + + with a game mod, you have several cycles, I use a timer so that it will not lagging?
You can use threads.

@By the way, is it my bad, or the binaries aren't yet upgraded of the latest sa-mp release?
Reply

Quote:
Originally Posted by Kikito
Посмотреть сообщение
You can use threads.
In simple.
There are many more resources are available to if I am writing in C + + gamemode?
Reply

Quote:
Originally Posted by d711728
Посмотреть сообщение
In simple.
There are many more resources are available to if I am writing in C + + gamemode?
Yes, definitly.
Reply

But there is a big problem.
RAM requirements are very high, you can do something about it?
Reply

More optimizated the gamemode is, less ram will be used.
Quite simple.

For example: Avoid useless variables.
Reply

Before I start to write a letter gamemode more.

How do I have the opportunity to use mysql plugin (maddinat0r r37)?

Where can I find a server that is sure to written in the form of plugin for?
Reply

The best way would be to use MySQL C/C++ connector instead of the plugin, of course if you're not going to need MySQL in scripts anymore. If you're used to the plugin or you need MySQL in pawn scripts too, you can use sampgdk_invoke_native along with sampgdk_find_native to call plugin's functions.
Reply

Quote:
Originally Posted by Pupak
Посмотреть сообщение
The best way would be to use MySQL C/C++ connector instead of the plugin, of course if you're not going to need MySQL in scripts anymore. If you're used to the plugin or you need MySQL in pawn scripts too, you can use sampgdk_invoke_native along with sampgdk_find_native to call plugin's functions.
I see, thank you.

Код:
new query[128];
mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
// the variable 'query' contains now the formatted query (including the escaped string)
mysql_tquery(MySQL, query, "OnStuffSelected", "");
However, if for example, you would write code similar.

Then the function to call, how to solve?

The "OnStuffSelected" mean.
Reply

The function TogglePlayerSpectating the server crash in OnPlayerConnect, is the 3.7 version SAMPGDK.
Reply

I'm trying to invoke the functions from the MySQL plugin v R6 (G Stylezzzz / madinator), but it seems like I'm missing something. This is my code:

Код:
void mysql_connect(const char* hst, const char* usr, const char* db, const char* pass)
{
	return (void)sampgdk_invoke_native(sampgdk_find_native("mysql_connect"), "rrrr", hst, usr, db, pass);
}
now, I am supposed to do something like

Код:
 sqlHandler = mysql_connect (SQL_HOST, SQL_DB, SQL_USER, SQL_PASS);
but I don't have the handler type in my "project"

What else do I need? I mean, can I just invoke the plugin's functions, or I need a handler class or something? Is void the correct 'type' for the invoke_native call?

thanks

edit: it compiles even with the crap code I made.
Reply

Quote:
Originally Posted by [ESC]Walter_Wolf
Посмотреть сообщение
I'm trying to invoke the functions from the MySQL plugin v R6 (G Stylezzzz / madinator), but it seems like I'm missing something. This is my code:

Код:
void mysql_connect(const char* hst, const char* usr, const char* db, const char* pass)
{
	return (void)sampgdk_invoke_native(sampgdk_find_native("mysql_connect"), "rrrr", hst, usr, db, pass);
}
now, I am supposed to do something like

Код:
 sqlHandler = mysql_connect (SQL_HOST, SQL_DB, SQL_USER, SQL_PASS);
but I don't have the handler type in my "project"

What else do I need? I mean, can I just invoke the plugin's functions, or I need a handler class or something? Is void the correct 'type' for the invoke_native call?

thanks

edit: it compiles even with the crap code I made.
I also would be the question of how to handle mysql plugins.
Reply

Re-reading my previous post I realised I didn't quite explain my problem precisely.

The MySQL plugin (v R6) initializes a 'CMySQLHandler' (or similar name) object when the 'mysql_connect' function is called. I can 'sampgdk_find' and 'sampgdk_invoke' the 'mysql.dll' native function in my gamemode plugin, but how do I declare and use the other plugin's class object?

I need the handler for the querries and stuff.

Is it possible?

EDIT: amx_FindPubVar ?
Reply

Thanks a lot Gamer_Z, but I was rethinking the issue, and concluded I don't need the exact address of the class. The fabulous 'sampgdk' finds and calls the (other plugin) desired functions for me, initializes the variables etc.

This is the way I did it:

Код:
cell mysql_connect(string * hst, string * usr, string * db, string * pass)
{
	return (cell)sampgdk_invoke_native(sampgdk_find_native("mysql_connect"), "ssss", hst, usr, db, pass);
}

cell mysql_ping(cell *connectionHandle)
{
	return (cell) sampgdk_invoke_native(sampgdk_find_native("mysql_ping"), "i", connectionHandle);
}

cell mysql_errno(cell *connectionHandle)
{
	return (cell)sampgdk_invoke_native(sampgdk_find_native("mysql_errno"), "i", connectionHandle);
}
Код:
PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {
  
  ...
  cell i;
  i = mysql_connect (&SQL_HOST, &SQL_USER, &SQL_DB, &SQL_PASS);
  mysql_ping (&i);

  if(mysql_errno(&i) == 0) ServerLog::Printf("Connected");
  else  ServerLog::Printf("Connection failed!");
 
...

  return true;
}
... in case any other noobs like me wish to try it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)