[Plugin] UUID4 - Universal Unique Identifiers
#1

pawn-uuid



uuid provides a simple UUID version 4 generator function.

What’s a UUID? A UUID (Universal Unique Identifier) is a standardised implementation of generating unique byte sequences. In string format, these UUIDs look like this:
  • e338fae6-9df9-4e21-bb59-667c29e419cf
  • 0149476c-cf42-4432-b946-d9695656aec0
  • dcd2d8bd-0fb8-44db-93fd-b00efaa610ae

You’ll probably see these style strings all over the place from newsletters to website account IDs. They are very useful for uniquely identifying things without falling back to user-defined names or incrementing IDs.

What are these useful for?

Identifiers like this are perfect for identifying players without relying on their username - this allows players to freely change their username without changing a ton of database relations.

It’s also perfect for identifying entities such as vehicles, pickups, items, etc. A good example of this is the Scavenge and Survive gamemode: on each server restart, around 10-20,000 items are generated and placed in the world, each of these items is assigned a unique identifier so if a player picks one up and keeps it in their inventory or in a vehicle trunk, the unique identifier persists throughout the item’s lifetime and everywhere it goes can be tracked. This is very useful for auditing and anti-cheat.

Why not use an incrementing ID?

If you’re an SQL user you probably use AUTOINCREMENT to assign unique identifiers to entities you persist in the database.

The problem with this is you’re relying on the database implementation to handle the uniqueness. This locks you into using that database and also means there’s a reliance on sequentiality in the identifiers.

Why not use a random integer?

Sure there are 2^32 valid states you can use in a Pawn cell (integer), what’s the chance of a collision? That’s not actually a whole lot of entropy, especially if you’re creating new entities on every server restart/multiple times a day. It’s best to be safe when trying to generate unique identifiers.

Installation

Source and Binaries on GitHub

Simply install to your project:

Code:
sampctl package install Southclaws/pawn-uuid
Include in your code and begin using the library:

Code:

#include <uuid>
And add to your runtime configuration:

PHP Code:
{
  
"plugins": ["Southclaws/pawn-uuid"]

Usage

There’s only one function and one constant, the following example should be enough documentation for usage:

Code:

new uuid[UUID_LEN];
UUID(uuid, UUID_LEN);
printf("UUID: '%s'", uuid);
// prints a nice unique string shaped like: 00000000-0000-0000-0000-000000000000
Testing

Run unit tests with:

Windows

Code:
make test-windows
Linux

Requires Docker to be installed and available at the command line. If you’re actually on a Linux machine, just run the Windows makefile command above and it’ll still run fine on Linux!

Code:
make test-debian
Reply
#2

Really Awesome! OMG I really need this. Can you make some tutorials how to use this. For Newbies
Reply
#3

Quote:
Originally Posted by Xportaler
View Post
Really Awesome! OMG I really need this. Can you make some tutorials how to use this. For Newbies
I'm not sure this warrants even one tutorial, let alone multiple tutorials...

Reply
#4

u are fkn God
Reply
#5

Nice nice serves its purpose well, u r on fire mate gj ;d
Reply
#6

Can I use this with dini?
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
Can I use this with dini?
or LuxAdmin?
Reply
#8

Quote:
Originally Posted by Kar
View Post
or LuxAdmin?
I don't care about that, I just want to use this in my new strcmp UCP. It looks brilliant, and exactly what I need.

Just one question - what is it?
Reply
#9

Nice release. I was working on a project sometime ago which would have millions of items (100/1000's+ of each skin, vehicle, etc) ownable by players. This would have come in handy.

Quote:
Originally Posted by Y_Less
View Post
I don't care about that, I just want to use this in my new strcmp UCP. It looks brilliant, and exactly what I need.

Just one question - what is it?
Y_Less trolling? This is new.
Reply
#10

Quote:
Originally Posted by Grim_
View Post
Nice release. I was working on a project sometime ago which would have millions of items (100/1000's+ of each skin, vehicle, etc) ownable by players. This would have come in handy.



Y_Less trolling? This is new.
yeah, I guess it's a programming error in your robot brain, as we already know it's a programmer robot without feelings and emotions for which you can not make jokes, so apologize for the robot's error, it will not happen again, I've already deactivated the Troll filter in your brain, regards.


topic: nice release
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)