|
|
#1 |
|
Little Clucker
![]() Join Date: Mar 2011
Posts: 32
Reputation: 18
|
CSTL - VECTOR AND MAP FOR PAWN
Implementing std::vector and std::map for PAWN Natives VECTOR VECTORS DONT HAVE TO BE INITIALIZED, SPECIFY AN INTEGER AS VECID PARAMETER. Vectors are typeless (you can push and set any datatypes without problem). But vector will do type checking when returning values (trying to vector_get_arr on float value will fail, you can use vector_entry_type to get datatype of entry). Vector size is automatically increased when using push_back to add more data. Its also possible to increase vector size manually with vector_resize. You can NOT use vector_set to set anything into index bigger than vector size (size - 1, indexes are same as in arrays). Disallowed example: pawn Code:
Allowed example pawn Code:
native vector_push_back(vecid, element); // push back integer native vector_push_back_float(vecid, Float:element); // push back float native vector_push_back_arr(vecid, element[]); // push back array (string) native vector_size(vecid); // get vector size native vector_get(vecid, id); // get integer by index native Float:vector_get_float(vecid, id); // get floating point number by index native vector_get_arr(vecid, id, buffer[], buflen); // get array element to buffer by index native vector_set(vecid, id, element); // set index native vector_set_float(vecid, id, Float:element); // set float native vector_set_arr(vecid, id, element[]); // set array native vector_clear(vecid); // clear vector native vector_resize(vecid, newsize); // resize vector to new size native vector_entry_type(vecid, id); // get element type (int, array or float) native vector_remove(vecid, id); // remove element by index native vector_find(vecid, element); // find index of int element native vector_find_float(vecid, Float:element); // find index of float element native vector_find_arr(vecid, element[]); // find index of array native vector_globalize(vecid); // makes vector visible to all scripts native vector_deglobalize(vecid); // deglobalizes vector (vector removed from all scripts except calling script) native vector_is_globalized(vecid); // is vector ID globalized MAP MAPS ALSO DONT HAVE TO BE INITIALIZED native map_insert(mapid, key[], value); // insert with integer value native map_insert_float(mapid, key[], Float:value); // insert with float value native map_insert_arr(mapid, key[], value[]); // insert with array as value native map_get(mapid, key[]); // get integer native Float:map_get_float(mapid, key[]); // get float native map_get_arr(mapid, key[], buffer[], buflen); // get array to buffer native map_size(mapid); // element count of array native map_remove(mapid, key[]); // remove specific key native map_contains(mapid, key[]); // does map contain specific key native map_entry_type(mapid, key[]); // return value type of key (int, array or float) native map_clear(mapid); // clear the map native map_globalize(mapid); // makes map visible to all scripts native map_deglobalize(mapid); // deglobalizes map (map removed from all scripts except calling script) native map_is_globalized(mapid); // is map ID globalized Example Vector pawn Code:
outputs: Code:
ARRAY: A CELL: 1 ARRAY: B Vector size: 0 pawn Code:
outputs: Code:
Map key "key" has value: This is value Map length is now: 1 After removal size is: 0
License Copyright (C) 2011, Teprey All rights reserved. By using functions provided by this plugin within your software or otherwise using this software, you agree to comply with following terms and conditions: You may not change copyright message or credit information in any file of this product. You may redistribute and/or modify this software only if you preserve credit. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. DOWNLOAD WINDOWS DLL + LINUX .SO + SOURCE Last edited by Teprey; 30/06/2011 at 06:20 AM. |
|
|
|
|
|
#2 |
|
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2008
Posts: 5,609
Reputation: 377
|
What does this, actually do? I'm confused, how is this somewhat helpful ?
|
|
|
|
|
|
#3 |
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Dec 2009
Location: Home
Posts: 2,349
Reputation: 212
|
i agree with Zh3r0
|
|
|
|
|
|
#4 |
|
Little Clucker
![]() Join Date: Mar 2011
Posts: 32
Reputation: 18
|
Its "dynamic array" (you dont have to know maximum size for it, unlike normal arrays in PAWN)
For example you can store all online playerids in it, and the vector size changes according to player count. Then if you need to loop through all players online, you do not have to loop from 0 to MAX_PLAYER and check if player is online, but you can just loop through vector (hard to explain) Example filterscript: pawn Code:
|
|
|
|
|
|
#5 | |
|
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2008
Posts: 5,609
Reputation: 377
|
Quote:
Now i understand, genius! Good job. |
|
|
|
|
|
|
#6 |
|
Guest
Posts: n/a
|
In another words, this is kinda like foreach?
pawn Code:
|
|
|
|
#7 |
|
Little Clucker
![]() Join Date: Mar 2011
Posts: 32
Reputation: 18
|
This can be used like foreach and is suitable for that but basically this is suitable for many other things too.
You can search values and get values from middle of vector easily without looping. Basically this is array without some restrictions (need to specify size in code). I'm gonna extend this plugin to have other data containers too (std::map: key->value storage, kinda like dictionary) |
|
|
|
|
|
#8 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: May 2008
Posts: 643
Reputation: 0
|
Good. I haven't used something like this before, but I will use it for my gamemode
|
|
|
|
|
|
#9 |
|
Banned
![]() Join Date: Feb 2011
Location: Osama Bin Laden's house ;)
Posts: 552
Reputation: 1
|
really nice work!!
|
|
|
|
|
|
#10 |
|
Little Clucker
![]() Join Date: Mar 2011
Posts: 32
Reputation: 18
|
Update
Now plugin also provides std::map data container. std::map is basically key-value list. Key is always string (array). Value can be either int, float or array (string). Values are referenced with keys (map_get(MAPID, "key") to get integer value) Example: "stringkey1" => "this is value" "floatkey2" => 0.492 "intkey" => 46 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Setting an object rotation by the player's camera vector? | [XST]O_x | Scripting Help | 3 | 14/07/2012 02:03 PM |
| [Map] Storage Container (Illegal Items) & Two Others | Norn | Maps | 2 | 19/12/2010 05:58 AM |
| Send data to website, website puts data into Database | DeathOnaStick | Help Archive | 9 | 27/08/2010 01:34 PM |
| TAKE DATA FROM SQL | Zafire2008 | Help Archive | 4 | 25/01/2010 08:17 PM |
| Data | commad | Help Archive | 5 | 16/12/2009 10:57 PM |