AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Ini Check Player Exists (https://forums.alliedmods.net/showthread.php?t=295199)

DarthMan 03-19-2017 05:49

[HELP] Ini Check Player Exists
 
Hello. I am running into a problem with my script for my HL1 server. It basically reports players and stores them in an ini file. The problem is that I don't know how to make it only add the reported player to the ini file if it wasn't already reported by the reporter.I use ReporterName and ReportedName vars. Thanks!

Code:

get_user_name(id, ReporterName, charsmax(ReporterName));
Code:

new Player = find_player("bl", ReportedName);

DarthMan 03-19-2017 07:26

Re: [HELP] Ini Check Player Exists
 
I almost did it, but it's not perfect yet.

fysiks 03-19-2017 13:49

Re: [HELP] Ini Check Player Exists
 
So, do you have an actual question? If you have code already, you need to attach the file so that we can see what you are working with. Then, explain what exactly your problem is.

Really the only thing that we can say at this point is: If you don't want to duplicate something in the file the you have to check if it exists first and if it does, don't add it again.

DarthMan 03-19-2017 14:37

Re: [HELP] Ini Check Player Exists
 
Quote:

Originally Posted by fysiks (Post 2504853)
So, do you have an actual question? If you have code already, you need to attach the file so that we can see what you are working with. Then, explain what exactly your problem is.

Really the only thing that we can say at this point is: If you don't want to duplicate something in the file the you have to check if it exists first and if it does, don't add it again.

It is not finished yet, for specific reasons I will upload it on pastebin.
http://pastebin.com/qxj1Ht00

I would like it to print a message that the player was already reported by the user.
Thanks, and upload it back to pastebin as private 1 day.
The reason why i don't really want my plugin to be public is because ti is specifically made for my HL server so it's better to just come back with a link that will be active for only 24 hours.

Natsheh 03-19-2017 17:11

Re: [HELP] Ini Check Player Exists
 
PHP Code:

 new flags get_user_flags(Player); 

use this inside the if is_user_connected statement

fysiks 03-19-2017 19:12

Re: [HELP] Ini Check Player Exists
 
1 Attachment(s)
There are many thing wrong with this code:
  1. The file path for your file will never change while the server is running. Because of this, the file path should only be obtained once in plugin_init() and then stored globally.
  2. ReporterName is a string and should never be index with id (or anything else unless you are trying to reference single characters.
  3. To check if the player is or isn't the player executing the command you should use the entity index. In your case, you would check "id == Player" or "id != Player" where Player is the result of cmd_target().
  4. You should avoid getting any names, or doing anything really, until after you know that you are absolutely going to use them. That means that you should do the "self" check and the immunity check first. The only code that should exist before these is the code that these checks require. Nothing more. Basically, do the simplest checks first.
  5. You should always use SteamID when you want to unique identify a player because they can change their name to their hearts content and flood this plugin.
  6. To be able to do what you originally asked, you need to store the information in a way that it can be easily processed. Storing it as a sentence will not work reliable or efficiently. So, you should store the data in a structured format. For example, I would probably store it using tab delimiting (tabs because it's unlikely that a tab character will exist in the data normally).

P.S. Nothing on the internet is temporary. Also, there is no need to hide a plugin like this. The concept and code are both trivial. I've attached the original plugin so that people looking at this thread in the future will have a reference for my comments.

DarthMan 03-20-2017 02:34

Re: [HELP] Ini Check Player Exists
 
Quote:

Originally Posted by fysiks (Post 2504973)
There are many thing wrong with this code:
  1. The file path for your file will never change while the server is running. Because of this, the file path should only be obtained once in plugin_init() and then stored globally.
  2. ReporterName is a string and should never be index with id (or anything else unless you are trying to reference single characters.
  3. To check if the player is or isn't the player executing the command you should use the entity index. In your case, you would check "id == Player" or "id != Player" where Player is the result of cmd_target().
  4. You should avoid getting any names, or doing anything really, until after you know that you are absolutely going to use them. That means that you should do the "self" check and the immunity check first. The only code that should exist before these is the code that these checks require. Nothing more. Basically, do the simplest checks first.
  5. You should always use SteamID when you want to unique identify a player because they can change their name to their hearts content and flood this plugin.
  6. To be able to do what you originally asked, you need to store the information in a way that it can be easily processed. Storing it as a sentence will not work reliable or efficiently. So, you should store the data in a structured format. For example, I would probably store it using tab delimiting (tabs because it's unlikely that a tab character will exist in the data normally).

P.S. Nothing on the internet is temporary. Also, there is no need to hide a plugin like this. The concept and code are both trivial. I've attached the original plugin so that people looking at this thread in the future will have a reference for my comments.

All right, it's ok then :-)


All times are GMT -4. The time now is 18:02.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.