AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can this plugin works? (https://forums.alliedmods.net/showthread.php?t=87505)

AlejandroSk 03-12-2009 22:41

Can this plugin works?
 
hi , im a noob on scripting and im training and i make a little script for my server and wanna know if its correct =(

PHP Code:

 #include <amxmodx>

#define plugin_name "Block Change Name"
#define plugin_version "0.1"
#define plugin_author "AlejandroSk"

new name[32]
new 
name2[32]

public 
plugin_init()
{
    
register_plugin(plugin_nameplugin_versionplugin_author)
    
register_logevent("EventRoundStart"2"1=Round_Start");
}

public 
client_connect(id)
{
    
name[id] = get_user_name(idname31)
    
client_print(idprint_chat"Welcome %s to %hostname%"name)
}

public 
EventRoundStart(id)
{
    
name2[id] = get_user_name(idname231)
    if (
name[id] != name2[id])
    {
        
client_cmd(id"name %s" name)
        
client_print(id print_chat"%s , You cant change your name in this server !" name)
    
    }


please dont -karma me just for dont be a pro scripter

[ --<-@ ] Black Rose 03-13-2009 00:19

Re: Can this plugin works?
 
There's no such thing as "%hostname%"
You will have to use
Code:
new hostname[64]; get_cvar_string("hostname", hostname, 63);

Also client_connect is way before they are able to see the chat. Use client_putinserver() and then set_task() to show the message.
Here's an example:
Code:
public client_putinserver(id)  set_task(5.0, "show_message", id);   public show_message(id) {  new name[32];  get_user_name(id, name, 31);    new hostname[64];  get_cvar_string("hostname", hostname, 63);    client_print(id, print_chat, "Welcome %s to %s", name, hostname); }

There are better ways to check if player changes his name.
Code:
public client_infochanged(id) {  if ( ! is_user_connected(id) )   return;    new newname[32], oldname[32];    get_user_name(id, oldname, 31);  get_user_info(id, "name", newname, 31);    if ( ! equal(newname, oldname) ) {         client_cmd(id, "name %s" , name);         client_print(id , print_chat, "%s , You cant change your name in this server !" , name);  } }

grankee 03-13-2009 04:41

Re: Can this plugin works?
 
Quote:

client_cmd(id, "name %s" , name);
should be
Code:

client_cmd(id, "name %s" , oldname);
but if client is death, his name is player and type in console
Code:

name test
name player

(like this plugin), name will not change to old, some bug

anakin_cstrike 03-13-2009 05:17

Re: Can this plugin works?
 
Actually:
PHP Code:

client_cmdid"name ^"%s^""whatever ); 

But this is more efficient:
Code:
#include <amxmodx> #include <fakemeta> #include <amxmisc> #define PLUGIN_NAME "No Name Change" #define PLUGIN_VERSION "0.1" #define PLUGIN_AUTHOR "VEN" new const g_reason[] = "[NNC] Sorry, name change isn't allowed on this server!" new const g_name[] = "name" public plugin_init() {     register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)     register_forward(FM_ClientUserInfoChanged, "fwClientUserInfoChanged") } public fwClientUserInfoChanged(id, buffer) {     if (!is_user_connected(id))         return FMRES_IGNORED;     if ( is_user_admin ( id ) )         return PLUGIN_HANDLED;     static name[32], val[32]     get_user_name(id, name, sizeof name - 1)     engfunc(EngFunc_InfoKeyValue, buffer, g_name, val, sizeof val - 1)     if (equal(val, name))         return FMRES_IGNORED;     engfunc(EngFunc_SetClientKeyValue, id, buffer, g_name, name)     console_print(id, "%s", g_reason)     return FMRES_SUPERCEDE; }
I can't find the thread, so i posted the code.

[ --<-@ ] Black Rose 03-13-2009 12:06

Re: Can this plugin works?
 
Quote:

Originally Posted by anakin_cstrike (Post 779515)
Actually:
PHP Code:

client_cmdid"name ^"%s^""whatever ); 

But this is more efficient:

Code:
</p><p>#include <amxmodx></p><p>#include <fakemeta></p><p>#include <amxmisc></p><p>&nbsp;</p><p>#define PLUGIN_NAME "No Name Change"</p><p>#define PLUGIN_VERSION "0.1"</p><p>#define PLUGIN_AUTHOR "VEN"</p><p>&nbsp;</p><p>new const g_reason[] = "[NNC] Sorry, name change isn't allowed on this server!"</p><p>&nbsp;</p><p>new const g_name[] = "name"</p><p>&nbsp;</p><p>public plugin_init() {</p><p> register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)</p><p> register_forward(FM_ClientUserInfoChanged, "fwClientUserInfoChanged")</p><p>}</p><p>&nbsp;</p><p>public fwClientUserInfoChanged(id, buffer) {</p><p> if (!is_user_connected(id))</p><p> return FMRES_IGNORED;</p><p> if ( is_user_admin ( id ) )</p><p> return PLUGIN_HANDLED;</p><p>&nbsp;</p><p> static name[32], val[32]</p><p> get_user_name(id, name, sizeof name - 1)</p><p> engfunc(EngFunc_InfoKeyValue, buffer, g_name, val, sizeof val - 1)</p><p> if (equal(val, name))</p><p> return FMRES_IGNORED;</p><p>&nbsp;</p><p> engfunc(EngFunc_SetClientKeyValue, id, buffer, g_name, name)</p><p> console_print(id, "%s", g_reason)</p><p>&nbsp;</p><p> return FMRES_SUPERCEDE;</p><p>}</p><p>&nbsp;</p><p>


I can't find the thread, so i posted the code.

No, it is not more efficient.

anakin_cstrike 03-13-2009 12:57

Re: Can this plugin works?
 
And why you say that? because is more code ? :)

IneedHelp 03-13-2009 13:29

Re: Can this plugin works?
 
Why in that code there's a fakemeta forward instead of the normal client_infochanged ?

AntiBots 03-13-2009 13:48

Re: Can this plugin works?
 
Quote:

Originally Posted by IneedHelp (Post 779792)
Why in that code there's a fakemeta forward instead of the normal client_infochanged ?

I test and have the same reaccion.

fysiks 03-13-2009 14:23

Re: Can this plugin works?
 
The FM forward is an alternate (better?) method to hook the event of changing one's info.

AlejandroSk 03-13-2009 14:40

Re: Can this plugin works?
 
thanks for ur help


All times are GMT -4. The time now is 08:59.

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