AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Name Checker (https://forums.alliedmods.net/showthread.php?t=24996)

onfirenburnin420 03-05-2006 18:33

Name Checker
 
1 Attachment(s)
Okay, I just scripted this plugin and it will not complie without errors, here is the code and errors. Please help.
Code:
//------------------------ //  Amx Mod X Script //------------------------ // //    Name Checker //       -- Checks a clients name if they were added to the file, changes there name to the one in the file. // //------------------------ // //    Names Stored In: //       --/addons/amxmodx/configs/name_checker.ini // //       This file is created automatically when the plugin is run for the first time. //       The names are loaded on map change. // //------------------------ // //    Cvars: // //       nc_enable < 0=off | 1=on > //              --Enables/Disables map objective showing // // //------------------------ // //    Commands: // //       nc_add <steamid> <name> //              --Adds client to the name checker list. // //       nc_del <steamid> //              --Deletes client from the name checker list. // //------------------------ // //    Changelog: // //        v1.0 - Initial Build // //------------------------ #include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Name Checker","v1.0","Fire")     register_cvar("nc_enable","1")     register_concmd("nc_add","nc_add",ADMIN_IMMUNITY,"Adds a Name To Be Checked -- nc_add <steamid> <name>")     register_concmd("nc_del","nc_del",ADMIN_IMMUNITY,"Deletes a Name That Is Being Checked -- nc_del <steamid>") } public nc_add(id, level, cid) {     if(get_cvar_num("nc_enable") == 0)         return PLUGIN_HANDLED             if (!cmd_access(id, level, cid, 3))         return PLUGIN_HANDLED     new Arg1[32]     new Arg2[32]         read_argv(1, Arg1, 31)     read_argv(2, Arg2, 31)             new szConfigsdir[200]     get_configsdir(szConfigsdir, 199)         new szConfigfile[200]     format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)         new iLine, szLinestr[256], iLen     while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {         console_print(id,"%s's name is all ready being checked!", Arg2)             } else {         write_file("szConfigfile", "^"%s^" ^"%s^"", -1, Arg1, Arg2)             }         }     return PLUGIN_HANDLED } public nc_del(id, level, cid) {     if(get_cvar_num("nc_enable") == 0)         return PLUGIN_HANDLED             if (!cmd_access(id, level, cid, 2))         return PLUGIN_HANDLED     new Arg1[32]     read_argv(1, Arg1, 31)     new szConfigsdir[200]     get_configsdir(szConfigsdir, 199)         new szConfigfile[200]     format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)         new iLine, szLinestr[256], iLen     while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {         write_file("szConfigfile", "", iLine)         }     }     return PLUGIN_HANDLED } public client_authorized(id) {     if(get_cvar_num("nc_enable") == 0)         return PLUGIN_HANDLED             new szConfigsdir[200]     get_configsdir(szConfigsdir, 199)         new szConfigfile[200]     add(szConfigsdir, 199, "/name_checker.ini")     if(!file_exists(szConfigsdir)) {         write_file(szConfigfile, "; Name Checker -- By: Fire")         write_file(szConfigfile, "; -- Do Not Edit This --")     }         format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)         new szSteamid[35]     get_user_authid(id, szSteamid, 34)         new iLine, szLinestr[256], iLen         new szName[35], szStoredSteamid[35]         while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || !iLen) continue         parse(szLinestr, szStoredSteamid, 34, szName, 34)         if(equal(szSteamid, szStoredSteamid)) {             client_cmd("name %s", szName)         }     }     return PLUGIN_HANDLED }
Code:

/home/users/amxmodx/tmp3/phpXzBHPF.sma(78) : error 088: number of arguments does not match definition
/home/users/amxmodx/tmp3/phpXzBHPF.sma(143) : error 035: argument type mismatch (argument 1)

Please Help +karma :)

karlos 03-05-2006 18:45

compiles without error, but no warrenty if it works
Code:

#include <amxmodx>
#include <amxmisc>

public plugin_init() {
        register_plugin("Name Checker","v1.0","Fire")
        register_cvar("nc_enable","1")
        register_concmd("nc_add","nc_add",ADMIN_IMMUNITY,"Adds a Name To Be Checked -- nc_add <steamid> <name>")
        register_concmd("nc_del","nc_del",ADMIN_IMMUNITY,"Deletes a Name That Is Being Checked -- nc_del <steamid>")
}

