AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Why does my code not work? CS 1.6 (https://forums.alliedmods.net/showthread.php?t=277672)

JavoL 01-13-2016 15:28

Why does my code not work? CS 1.6
 
Okay so I'm making a small plugin called Welcome Message :3
I'm a beginner so what does the plugin do is when a player joins a server public client_connect(id) it will print a message in chat "Welcome to the server blah blah blah" but in color! The thing is when I open cs and test it nothing happens! :nono:
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <colorchat> //I'm using colorchat for colors :3

#define PLUGIN "WelcomeMessage"
#define VERSION "1.0"
#define AUTHOR "JavoL" //<-- That's my name :O


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)    
}

public 
client_connect(id)
{
    new 
szName[33//User's name
    
get_user_name(idszNamecharsmax(szName)) //Well... You kno'
    
ColorChat(idTEAM_COLOR"^3Dobrodosao na server ^4%s^3! ^3Say: ^4/pravila ^3da vidite pravila servera."szName//Message


If you can see the problem please, REPLY!

addons_zz 01-13-2016 16:08

Re: Why does my code not work? CS 1.6
 
Try use client_putinserver(id) using a task, instead of just client_connect. Is very good for start to see others well codes plugins. Then see also: Welcome message plugin ? and https://www.google.com/#q=welcome message amx mod x site:forums.alliedmods.net

fysiks 01-13-2016 21:13

Re: Why does my code not work? CS 1.6
 
client_putinserver() won't work reliably (because it will be behind all the CS menus and likely disappear before you get on a team). You need to set a task in client_putinserver() to wait a few seconds at least if you want that player to see it.

Spirit_12 01-13-2016 21:52

Re: Why does my code not work? CS 1.6
 
Use set_task native with a delay of a few seconds.

https://www.amxmodx.org/api/amxmodx/set_task

abdobiskra 01-14-2016 07:00

Re: Why does my code not work? CS 1.6
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat> //I'm using colorchat for colors :3

#define PLUGIN "WelcomeMessage"
#define VERSION "1.0"
#define AUTHOR "JavoL" //<-- That's my name :O


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR
}

public 
client_putinserver(id)
{
    if(
is_user_connected(id))        
    
set_task(8.0"welcome"id)

}
public 
welcome(id)
{
    new 
szName[33//User's name
    
get_user_name(idszNamecharsmax(szName)) //Well... You kno'
    
ColorChat(idTEAM_COLOR"^3Dobrodosao na server ^4%s^3! ^3Say: ^4/pravila ^3da vidite pravila servera."szName//Message



siriusmd99 01-14-2016 09:27

Re: Why does my code not work? CS 1.6
 
Quote:

Originally Posted by abdobiskra (Post 2383203)
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat> //I'm using colorchat for colors :3

#define PLUGIN "WelcomeMessage"
#define VERSION "1.0"
#define AUTHOR "JavoL" //<-- That's my name :O


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR
}

public 
client_putinserver(id)
{
    if(
is_user_connected(id))        
    
set_task(8.0"welcome"id)

}
public 
welcome(id)
{
    new 
szName[33//User's name
    
get_user_name(idszNamecharsmax(szName)) //Well... You kno'
    
ColorChat(idTEAM_COLOR"^3Dobrodosao na server ^4%s^3! ^3Say: ^4/pravila ^3da vidite pravila servera."szName//Message



Actually your code is wrong. Wtf you are checking on putin and after 8 seconds you are not checking if player is connected?
And you should check if task exists so it would be will exactly at 8 seconds.

This code is correct:



PHP Code:

#include <amxmodx>
#include <colorchat>

#define PLUGIN "WelcomeMessage"
#define VERSION "1.0"
#define AUTHOR "JavoL"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR); 
}

public 
client_putinserver(id)
{      
    if(
task_exists(id))
         
remove_task(id);

    
set_task(8.0"welcome_msg"id);
}

public 
welcome_msg(id)
{
    if(!
is_user_connected(id)) return;
    new 
szName[33];
    
get_user_name(idszNamecharsmax(szName));
    
ColorChat(idTEAM_COLOR"^3Dobrodosao na server ^4%s^3! ^3Say: ^4/pravila ^3da vidite pravila servera."szName);



Spirit_12 01-14-2016 14:24

Re: Why does my code not work? CS 1.6
 
Stop using words like"WTF" on this forum. Keeping things classy won't hurt anyone.

Also, would it not be better to remove task on client_disconnect than checking on new connect, if the task exists?

siriusmd99 01-14-2016 16:58

Re: Why does my code not work? CS 1.6
 
Quote:

Originally Posted by Spirit_12 (Post 2383307)
Stop using words like"WTF" on this forum. Keeping things classy won't hurt anyone.

Also, would it not be better to remove task on client_disconnect than checking on new connect, if the task exists?

No, because you hook both putin and disconnect . There is no need to do it.

Bugsy 01-14-2016 19:26

Re: Why does my code not work? CS 1.6
 
PHP Code:

#include <amxmodx>
#include <colorchat>

const TaskWelcome 123213;

#define PLUGIN "WelcomeMessage"
#define VERSION "1.0"
#define AUTHOR "JavoL"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR); 
}

//Player connects, set_task() will delay 8 seconds before calling welcome_msg(). This allows the player
//to get past the MOTD and team selection menus. There's no guarantee he will finish this stuff before 8
//seconds but this is a popular number for this type of thing. A random value is also added to the task-id
//so it can be more unique to this particular purpose. If you are doing multiple things with tasks, you 
//need a way to make each unique.
public client_putinserverid )
{      
    
set_task8.0 "welcome_msg" id TaskWelcome );
}

//A player disconnected so remove the welcome_msg task so it does not get called since the player isn't
//here anymore.
public client_disconnectid )
{
    
//You do not need to first check if task_exists(). You can just call remove_task() and if a task 
    //exists it will be removed. If no task exists then nothing happens. It is one less native call this way.
    
remove_taskid TaskWelcome );
}

//Show welcome message.
public welcome_msgid )
{
    new 
szName33 ];
    
get_user_nameid-TaskWelcome ,  szName charsmaxszName ) );
    
