SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Plugin Development (https://forum.sa-mp.com/forumdisplay.php?f=18)
-   -   [Plugin] GVar Plugin (https://forum.sa-mp.com/showthread.php?t=151076)

Incognito 29/05/2010 09:29 AM

GVar Plugin
 
GVar Plugin

This plugin is an extension to the per-player variable (PVar) system introduced in SA-MP 0.3a with a few key differences:
  • Global variables (GVars) that are not linked to any player IDs
  • Presence in memory until explicit deletion with DeleteGVar
  • Much faster execution time than properties (see this post for benchmarks)

Changelog

GitHub Commit History

Refer to the CHANGES file the binary package for the full changelog.

Definitions

pawn Code:
#define GLOBAL_VARTYPE_NONE (0)
#define GLOBAL_VARTYPE_INT (1)
#define GLOBAL_VARTYPE_STRING (2)
#define GLOBAL_VARTYPE_FLOAT (3)

Natives

pawn Code:
native SetGVarInt(const name[], value, id = 0);
native GetGVarInt(const name[], id = 0);
native SetGVarString(const name[], const value[], id = 0);
native GetGVarString(const name[], dest[], maxlength = sizeof dest, id = 0);
native SetGVarFloat(const name[], Float:value, id = 0);
native Float:GetGVarFloat(const name[], id = 0);
native DeleteGVar(const name[], id = 0);
native GetGVarsUpperIndex(id = 0);
native GetGVarNameAtIndex(index, dest[], maxlength = sizeof dest, id = 0);
native GetGVarType(const name[], id = 0);

Instructions

Create a directory called "plugins" inside of the server directory if one does not already exist. Place the plugin file (gvar.dll or gvar.so) inside of this directory.

Add the following line to server.cfg so that the plugin will load the next time the server starts:

Windows:
Code:

plugins gvar.dll
Linux:
Code:

plugins gvar.so
On Windows, add gvar.inc to the pawno\include folder. Include this file in any of the scripts the server is running:

pawn Code:
#include <gvar>

Recompile the scripts with any desired natives and callbacks provided by the include file. Start the server.

Notes
  • Remember to delete GVars when they are no longer needed, particularly when a gamemode or filterscript exits.
  • The optional ID, like the player ID in PVars, must be unique.
  • GVar names are case-insensitive.

Download

The latest compiled binaries will always be here:

GitHub Releases Page

The source can be browsed here. This repository can also be cloned.

The Windows version requires the Microsoft Visual C++ 2010 Redistributable Package.

Sergei 29/05/2010 10:10 AM

Re: [REL] GVar Plugin v1.0
 
Wow thank you very much for this :D.

Just one question. Why didn't you make it like in your streamer so:
Code:

native Streamer_SetIntData(type, {Text3D,_}:id, data, value);

native SetGVarInt(type, id, varname[], int_value);

Instead of enum used for 'data' parameter it would be varname. I think this would be the easiest way for us to work with them because atm we need ot format varname like "vehicle1.price".

xxmitsu 29/05/2010 10:56 AM

Re: [REL] GVar Plugin v1.0
 
Assuming that the memory isn't an issue, isn't it slower than using pawn structures?


Anyway, good job, and thank you for helping samp community!




Mike.

bpeterson 29/05/2010 11:17 AM

Re: [REL] GVar Plugin v1.0
 
Amazing job again, Incognito! :o

Incognito 29/05/2010 11:23 AM

Re: [REL] GVar Plugin v1.0
 
$ЯĢ: This wasn't really designed for complex data structures, though I do see your point. The absence of a player ID means that some other form of identification would be useful to have. I think it would work much better as an optional parameter, though, as it's not always needed:

pawn Code:
SetGVarInt(varname[], int_value, id = 0);

Therefore, rather than doing this:

pawn Code:
format(string, sizeof(string), "vehicle_%d_price", gVehicle);
SetGVarInt(string, 5000);

You could do this instead:

pawn Code:
SetGVarInt("vehicle_price", 5000, gVehicle);

I'll see about adding that parameter to the natives later, but it will require some additional checks.

Sma_X: Yes, it will be slower due to function overhead, but it consumes less memory (in most cases) and can be used for inter-script communication.

[HUN]Gamestar 29/05/2010 03:34 PM

Re: [REL] GVar Plugin v1.0
 
Nice!

Victor 29/05/2010 03:51 PM

Re: [REL] GVar Plugin v1.0
 
I was thinking of something like this and what do you know :mrgreen:


Very Nice! Keep up the good work

[HUN]Gamestar 29/05/2010 04:10 PM

Re: [REL] GVar Plugin v1.0
 
-

Toni 29/05/2010 05:29 PM

Re: [REL] GVar Plugin v1.0
 
very nice, keep up the good work! ;)

Johnny_Xayc 29/05/2010 05:56 PM

Re: [REL] GVar Plugin v1.0
 
Niceeeeee :o


All times are GMT. The time now is 07:41 PM.

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