SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 24/06/2017, 03:53 PM   #1
jlalt
High-roller
 
Join Date: Oct 2014
Posts: 1,354
Reputation: 332
Default C++ Vectors plugin

Introduction:
This is a simple plugin which gives the ability to use c++ vectors in pawn.


What vectors are?
They are kind of arrys which can save huge amount of data. if you've worked before with c# or php they are just like c# Lists or php arrays.


Functions list:
PHP Code:
native Vector_Push(const kind, const ID:vectorid, const value[] = ""Float:v2 0.0);
native Vector_GetValue(const kind, const ID:vectorid, const itemid, const str_source[] = "", const len sizeof str_source);
native Vector_GetSize(const kind, const ID:vectorid);
native Vector_GetItemLen(const kind, const ID:vectorid, const itemid);
native Vector_ItemErase(const kind, const ID:vectorid, const itemid);
native Vector_SetItemValue(const kind, const ID:vectorid, const itemid, const data[] = ""Float:v2 0.0);
native Vector_AppendItemValue(const kind, const ID:vectorid, const itemid, const data[] = ""Float:v2 0.0);
native Vector_Clear(const kind, const ID:vectorid);
native Vector_Sort(const kind, const ID:vectorid);
native ID:Vector_Create(const kind); 
sample of scripting:
https://pastebin.com/CePNKeQx


Download v1: https://github.com/Jlalt/CPPVectors/releases/tag/1.0
Download v2: https://github.com/Jlalt/CPPVectors/releases/tag/1.1

v2 Changes:
  • No need to set specific size for vectors [ removed SetMaxVector ]
  • Added vector_sort to sort vector elements
  • Added vector_create to initialize new vector.

Source: https://github.com/Jlalt/CPPVectors

Credits:
Kurta for his c++ tutorials
X337 for his helps on building linux version
me for programming D:
quera site for their scripting contests and question and increasing my cpp knowledge.

Last edited by jlalt; 04/01/2018 at 07:04 PM.
jlalt is offline   Reply With Quote
Old 30/06/2017, 12:35 PM   #2
Beryllium
Banned
 
Join Date: May 2017
Location: Egypt.
Posts: 74
Reputation: 4
Default Re: C++ Vectors plugin

Was looking for something like this, Good job jlalt.
Beryllium is offline   Reply With Quote
Old 30/06/2017, 12:56 PM   #3
iLearner
Gangsta
 
iLearner's Avatar
 
Join Date: Apr 2017
Posts: 539
Reputation: 113
Default Re: C++ Vectors plugin

I've used these in c#, very cool.

Any documentation page?
iLearner is offline   Reply With Quote
Old 30/06/2017, 01:03 PM   #4
jlalt
High-roller
 
Join Date: Oct 2014
Posts: 1,354
Reputation: 332
Default Re: C++ Vectors plugin

Quote:
Originally Posted by iLearner View Post
I've used these in c#, very cool.

Any documentation page?
not yet, idk if will do one ever :#
jlalt is offline   Reply With Quote
Old 30/06/2017, 03:46 PM   #5
coool
Huge Clucker
 
Join Date: Feb 2013
Location: Pakistan, Sindh
Posts: 452
Reputation: 28
Default Re: C++ Vectors plugin

Looks sick *appreciated*
__________________
My Writing Works
Lost In Future

coool is offline   Reply With Quote
Old 30/06/2017, 05:51 PM   #6
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 565
Reputation: 236
Default Re: C++ Vectors plugin

Don't know why no one else hasn't written a plugin that gives the ability to use data structures in general. Guess not enough people know what they are, or they just aren't needed in scripting a server.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 30/06/2017, 07:12 PM   #7
Michalec
Big Clucker
 
Michalec's Avatar
 
Join Date: Jun 2009
Location: Poland
Posts: 94
Reputation: 2
Default Re: C++ Vectors plugin

Quote:
Originally Posted by Freaksken View Post
Don't know why no one else hasn't written a plugin that gives the ability to use data structures in general. Guess not enough people know what they are, or they just aren't needed in scripting a server.
There are two plugins:
http://forum.sa-mp.com/showthread.php?t=238844
http://forum.sa-mp.com/showthread.php?t=364285

But... Both are bugged and crashes a server
Michalec is offline   Reply With Quote
Old 30/06/2017, 07:20 PM   #8
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 565
Reputation: 236
Default Re: C++ Vectors plugin

Quote:
Originally Posted by Michalec View Post
There are two plugins:
http://forum.sa-mp.com/showthread.php?t=238844
http://forum.sa-mp.com/showthread.php?t=364285

But... Both are bugged and crashes a server
Oh lol, I even posted on that second thread. That being said, there are a lot more useful datastructures than vectors, deques and maps.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is offline   Reply With Quote
Old 03/07/2017, 07:09 PM   #9
ArminKH
Little Clucker
 
Join Date: Sep 2015
Posts: 12
Reputation: 1
Default Re: C++ Vectors plugin

Nice job
ArminKH is offline   Reply With Quote
Old 04/01/2018, 06:15 PM   #10
jlalt
High-roller
 
Join Date: Oct 2014
Posts: 1,354
Reputation: 332
Default Re: C++ Vectors plugin

