Online and Offline members (ini)
#1

Something like this:



When leader types for example /allmembers I want to loop through all players in scriptfiles and check is anybody in his faction (if pLeader == 1; check all players that are pMember ==1) and display them like this. Display who is offline and who is online for faction that leader is.

I have Users storage:

PHP код:
#define PATH "Users/%s.ini" 
PHP код:
//===============================================================================================================================//
stock UserPath(playerid)
{
    new 
string[128],playername[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,playername,sizeof(playername));
    
format(string,sizeof(string),PATH,playername);
    return 
string;
}
//===============================================================================================================================//
forward LoadUser_data(playerid,name[],value[]);
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_Int("Leader",PlayerInfo[playerid][pLeader]);
    
INI_Int("Member",PlayerInfo[playerid][pMember]);
     return 
1;

So, how to loop through all players (online and offline)?
Reply
#2

I recommend you to use MySQL as it is very easy for such needs.

If you wanna use Y_INI, This is how you should proceed:
You have to create a new folder called factions. In that, Store the faction id, For eg: 1.ini, 2.ini.... In each faction, store the Name of the faction, Name of the leader and and name of member eg, Member 1, Member 2, etc. Then when a leader types /allmembers, get his faction id from this playername.ini file, Open the file which corresponds to that faction id, and get the name of the members.

Again, If You're just starting out with your script, Switch to MySQL. It'll be hard at first, But this community has a great number of tutorials. I HIGHLY RECOMMEND you to use MySQL.
Reply
#3

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
I recommend you to use MySQL as it is very easy for such needs.

If you wanna use Y_INI, This is how you should proceed:
You have to create a new folder called factions. In that, Store the faction id, For eg: 1.ini, 2.ini.... In each faction, store the Name of the faction, Name of the leader and and name of member eg, Member 1, Member 2, etc. Then when a leader types /allmembers, get his faction id from this playername.ini file, Open the file which corresponds to that faction id, and get the name of the members.

Again, If You're just starting out with your script, Switch to MySQL. It'll be hard at first, But this community has a great number of tutorials. I HIGHLY RECOMMEND you to use MySQL.
Thanks for reply. What requirements I need if I'm gonna use mysql. How the code would work if I wanted this command /allmembers for example?
Reply
#4

Quote:
Originally Posted by Saddin
Посмотреть сообщение
Thanks for reply. What requirements I need if I'm gonna use mysql. How the code would work if I wanted this command /allmembers for example?
You're gonna need to have 2 tables, One for storing the Player Info. If you're working only one a faction system, It should just be his userid(not playerid), Name, Faction ID, and Faction Rank(Leader(1), Member(2), Not Member(0) etc).

Second table will have the Faction Info, Which will contain the columns Faction id, Faction leader (You can add columns later if you want to add extra stuff like faction name, faction rank etc.)

Now you load the player info when a player connects and store in an ENUM with his playerid as an index. Then when a player types /allmembers, You can check if He is a leader of any faction by getting his rank His enum, which we loaded from the database when he connected. Then You can get his Faction ID. Then you can do a query which selects all the members from the Player Info table with the same Faction ID as the leader. For Eg, If the faction ID of the leader is 1, We look through the database and find all the members who has the same faction id. Then we load there usernames, Store it in an array and just print them. One of the main advantages of using this method is that you can have as many members as you want in a faction and it will still be the same code for loading.

This sounds really complicated but its actually really simple. The only hard part is loading and saving to MySQL database, and that's the only difference from Y_INI. Rest of the code is Simple!
Reply
#5

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
You're gonna need to have 2 tables, One for storing the Player Info. If you're working only one a faction system, It should just be his userid(not playerid), Name, Faction ID, and Faction Rank(Leader(1), Member(2), Not Member(0) etc).

Second table will have the Faction Info, Which will contain the columns Faction id, Faction leader (You can add columns later if you want to add extra stuff like faction name, faction rank etc.)

Now you load the player info when a player connects and store in an ENUM with his playerid as an index. Then when a player types /allmembers, You can check if He is a leader of any faction by getting his rank His enum, which we loaded from the database when he connected. Then You can get his Faction ID. Then you can do a query which selects all the members from the Player Info table with the same Faction ID as the leader. For Eg, If the faction ID of the leader is 1, We look through the database and find all the members who has the same faction id. Then we load there usernames, Store it in an array and just print them. One of the main advantages of using this method is that you can have as many members as you want in a faction and it will still be the same code for loading.

This sounds really complicated but its actually really simple. The only hard part is loading and saving to MySQL database, and that's the only difference from Y_INI. Rest of the code is Simple!
Well it is little complicated. I know little about mysql in general, I learned in my high school little about mysql but know I have to learn more.

