• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Better way to do it?

AlexeWarr

Epic Member
Hello, I used a bad implementation for one of my scripts, inspired from kilstreak system for trinity

The thing is that I didn't understand it at all so Im gonna need a bit of support to understand it

They way I want to use this is, I want to register a value / number for a player by his GUID,

So how I m thinking about:

uint32 test;
uint32 start;

So I want to use to get or register the value by the player's GUID:

test[GUID].start = 1;

So when ever this is called will return the number specified for that guid, srry for the explanation am a bit drunk haha ;)

Can somebody provide a proper code for this use ? :S
 
Last edited:

Rochet2

Moderator / Eluna Dev
You can make a struct for the values:
Code:
struct playerData
{
    uint32 test;
    uint32 start;
};
then make an unordered map or map or vector or something:
Code:
UNORDERED_MAP<uint32, playerData> playerDatas; // GUIDLow, playerData

Then you can do as you wish.
[] operator should create a new playerData if one doesnt exist since we are not using a pointer.
This means that if a player guid(low) is not in the map or w/e, it will still return an object and both test and start will be 0 unless set to something.
This means that you dont need to check if a player has a record in the map.

Code:
playerDatas[player->GetGUIDLow()].start; // if printed should be 0
playerDatas[player->GetGUIDLow()].start = 123; // changed to 123


Btw. Structs are like classes. They can have constructors and so on.
But there is something different with the default values.
 
Last edited:

AlexeWarr

Epic Member
You can make a struct for the values:
Code:
struct playerData
{
    uint32 test;
    uint32 start;
};
then make an unordered map or map or vector or something:
Code:
UNORDERED_MAP<uint32, playerData> playerDatas; // GUIDLow, playerData

Then you can do as you wish.
[] operator should create a new playerData if one doesnt exist since we are not using a pointer.
This means that if a player guid(low) is not in the map or w/e, it will still return an object and both test and start will be 0 unless set to something.
This means that you dont need to check if a player has a record in the map.

Code:
playerDatas[player->GetGUIDLow()].start; // if printed should be 0
playerDatas[player->GetGUIDLow()].start = 123; // changed to 123


Btw. Structs are like classes. They can have constructors and so on.

Thank you Rochet
 
Top