Raised This Month: $ Target: $400
 0% 

Why does my code not work? CS 1.6


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JavoL
New Member
Join Date: Jan 2016
Old 01-13-2016 , 15:28   Why does my code not work? CS 1.6
Reply With Quote #1

Okay so I'm making a small plugin called Welcome Message
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!
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!
__________________
"When life hits you, you don't hit life, you tell your mom..." -JavoL
MoM <3
JavoL is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-13-2016 , 16:08   Re: Why does my code not work? CS 1.6
Reply With Quote #2

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
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-14-2016 at 19:19. Reason: spelling fix
addons_zz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-13-2016 , 21:13   Re: Why does my code not work? CS 1.6
Reply With Quote #3

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.
__________________
fysiks is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 01-13-2016 , 21:52   Re: Why does my code not work? CS 1.6
Reply With Quote #4

Use set_task native with a delay of a few seconds.

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

Last edited by Spirit_12; 01-13-2016 at 21:54.
Spirit_12 is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 01-14-2016 , 07:00   Re: Why does my code not work? CS 1.6
Reply With Quote #5

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

__________________

Last edited by abdobiskra; 01-14-2016 at 07:00.
abdobiskra is offline
Send a message via Skype™ to abdobiskra
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-14-2016 , 09:27   Re: Why does my code not work? CS 1.6
Reply With Quote #6

Quote:
Originally Posted by abdobiskra View Post
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);

siriusmd99 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 01-14-2016 , 14:24   Re: Why does my code not work? CS 1.6
Reply With Quote #7

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?
__________________
Spirit_12 is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 01-14-2016 , 16:58   Re: Why does my code not work? CS 1.6
Reply With Quote #8

Quote:
Originally Posted by Spirit_12 View Post
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.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-14-2016 , 19:26   Re: Why does my code not work? CS 1.6
Reply With Quote #9

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 );

__________________

Last edited by Bugsy; 01-15-2016 at 08:29.
Bugsy is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 01-15-2016 , 05:53   Re: Why does my code not work? CS 1.6
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
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 ?
__________________
JusTGo is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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