SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 29/05/2010, 08:29 AM   #1
Incognito
Huge Clucker
 
Join Date: May 2006
Posts: 459
Reputation: 410
Default GVar Plugin

GVar Plugin v1.3

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

v1.3:
  • Made indexes local to each unique ID
  • Slightly improved GetGVarsUpperIndex

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

Server Plugin (Windows and Linux) (Mirror)
Source Code (Cross-Compatible) (Mirror)

The Windows version requires the Microsoft .NET Framework 4.0 or higher.

Last edited by Incognito; 18/05/2014 at 06:33 PM.
Incognito is offline   Reply With Quote
Old 29/05/2010, 09:10 AM   #2
Sergei
High-roller
 
Sergei's Avatar
 
Join Date: Mar 2008
Location: Slovenia
Posts: 2,688
Reputation: 130
Default Re: [REL] GVar Plugin v1.0

Wow thank you very much for this .

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".
Sergei is offline   Reply With Quote
Old 29/05/2010, 09:56 AM   #3
xxmitsu
Gangsta
 
Join Date: Feb 2009
Posts: 629
Reputation: 35
Default 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.
__________________
aka xanto - Retired - Former eGaming.ro technical staff.
xxmitsu is offline   Reply With Quote
Old 29/05/2010, 10:17 AM   #4
bpeterson
Banned
 
Join Date: Dec 2008
Posts: 236
Reputation: 0
Default Re: [REL] GVar Plugin v1.0

Amazing job again, Incognito!
bpeterson is offline   Reply With Quote
Old 29/05/2010, 10:23 AM   #5
Incognito
Huge Clucker
 
Join Date: May 2006
Posts: 459
Reputation: 410
Default 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.
Incognito is offline   Reply With Quote
Old 29/05/2010, 02:34 PM   #6
[HUN]Gamestar
Big Clucker
 
Join Date: Aug 2009
Posts: 183
Reputation: 0
Default Re: [REL] GVar Plugin v1.0

Nice!
[HUN]Gamestar is offline   Reply With Quote
Old 29/05/2010, 02:51 PM   #7
Victor
Big Clucker
 
Join Date: Dec 2008
Posts: 63
Reputation: 0
Default Re: [REL] GVar Plugin v1.0

I was thinking of something like this and what do you know


Very Nice! Keep up the good work
__________________
Do not friend request me unless I know you!
Victor is offline   Reply With Quote
Old 29/05/2010, 03:10 PM   #8
[HUN]Gamestar
Big Clucker
 
Join Date: Aug 2009
Posts: 183
Reputation: 0
Default Re: [REL] GVar Plugin v1.0

-
[HUN]Gamestar is offline   Reply With Quote
Old 29/05/2010, 04:29 PM   #9
Toni
High-roller
 
Toni's Avatar
 
Join Date: Aug 2009
Location: United States
Posts: 1,535
Reputation: 154
Default Re: [REL] GVar Plugin v1.0

very nice, keep up the good work!
__________________
Toni is offline   Reply With Quote
Old 29/05/2010, 04:56 PM   #10
Johnny_Xayc
Huge Clucker
 
Johnny_Xayc's Avatar
 
Join Date: Aug 2009
Posts: 322
Reputation: 0
Default Re: [REL] GVar Plugin v1.0

Niceeeeee
Johnny_Xayc 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
[Include] GVar (Plugin-Free!) Maxips2 Includes 18 24/08/2012 06:43 AM
[HELP] How to use GVar's Swimor Scripting Help 1 25/07/2012 09:16 AM
Problem with Gvar in 0.3d NeyMar96 Scripting Help 4 26/12/2011 12:58 PM
question Gvar NeyMar96 Scripting Help 3 12/09/2011 07:39 PM
[Q] GVar Plugin Vs enum XePloiT Help Archive 3 05/12/2010 07:51 AM


All times are GMT. The time now is 08:08 PM.


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