Now every system of saving in my script is using ini. Now what is experience in combining those two systems?
For example if I use mysql just for player statistics/variables and ini for other stuff?
Reply
#6

Quote:
Originally Posted by Saddin
Посмотреть сообщение
Well it is little complicated. I know little about mysql in general, I learned in my high school little about mysql but know I have to learn more.

Now every system of saving in my script is using ini. Now what is experience in combining those two systems?
For example if I use mysql just for player statistics/variables and ini for other stuff?
You can combine them as you like. There won't be any technical problems with that until you want to link data from MySQL to data from INI. It's important to think about how you store the data - not where (MySQL/INI).

Say you have a Property system that allows players to own as many Properties as they like.

Using INI Files you would probably store the Owner in the Property's file/section.

In MySQL this should be done a bit differently, like DarkSkull already pointed out. You would create a new table with two fields - Player Name/UID and Property UID - which links both the Property and the Player, resulting in a list of Property Ownerships.

The first solution doesn't let you efficiently query all Properties of a Player. You must go through the file, retrieve each Prop's Owner and Compare it. If the data is buffered in Memory (an Array) it's the same, just a bit faster.
The second solution lets you retrieve a list of all Properties owned by a Player in one step.
It's getting complicated if you mix these (Ownership and Property Data). You would never do this of course, it's just an example.
Also MySQL is very optimized and a lot faster for these actions. Plus you can thread heavy queries, so that the Server basically doesn't have to do anything to get the data. This is getting important if you have a lot of data..


What I want to say with this is, it is okay to seperate different data to MySQL or INI if you can manage it, however it may get ugly and unneccessarily complex once you want to build a relation between data from INI and MySQL.
Make sure you know which data is going to be linked, and which is never going to.
At a later point you'll have to port even more stuff than you have to now. That's why it is good to think it through now than having to edit 20,000 lines later on.
Reply
#7

INI is very bad at storing lists of things because the whole thing is built on the key-value principle where every key needs to be unique. That's why you regularly see stuff like Vehicle5Mod13, which is hideous. I don't know why you would still want to use ini when you've got SQL. Except perhaps for its original purpose: storing configuration data.

To make the system in question I would actually recommend three tables: player, faction and factionMember. The latter one linking the two former ones together. It'll work with two tables as well if a player can only be in one faction at a time, but I prefer not to clutter the main player table if it's not absolutely necessary. See the tutorial in my sig about association tables.
Reply
#8

Only thing I would still use ini is because I have experience about it more than using mysql. So if I got this right:

I have to create tables which containts some variables for example:

Table Players (Level, Money, Deaths, Leader, FactionID, OwnPropertyID, ...)
Table Factions(FactionID, Slots, Leader, ...)
Table Properties (ID, Cost, Int, VW, ...)

So, if Im using all of these tables I can't do nothing like Property (using ini) and Players (using mysql), those two storages can't get along because it's complex, messy.

NaS, is that what are you thinking?

In MySQL way this linking need to get in relationship (and connects it via table key?) - is that correct and how will that work?

Vince, why would I need 3 tables: Players, Faction, FactionMember? Didn't get you when you said that and sentence after that? Why would I need seperate Faction and FactionMember. Why would I need those 2 tables at all when I can store FactionMember (as integer - id of faction), FactionRank (as integer - rank in faction) in 1 table Players. Than later if I want to get all players that have FactionMember == 2 (example) I would just go through all players (online and offline) and get their variable from table Players that is FactionMember == 2? Am I thinking wrong, is it possible like this?

I would really like to make this work. Because now with this I could make some online stats on website reading player variables from database.

I tried to copy-paste and study little the tutorials I found on this forum about mysql registration/login system and general other MySQL system and almost every other is using different technique. Somewhere is mentioned Saltion key, Corrupt check and similiar stuff but I dont know any of these details.

However I tried and scripted (copied codes from tutorials) and managed to make some simple mysql reg/login system with loading data from alive server/host but I have problem with that, can' connect to mysql online database.

I use correct and checked input info which is username, database name, database password but i don't know what host should i put? I tried from 'localhost', 'localhost:3036' (which says on my website cpanel), 'www.mywebsite.com:3036', but nothing of this will work. Someone know how to check host and what hostname should I put?

And thank you all for replying the topic.
Reply
#9

bump
Reply
#10

Nothing wrong with ini.
Just have to use it correctly, read/write process must be flawless.
I dont know if samp supports ini or is it just used as ini, if it supports it, then any flaw might be in the read/write source code and might not mistake by user.
Reply
#11

Could someone reply on my latest post here (not bump) and could someone help me with next:

Can I put all the player stats (pLeader, pRank, pFactionID, pLevel, pMoney, pDeaths, ...) into one table and later read from that table variable that I want to read. How can I read from pMoney for example. Will I read anyway all the variables from player after player login?

For example:

1) Player Connects
2) Player login (every variables from table PLAYERS are loaded into enum that I defined)
3) Player spawn
4) later when I want to use and compare any player variable (PlayerInfo[playerid][pMoney] = 3000) - I can play with it as I want.

Step 2 is a bit confusing, how would you do that? How to load every variable from mysql database table players to script and than later on play with those variables while player is online. What happens when player is offline? How to save those edited variables into mysql database?

What for do I need more tables except for example Property info from different table "properties". I still can' configure that what relationship is needed between table PLAYERS and table PROPERTIES?

I appreciate any help.
Reply
#12

Quote:
Originally Posted by Saddin
Посмотреть сообщение
Could someone reply on my latest post here (not bump) and could someone help me with next:

Can I put all the player stats (pLeader, pRank, pFactionID, pLevel, pMoney, pDeaths, ...) into one table and later read from that table variable that I want to read. How can I read from pMoney for example. Will I read anyway all the variables from player after player login?

For example:

1) Player Connects
2) Player login (every variables from table PLAYERS are loaded into enum that I defined)
3) Player spawn
4) later when I want to use and compare any player variable (PlayerInfo[playerid][pMoney] = 3000) - I can play with it as I want.

Step 2 is a bit confusing, how would you do that? How to load every variable from mysql database table players to script and than later on play with those variables while player is online. What happens when player is offline? How to save those edited variables into mysql database?

What for do I need more tables except for example Property info from different table "properties". I still can' configure that what relationship is needed between table PLAYERS and table PROPERTIES?

I appreciate any help.
You usually connect to host "127.0.0.1" or "localhost", the port should be a seperate argument of the respective PAWN function. User "root" would be the default when you just installed the Server.

I'd suggest you download XAMPP/WAMP (which include a Web Server, MySQL Server and more - but you probably already did) and open phpmyadmin. It's a (local) web tool to manage MySQL Tables, data and everything else related to MySQL with a GUI. Then, while reading some tutorials, you can play around with Tables and Queries (you can execute Queries right from phpmyadmin). That really helps understanding it before using it in another Scripting Language, which (imo) makes it a bit harder to understand when starting.

Regarding the Faction Leaderships/Property Ownerships - in your second last post you gave an example for the data structure of a Player/Property/Faction Database. It would be possible to do it that way but it's not the optimal solution - especially for Factions because Factions can have many Members.

Best would be having something like these Tables:

Players:

- UID (Unique ID - not PlayerID)
- Name
- Kills
- Deaths
- no info about ownerships/leaderships

Properties:

- UID
- Name
- Position...

Factions:

- UID
- Name
- ...

Property Ownerships:

- Player UID
- Property UID

Faction Memberships:

- Player UID
- Faction UID
- Member Rank (1 = Leader, 2 = Member, etc)

Both of the last 2 tables are only used for holding the Ownerships/Memberships and data that is directly related to that, no info about the actual Faction.

Now, it wouldn't be a problem storing the Property UID with the Player Data, or the Player UID with the Property Table.
But for Factions this will become a problem. You'd have to save 20 Player UIDs with the Main Data and this would automatically limit the Number of Players in any Faction depending how you make it - I've seen people create 50 columns (Member1, Member2, ..., Member50) for this...

With the seperate Table you can store and actually have as many Faction Members as you want. Literally.
Also you can now query all Faction Members by Faction, or all Faction Leaders of any Faction very easily.

Btw all of this is covered in many starter Tutorials. Most of them explain it a lot better than I can, so I guess the best you can do is follow those.
Reply
#13

you cant create the files only by thier names, you need to create it by id.
then create a loop, and check who is online.
Reply
#14

NaS, thanks for reply. I was looking for a lot of tutorials by now and went almost through all of them I found on this forum. I also searched and studied some gamemodes with mysql systems. I already installed wamp and configure all needed mysql connection in script, I made simple register/login system and I did some examples on queris on phpmyadmin of my localhost. Now I managed to store player data inside table PLAYERS and read from it on player connect.

Now if I get this right. PLAYERS table don't have any variable in PlayerInfo enum about ownership (house, business, ...) and also leadership (membership). Rather than that you propose using different tables that would only had for example:

Table Houses
UID of Player
House ID
House Owner (?)
House Int, ...

Table Business
UID of Player
Biz ID
Business Owner (?)
Business Int, ...

