A small MYSQL storing/retrieving data based command. How?
#1

Hello, i was thinking alot, thinking more of how would my idea work nor can be made. I'am potentially confused and bothered on these kind of features that can possibly added on to my roleplay server. I know this kinda noob question, just dont care about it. Well, basicly i'am critically thinking on this feature (/factions), What does it do? Indeed, in short it shows all the factions , leaders, online members and total members. Im literally thinking this almost a week and i still have no clue how would this work based on my own idea and algorithm/codes. That doesn't mean im new on a typical PAWN language but im totally confused. I mean how could i make this?

My idea:
1. Create the factionlist table in the db.
2. Right after /makeleader command is executed the NAME of the given playerid and should be stored in "leader" row.
3. Then everytime /factions command is executed it will retrieve the data on factionlist table "leader" and should be shown like this one (Los Santos Police Dept. | Leader: %s, RetrieveLeaderRow value or var from factionlist table)
4. How about the total members of faction? (As far as i know, i would need to make a totalmembers row inside the LSPD table from the factionlist table, then increase/decrease the value everytime /accept invite has been executed and will obviously decrease the value everytime /quitfaction has been executed by a player inside the faction.
5. I would also like to make this on every faction such as FBI, SAN NEWS, GOV, and so on. So there would be different table inside the factionlist table such as (LSPD,FBI,LSFMD,Hitman, GOV and San News) every each factions have rows which is (leader,totalmembers, and online members)

I'm not confident with my idea and doesnt support it either, If im wrong please correct me. What i need is the codes and how would i do that? Is it even possible? What are the possible bugs and glitches that i could encounter in the future? I know this is not small favour and it is hardcode. Isn't it?

I would be very grateful and glad if you could show me the step and codes on this kind of idea. Please feel free to post below if you have some opinions and thoughts, i would also provide my necesary codes and commands if asked. Thank you.
Reply
#2

This is of how I thought of this:

- Main table factions with 2 columns: factionid (PRIMARY KEY and auto increment) and leader (default value 0).
- Child table factions_members with 2 columns: factionid (references to factions.factionid so if a faction is deleted from main table, all its members will be removed from this table as well) and userid (upon registering a unique ID for each player - references to players.userid).

For the query in /factions, you can use JOIN to get the player's name of the leader and COUNT for the total (rows) members of each faction.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
This is of how I thought of this:

- Main table factions with 2 columns: factionid (PRIMARY KEY and auto increment) and leader (default value 0).
- Child table factions_members with 2 columns: factionid (references to factions.factionid so if a faction is deleted from main table, all its members will be removed from this table as well) and userid (upon registering a unique ID for each player).

For the query in /factions, you can use JOIN to get the player's name of the leader and COUNT for the total (rows) members of each faction.
My callback to get player name is GetPlayerNameEx(giveplayerid) will that work too?

What are the possible codes to make this?
Reply
#4

Forget Pawn for now, the listed factions with their name, their leader and the total number of members will be done in SQL. I ran a couple of queries and that seems to do its job:
PHP код:
SELECT f.faction_name,IFNULL(p.name,""),COUNT(fm.useridFROM factions f LEFT JOIN players p ON p.userid=f.leader LEFT JOIN factions_members fm ON fm.factionid=f.factionid GROUP BY f.factionid
The result will be "faction name|leader*|total members".

*Empty if none.

All was done good except for some reason I cannot add foreign key constraint for my players table, I'll look into that later.

PS: In main table, add another column for the faction's name.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Forget Pawn for now, the listed factions with their name, their leader and the total number of members will be done in SQL. I ran a couple of queries and that seems to do its job:
PHP код:
SELECT f.faction_name,IFNULL(p.name,""),COUNT(fm.useridFROM factions f LEFT JOIN players p ON p.userid=f.leader LEFT JOIN factions_members fm ON fm.factionid=f.factionid GROUP BY f.factionid
The result will be "faction name|leader*|total members".

*Empty if none.

All was done good except for some reason I cannot add foreign key constraint for my players table, I'll look into that later.

PS: In main table, add another column for the faction's name.
Wow, thank you, I will try this one and update you the result.

Do you have skype? Maybe we could communicate faster
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
This is of how I thought of this:

- Main table factions with 2 columns: factionid (PRIMARY KEY and auto increment) and leader (default value 0).
- Child table factions_members with 2 columns: factionid (references to factions.factionid so if a faction is deleted from main table, all its members will be removed from this table as well) and userid (upon registering a unique ID for each player - references to players.userid).

For the query in /factions, you can use JOIN to get the player's name of the leader and COUNT for the total (rows) members of each faction.
Needs one more column to store rank. The player with the highest rank is then automatically the leader, so a faction can't be leaderless.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Forget Pawn for now, the listed factions with their name, their leader and the total number of members will be done in SQL. I ran a couple of queries and that seems to do its job:
PHP код:
SELECT f.faction_name,IFNULL(p.name,""),COUNT(fm.useridFROM factions f LEFT JOIN players p ON p.userid=f.leader LEFT JOIN factions_members fm ON fm.factionid=f.factionid GROUP BY f.factionid
The result will be "faction name|leader*|total members".

*Empty if none.

All was done good except for some reason I cannot add foreign key constraint for my players table, I'll look into that later.

PS: In main table, add another column for the faction's name.
PHP код:
#1146 - Table 'stratumrp.factions' doesn't exist 
Weird, even though ive already created that table.
Reply
#8

Bump, i still need help!
Reply
#9

Quote:
Originally Posted by Noris
Посмотреть сообщение
PHP код:
#1146 - Table 'stratumrp.factions' doesn't exist 
Weird, even though ive already created that table.
Are you sure you created the table in the database "stratumrp"? Posting some screenshots would be useful for us.

Quote:
Originally Posted by Vince
Посмотреть сообщение
Needs one more column to store rank. The player with the highest rank is then automatically the leader, so a faction can't be leaderless.
Good idea. I suppose when a player is deleted from the main table, leader should be set to null on its own and with a query to check if leader is null to load the player's name with the highest rank instead.
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Are you sure you created the table in the database "stratumrp"? Posting some screenshots would be useful for us.



Good idea. I suppose when a player is deleted from the main table, leader should be set to null on its own and with a query to check if leader is null to load the player's name with the highest rank instead.
Yes I've created "stratumrp.factions" table before I ran that query.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)