public nc_add(id, level, cid) {

        if(get_cvar_num("nc_enable") == 0)
                return PLUGIN_HANDLED
               
        if (!cmd_access(id, level, cid, 3))
                return PLUGIN_HANDLED

        new Arg1[32]
        new Arg2[32]
       
        read_argv(1, Arg1, 31)
        read_argv(2, Arg2, 31)
               
        new szConfigsdir[200]
        get_configsdir(szConfigsdir, 199)
       
        new szConfigfile[200]
        format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)
       
        new iLine, szLinestr[256], iLen
        while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {
       
                if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {
                        console_print(id,"%s's name is all ready being checked!", Arg2)
                } else {
                        new temp_str[71]
                        format(temp_str, 70, "^"%s^" ^"%s^"", Arg1, Arg2)
                        write_file(szConfigfile, temp_str, -1)
                }
        }
        return PLUGIN_HANDLED
}


public nc_del(id, level, cid) {

        if(get_cvar_num("nc_enable") == 0)
                return PLUGIN_HANDLED
               
        if (!cmd_access(id, level, cid, 2))
                return PLUGIN_HANDLED

        new Arg1[32]
        read_argv(1, Arg1, 31)

        new szConfigsdir[200]
        get_configsdir(szConfigsdir, 199)
       
        new szConfigfile[200]
        format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)
       
        new iLine, szLinestr[256], iLen
        while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {
       
                if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {
                        write_file(szConfigfile, "", iLine)
                }
        }
        return PLUGIN_HANDLED
}

public client_authorized(id) {

        if(get_cvar_num("nc_enable") == 0)
                return PLUGIN_HANDLED
               
        new szConfigsdir[200]
        get_configsdir(szConfigsdir, 199)
       
        new szConfigfile[200]
        add(szConfigsdir, 199, "/name_checker.ini")

        if(!file_exists(szConfigsdir)) {
                write_file(szConfigfile, "; Name Checker -- By: Fire")
                write_file(szConfigfile, "; -- Do Not Edit This --")
        }
       
        format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)
       
        new szSteamid[35]
        get_user_authid(id, szSteamid, 34)
   
        new iLine, szLinestr[256], iLen
       
        new szName[35], szStoredSteamid[35]
       
        while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {
                if(szLinestr[0] == ';' || !iLen) continue

                parse(szLinestr, szStoredSteamid, 34, szName, 34)

                if(equal(szSteamid, szStoredSteamid)) {
                        client_cmd(id, "name %s", szName)
                }
        }
        return PLUGIN_HANDLED
}

do not pass strings as a word to write_file ( eg: szConfigfile must be szConfigfile and NOT "szConfigfile")
write_file does not support fomating ( as you did : write_file(szConfigfile, "^"%s^" ^"%s^"", -1, Arg1, Arg2) ), only file , text, linenum

Hawk552 03-05-2006 18:49

Bad indentation, but whatever.

Did you really write this? It looks like you grabbed some code from one of the scripts I wrote. I'm like the only person that ever uses the variable name "szLinestr".

Anyways, here:

EDIT: Oh, karlos got to it first, oh well.

