y_ini search
#1

How can I make a command search through all the user scriptfiles made by y_ini, for a specific value? Let's say for an example I want to make a list of top 10 richest players or I don't know.
Reply
#2

Sounds interesting tho, I'd like to know this as I use yini too. I think it has something to do with ParseFile but not pretty sure.
Reply
#3

I would not recommend doing these with y_ini, at least not without keeping track of that top 10 richest players...
You would need to loop thru all users (files) using file manager plugin (https://sampforum.blast.hk/showthread.php?tid=92246). Point is, you need to open each file, read that value. Than check if he is in top 10, if he is insert (and kick out the last one) if not just continue (opet next user file). Opening, reading and closing is a huge server overhead so i guess you will need to keep track of that richest players in some separate file...One easy way would be to hook onto Get/Set PlayerMoney and keep track of all players money in sqlite/mysql
Reply
#4

Sounds good. You need to create a folder "RichestPlayer", Check the player money , Create a new file in "RichestPlayer".So etc.

When the top 10 RichestPlayer has $999999 money and the top 11 Richestplayer has $1000000 money , replace them (by deleting the file)
Reply
#5

Or maybe create a single .txt file that saves user's money like so:
Jason_White | $3000
Maria_White | $9543

and just read that one .txt file to compare the values?
Reply
#6

I'd make this completely without files (at least during runtime).

Make an array for the richest players (size of 10 for example) and store playernames and the according money inside it.

Then you can occasionally check if any player has more money as anyone else in that list and put him in accordingly.

Then load/save it from/to a file in OnGameModeInit/Exit.

Doing this with files during runtime has many drawbacks.

You have to either use a file system (like y_ini) which is generally slower for this application or re-write the whole file if the order changes (which can be very often if you have many rich players online).

The array lets u just switch two entries (or more if you need to reorder) and it's a LOT faster.
Reply
#7

Quote:
Originally Posted by NaS
Посмотреть сообщение
I'd make this completely without files (at least during runtime).

Make an array for the richest players (size of 10 for example) and store playernames and the according money inside it.

Then you can occasionally check if any player has more money as anyone else in that list and put him in accordingly.

Then load/save it from/to a file in OnGameModeInit/Exit.

Doing this with files during runtime has many drawbacks.

You have to either use a file system (like y_ini) which is generally slower for this application or re-write the whole file if the order changes (which can be very often if you have many rich players online).

The array lets u just switch two entries (or more if you need to reorder) and it's a LOT faster.
I kinda do get the idea of your point, but can you give a little explenation in code?
Reply
#8

Quote:
Originally Posted by saffierr
Посмотреть сообщение
I kinda do get the idea of your point, but can you give a little explenation in code?
Of course.

Do you need the code for the sorting/keeping the array "up-to-date" or with the saving/loading part?
Reply
#9

with the sorting/keeping part please.


If you don't mind, both of them, just if you're in the mood for it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)