ColorChat(id-TaskWelcome TEAM_COLOR"^3Dobrodosao na server ^4%s^3! ^3Say: ^4/pravila ^3da vidite pravila servera." szName );



JusTGo 01-15-2016 05:53

Re: Why does my code not work? CS 1.6
 
Quote:

Originally Posted by Bugsy (Post 2383401)
PHP Code:

#include <amxmodx>
#include <colorchat>

const TaskWelcome 123213;

#define PLUGIN "WelcomeMessage"
#define VERSION "1.0"
#define AUTHOR "JavoL"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR); 
}

//Player connects, set_task() will delay 8 seconds before calling welcome_msg(). This allows the player
//to get past the MOTD and team selection menus. There's no guarantee he will finish this stuff before 8
//seconds but this is a popular number for this type of thing. A random value is also added to the task-id
//so it can be more unique to this particular purpose. If you are doing multiple things with tasks, you 
//need a way to make each unique.
public client_putinserverid )
{      
    
set_task8.0 "welcome_msg" id TaskWelcome );
}

//A player disconnected so remove the welcome_msg task so it does not get called since the player isn't
//here anymore.
public client_disconnectid )
{
    
//You do not need to first check if task_exists(). You can just call remove_task() and if a task 
    //exists it will be removed. If no task exists then nothing happens. It is one less native call this way.
    
remove_taskid TaskWelcome );
}

//Show welcome message.
public welcome_msgid )
{
    new 
szName33 ];
    
get_user_nameid-TaskWelcome ,  szName charsmaxszName ) );
    
ColorChat(idTEAM_COLOR"^3Dobrodosao na server ^4%s^3! ^3Say: ^4/pravila ^3da vidite pravila servera." szName );



ColorChat(id >>>> ColorChat(id-TaskWelcome ?


All times are GMT -4. The time now is 09:25.

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