Simmo23 Posted August 29, 2018 Share Posted August 29, 2018 Hey guys, I use c# with the bridge. Is there any possibility to get an identifier from an Entity (Client, Vehicle)?. I like to manage additional data for clients (level, money, ...) which are stored in a DB. Just like that i like to manage additional data for vehicles later. Once an event is triggerd by a client, i like to manipulate the additional data. So i have to create a connection from the Client object - which i got from the event - and my User object. (Currently I'm using a dictionarylist with the client.Name as Key an my User object as Value and everytime i like to manipulate the data, i have to search for the client.Name as key in the List to get the User object). But if i think about the vehicles, I don't find any identifier. When I remember SA:MP, everything had an identifier, which has never change since the creation. What i've already tried: I tried to create a sub class user with the Client as base. So the User has got all the properties from its base class and I can add additional properties. The problem i have related to the constructor of the base class. Link to comment Share on other sites More sharing options...
Static Posted August 29, 2018 Share Posted August 29, 2018 (edited) I find it easier to work with Entity Data. Take a look here: https://wiki.gtanet.work/index.php?title=Getting_Started_with_EntityData Whenever an a player joins, goes through Authentication and his data is retrieved from your storage (database) you can create an instance of a class you defined for your players with all that custom data. Then you can use entity data to attach the reference to that instance. For example: We have a class called account. class Account { public string sqlId { set; get; } public string playerName { set; get; } public string money { set; get; } ... } When a players joins in the server, you go through your regular authentication routine. If all goes well, you then load that data into an instance of that Account class. public static boolean AuthenticatePlayer(username, password, ....) { // Authentication routine ... // Account playerAccountData = Database.RecoverAccount(sqlID, ...); NAPI.Data.SetEntityData(player, "MY_CUSTOM_PLAYER_DATA", playerAccountData); return true; } If at some point you wish to access that data { ..... if(NAPI.Data.HasEntityData(player, "MY_CUSTOM_PLAYER_DATA")) { Account account = NAPI.Data.GetEntityData(player, "MY_CUSTOM_PLAYER_DATA"); account.money += 500; .... } else { // No entity data: throw exception, error, message etc. } .... } Edited August 29, 2018 by Static Link to comment Share on other sites More sharing options...
Simmo23 Posted August 30, 2018 Author Share Posted August 30, 2018 I'm very grateful for this advice. I don't know about EntityData. That will help me. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now