Code:
//------------------------ //  Amx Mod X Script //------------------------ // //    Name Checker //       -- Checks a clients name if they were added to the file, changes there name to the one in the file. // //------------------------ // //    Names Stored In: //       --/addons/amxmodx/configs/name_checker.ini // //       This file is created automatically when the plugin is run for the first time. //       The names are loaded on map change. // //------------------------ // //    Cvars: // //       nc_enable < 0=off | 1=on > //              --Enables/Disables map objective showing // // //------------------------ // //    Commands: // //       nc_add <steamid> <name> //              --Adds client to the name checker list. // //       nc_del <steamid> //              --Deletes client from the name checker list. // //------------------------ // //    Changelog: // //        v1.0 - Initial Build // //------------------------ #include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("Name Checker","v1.0","Fire")     register_cvar("nc_enable","1")     register_concmd("nc_add","nc_add",ADMIN_IMMUNITY,"Adds a Name To Be Checked -- nc_add <steamid> <name>")     register_concmd("nc_del","nc_del",ADMIN_IMMUNITY,"Deletes a Name That Is Being Checked -- nc_del <steamid>") } public nc_add(id, level, cid) {     if(get_cvar_num("nc_enable") == 0)         return PLUGIN_HANDLED             if (!cmd_access(id, level, cid, 3))         return PLUGIN_HANDLED     new Arg1[32]     new Arg2[32]         read_argv(1, Arg1, 31)     read_argv(2, Arg2, 31)             new szConfigsdir[200]     get_configsdir(szConfigsdir, 199)         new szConfigfile[200]     format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)         new iLine, szLinestr[256], iLen     while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {         console_print(id,"%s's name is all ready being checked!", Arg2)             } else {                     new szWrite[62]         format(szWrite,61,"^"%s^" ^"%s^"",Arg1,Arg2)         write_file(szConfigfile,szWrite, -1)             }         }     return PLUGIN_HANDLED } public nc_del(id, level, cid) {     if(get_cvar_num("nc_enable") == 0)         return PLUGIN_HANDLED             if (!cmd_access(id, level, cid, 2))         return PLUGIN_HANDLED     new Arg1[32]     read_argv(1, Arg1, 31)     new szConfigsdir[200]     get_configsdir(szConfigsdir, 199)         new szConfigfile[200]     format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)         new iLine, szLinestr[256], iLen     while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {         write_file(szConfigfile, "", iLine)         }     }     return PLUGIN_HANDLED } public client_authorized(id) {     if(get_cvar_num("nc_enable") == 0)         return PLUGIN_HANDLED             new szConfigsdir[200]     get_configsdir(szConfigsdir, 199)         new szConfigfile[200]     add(szConfigsdir, 199, "/name_checker.ini")     if(!file_exists(szConfigsdir)) {         write_file(szConfigfile, "; Name Checker -- By: Fire")         write_file(szConfigfile, "; -- Do Not Edit This --")     }         format(szConfigfile, 199, "%s/name_checker.ini", szConfigsdir)         new szSteamid[35]     get_user_authid(id, szSteamid, 34)         new iLine, szLinestr[256], iLen         new szName[35], szStoredSteamid[35]         while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || !iLen) continue         parse(szLinestr, szStoredSteamid, 34, szName, 34)         if(equal(szSteamid, szStoredSteamid)) {             client_cmd(id,"name %s", szName)         }     }     return PLUGIN_HANDLED }

onfirenburnin420 03-05-2006 19:52

I saw it in some of suicid3's scripts and questioned it... he told me why he wrote like that and im picking it up, i guess :) btw thanks

onfirenburnin420 03-05-2006 20:27

hmmm.... still not working right, it dose not creat the file :?

Hawk552 03-05-2006 20:36

Quote:

Originally Posted by onfirenburnin420
hmmm.... still not working right, it dose not creat the file :?

You need to do an "if(!file_exists(<file>)) { write_file(...)" to create it.

onfirenburnin420 03-05-2006 21:06

i have that:
Code:
    if(!file_exists(szConfigfile)) {         write_file(szConfigfile, "; Name Checker -- By: Fire")         write_file(szConfigfile, "; -- Do Not Edit This --")     }

Xanimos 03-05-2006 21:33

this right here is horrible.
Code:
    while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || iLen <= 1 || equal(Arg1, szLinestr)) {         console_print(id,"%s's name is all ready being checked!", Arg2)             } else {                     new szWrite[62]         format(szWrite,61,"^"%s^" ^"%s^"",Arg1,Arg2)         write_file(szConfigfile,szWrite, -1)             }         }

make a "new szWrite" every iteration of the loop. and makes no sense. (On every line read, if it is a comment of if the line is empty or it is the person say name is already being check. Else make a new line.) So every line it reads that is not the player add the player?

Hawk im disappointed in you for not catching that. P.S: Since when are you the only one who codes like that? (Never)

onfirenburnin420 03-05-2006 21:43

so if i just do this it sould work?
Code:
    new iLine, szLinestr[256], iLen     while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen)) {         if(szLinestr[0] == ';' || iLen <= 1 || !equal(Arg1, szLinestr)) {             new szWrite[62]         format(szWrite,61,"^"%s^" ^"%s^"",Arg1,Arg2)         write_file(szConfigfile,szWrite, -1)                 console_print(id,"%s was added to the check list.", Arg2)                   }         }

Xanimos 03-05-2006 22:04

Code:
    new iLine, szLinestr[256], iLen     new bool:boolWrite = true     while(read_file(szConfigfile, iLine++, szLinestr, 255, iLen))     {         if(szLinestr[0] == ';' || !iLen) continue;         if(equal(Arg1, szLinestr))         {             boolWrite = false             break;              }     }     if(boolWrite)     {         new szWrite[62]         format(szWrite,61,"^"%s^" ^"%s^"",Arg1,Arg2)         write_file(szConfigfile,szWrite, -1)         console_print(id,"%s was added to the check list.", Arg2)     }     else         console_print(id,"%s was already in file. o_O" , Arg2)     return PLUGIN_HANDLED


All times are GMT -4. The time now is 20:21.

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