v1.1 has been released. so far its only available on windows, feel free to compile it on linux and keeping/sharing it.

Changes:
  • No need to set specific size for vectors [ removed SetMaxVector ]
  • Added vector_sort to sort vector elements
  • Added vector_create to initialize new vector.

Sample:
PHP Code:
#include a_samp
#include a_vectors

public OnFilterScriptInit()
{
    new 
tick GetTickCount(), inaccurate 0;
    new 
ID:vecid Vector_Create(Vector::Float);
    
Vector_Push(Vector::Floatvecid, .v2 55.6); // push data to float vector id 0
    
Vector_Push(Vector::Floatvecid, .v2 20.6); // push data to float vector id 0
    
Vector_Push(Vector::Floatvecid, .v2 4.2); // push data to float vector id 0
    
Vector_Push(Vector::Floatvecid, .v2 9.2); // push data to float vector id 0
    
new len Vector_GetSize(Vector::Floatvecid); // get count of datas exist in float vector id 0
    
new printtook GetTickCount();
    
printf("Length: %d",len);
    
inaccurate += GetTickCount() - printtook;
    for(new 
0leni++)
    {
        
printtook GetTickCount();
        
printf("%f",Vector_GetValue(Vector::Floatvecidi));
        
inaccurate += GetTickCount() - printtook;
    }
    
printtook GetTickCount();
    
printf("Now trying to create vectors");
    
inaccurate += GetTickCount() - printtook;
    new
    
ID:vec1 Vector_Create(Vector::Float),
    
ID:vec2 Vector_Create(Vector::Float);
    
printtook GetTickCount();
    
printf("%d %d %d"_:vec1_:vec2_:Vector_Create(Vector::Int));
    
printf("Removing floats vectors in slot 2 and 0");
    
inaccurate += GetTickCount() - printtook;
    
Vector_Clear(Vector::FloatID:2);
    
Vector_Clear(Vector::FloatID:0);
    
vec1 Vector_Create(Vector::Float);
    
vec2 Vector_Create(Vector::Float);
    
printtook GetTickCount();
    
printf("Remaking two float vectors: %d %d"_:vec1_:vec2);
    
inaccurate += GetTickCount() - printtook;
    
Vector_Push(Vector::IntID:0, .v2 15);
    
Vector_Push(Vector::IntID:0, .v2 6);
    
Vector_Push(Vector::IntID:0, .v2 9);
    
Vector_Push(Vector::IntID:0, .v2 20);
    
Vector_Push(Vector::IntID:0, .v2 23);
    
Vector_Push(Vector::IntID:0, .v2 4);
    
Vector_Push(Vector::IntID:0, .v2 18);
    
Vector_Sort(Vector::IntID:0);
     
len Vector_GetSize(Vector::IntID:0);
     
printtook GetTickCount();
     print(
"Testing Vector sort for int\n");
     
inaccurate += GetTickCount() - printtook;
     for(new 
0leni++)
    {
        
printtook GetTickCount();
        
printf("%d",Vector_GetValue(Vector::IntID:0i));
        
inaccurate += GetTickCount() - printtook;
    }
    
printtook GetTickCount();
    print(
"Testing Vector sort for string\n");
    
inaccurate += GetTickCount() - printtook;
    
Vector_Create(Vector::String);
    
Vector_Push(Vector::StringID:0"Kalcor");
    
Vector_Push(Vector::StringID:0"kalcor");
    
Vector_Push(Vector::StringID:0"Amir");
    
Vector_Push(Vector::StringID:0"Kurtana");
    
Vector_Push(Vector::StringID:0"iLearner");
    
Vector_Push(Vector::StringID:0"ILearner");
    
Vector_Push(Vector::StringID:0"Jlalt");
    
Vector_Push(Vector::StringID:0"Freaksken");
    
Vector_Sort(Vector::StringID:0);
    
len Vector_GetSize(Vector::StringID:0);
    for(new 
0leni++)
    {
        new 
name[32];
        
Vector_GetValue(Vector::StringID:0iname);
        
printtook GetTickCount();
        
printf("%s",name);
        
inaccurate += GetTickCount() - printtook;
    }
    
printf("Took %dms in total!",(GetTickCount() - inaccurate) - tick);

Output
PHP Code:
    Output:
    
Length4
    55.599998
    20.600000
    4.199999
    9.199999
    Now trying to create vectors
    1 2 0
    Removing floats vectors in slot 2 
and 0
    Remaking two float vectors
0 2
    Testing Vector sort 
for int

    4
    6
    9
    15
    18
    20
    23
    Testing Vector sort 
for string

    Amir
    Freaksken
    ILearner
    Jlalt
    Kalcor
    Kurtana
    iLearner
    kalcor
    Took 0ms in total

jlalt 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
Vectors adri1 Scripting Help 4 28/02/2015 02:16 PM
[Tutorial] Vectors in SA-MP RajatPawar Tutorials 11 04/02/2014 01:02 AM
Playing around with vectors (0.3z) Dragony92 Screenshots and Videos 9 31/01/2014 06:54 AM
Using vectors & maps Maxips2 Scripting Help 4 22/06/2013 11:19 AM
Vectors potato Help Archive 1 08/08/2010 05:09 AM


All times are GMT. The time now is 06:06 AM.


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