Table Factions
UID of Player
Player Rank (1, 2, 3, 4, 5)
Player Leader (1 - Police, 2 - Mafia, 3 - Gang) (is leader one of these)
Player Member (1 - Police, 2 - Mafia, 3 - Gang) (is member one of these) <---- (Faction ID) ?

And now the table factions should look something like this (if I'm right?):



Now comes these questions:

Should I also store Player Name in all of those tables because I need to know info about every player (if player have house or not, if player have business or not, is player in faction or not)?

Now I'm thinking that all these tables are some sort of similiar to original PLAYERS table. I'm not storing all those faction info, business info, house info into 1 table PLAYERS but I'm storing those in different tables to keep it optimized? It's easier and faster to work with it? Database is not so big and hard for CPU/RAM?

And question about thing I'm confused. On loading table PLAYERS into PlayerInfo enum all those variables in enum are defined and loaded to the script. Now... how it's getting really complicated for me. How the player who don't have faction info of it is connected (with uid, playerid?) is getting those informations from database. How the player who don't have the House variable in PlayerInfo enum can have House at all? Because table PLAYERS and table HOUSES are loaded differently. Houses have UID, Owner? and that stuff. If that House UID is not owned (Owner="NOTHING") what should info about player owning house would be? I hope you understand my question. I will try to illustrate my question:



Sorry if I waste your time.
Reply
#15

No need to save player name in all of the tables, just save the player's SQL id in the other tables as well, for example the house table and when you load the house, just fetch the player name from the player table by using the player's saved SQL id.
Reply
#16

Quote:
Originally Posted by Logic_
Посмотреть сообщение
No need to save player name in all of the tables, just save the player's SQL id in the other tables as well, for example the house table and when you load the house, just fetch the player name from the player table by using the player's saved SQL id.
Example please? (in script)
Reply
#17

I think you got me a bit wrong regarding the extra Table.
As I said before you don't have to do it that way, your current approach would work as well - but can bring problems with other systems (like Factions). Tell me if you want to stick with the current approach for Houses, then I can help you with that anyway. But for Factions I'd suggest you look at the rest of this reply.


You should take a look at some Tutorials that describe how to query data from multiple Tables in one Query (keyword: LEFT JOIN) before building the House/Faction Systems on your Server.

Example: http://www.mysqltutorial.org/mysql-left-join.aspx
Try to understand this (at least how they are connected, and why), then you will see the problem that I mentioned regarding Factions (Factions can have many members, you don't want to store 20 Members inside the Data Table).

I can help you getting the structure right but you'll have to learn the coding yourself.
Fully explaining LEFT JOIN here would be too much for me.

It becomes neccessary if you build a system that requires a many-to-many relation (eg. Players can be in multiple Factions, and Factions can have multiple Members).

If you do not want to make it this complex, store the Ownerships in the Players Table, not in the Houses/Factions Table. Reason: One Player can have only one Faction, but one Faction can have many Members (1-to-many relation). For Houses it technically doesn't matter but keeping a standard is a good idea.

Sorry, I didn't directly answer your recent post but I will if you tell me if you want to do it this way or another.
Reply
#18

Okay, I'm thinking this.

For faction system -> Player table (general storage of every player):
- UID
- Name
- Password
- Leader
- Member
- Rank
- ...

Every player has 3 variables for Faction (leader, member, rank) which contains integer. When I read those information in game I can know automatic that if player variable leader is 0 -> player isn't leader, if it is 1 - player is leader of faction id 1, and so on...
Same goes for member, Player variable member is 0 if the player isn't in any faction, 1 if the player is in faction id 1, and so on...
Player variable Rank can only be 0 - 5, 0 if it got 0 rank (not in faction), 1 - rank 1, 2 - rank 2, ...

That is how I'm thinking on making faction system regarding to saving player stats of faction into general table "PLAYERS" where players got also ... those other variables like UID, Name, Password...

__________________________________________________ _____________________


Now about House system and also other property kind of systems: Business, PersonalVehicles, ExtraProperties, AnythingElse...

Create for every new property kind of systems new table called for example Houses, Business, PersonalVehicles... which contains:

Table Houses:
- UID (house id, starts from 0 and is autoincrementing based on me creating new house)
- Owner (help me with this)
- Price
- IntX
- IntY
- IntZ
- VirtualWorld
- ... and so on

Table Business:
* same as houses
- UID (business id, ...)
- Owner (?)

Same for vehicles, and everything similiar to properties (and other similiar tables that players have some sort of connection to it)

Now, how to do it?

Please, correct me if I'm wrong from beginning in the post. What should you do to make more optimized/better because I'm looking for every detail but in some (not expert) level that I can make and control.
Reply
#19

?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)