AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random msg (https://forums.alliedmods.net/showthread.php?t=129049)

FlyingHorse 06-08-2010 09:42

random msg
 
Why wont this work?

PHP Code:

#include <amxmodx>
#include <colorchat>

#define MAX_MSG 4

new const PLUGIN[ ] = "Advertisements"
new const VERSION[ ] = "1.0"
new const AUTHOR[ ] = "FlyingHorse"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}
public 
client_putinserver(id)
{
    
    
set_task(10.0"advertisements"id)
}

public 
advertisements(id)
{
    switch (
random_num(1MAX_MSG))
    {
        case 
1:
        {
            
            
ColorChat(idRED"lol")
        }
        case 
2:
        {
            
ColorChat(idRED"blah")
        }
        case 
3:
        {
            
ColorChat(idRED"Drekes has a ponytail!")
        }
        case 
4:
        {
            
ColorChat(idRED"omfg")
        }
    }
    
set_task(20.0"advertisements"id)



shuttle_wave 06-09-2010 02:10

Re: random msg
 
do it this way. much more better way.

PHP Code:

/*
*    -----------------
*     Coded in 2010, 
*     Shuttle_Wave
*     -----------------
*     
*    .:: Description ::.
*     
*     Advertisement Plugin
*
*    .:: Contacts ::.
*
*    Email: [email protected]
*
*    Steam: shuttle_wave or lengjonathon

*/
#pragma semicolon 1

#include <amxmodx>

// Define the Plugin Version
new const VERSION[] = { "1.0" };

new 
p_Advertisement;

public 
plugin_init()
{
    
register_plugin("Advertise Plugin."VERSION"Shuttle_Wave");
    
    
p_Advertisement    register_cvar("server_advert_time",    "180.0");

    if( 
get_pcvar_float(p_Advertisement) > 0.0 )
        
set_task(get_pcvar_float(p_Advertisement), "taskAdvertise"___"b");
}

public 
taskAdvertise()
{
    
client_printc(0"Advertisement Plugin Testing by Shuttle_Wave");
}

// Colour Chat
stock client_printc(const id, const input[], any:...)
{
    new 
count 1players[32];
    static 
msg[191];
    
vformat(msg190input3);
    
    
replace_all(msg190"!g""^x04"); // Green Color
    
replace_all(msg190"!n""^x01"); // Default Color
    
replace_all(msg190"!t""^x03"); // Team Color
    
    
if (idplayers[0] = id; else get_players(playerscount"ch");
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i]);
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }



fysiks 06-09-2010 03:00

Re: random msg
 
It's better to only have one task than have 32 tasks all doing the same thing.

shuttle_wave 06-09-2010 03:04

Re: random msg
 
Quote:

Originally Posted by fysiks (Post 1203915)
It's better to only have one task than have 32 tasks all doing the same thing.

my one or his version?

FlyingHorse 06-09-2010 08:28

Re: random msg
 
ehm.. i wanted help to fix my code. I would have posted in suggestions, requests if i wanted a new plugin :) .. Im a beginner and im still learning. In fact i started like 2 weeks ago. I'd like help, not a new plugin, could anyone just help me fix whats not working in my code? :)

grimvh2 06-09-2010 08:54

Re: random msg
 
Quote:

Originally Posted by shuttle_wave (Post 1203919)
my one or his version?

Ur version, hes version is running a task for all players on the server. And hes not removing the task if players disconnect so that will probally get fucked up to.

I blame client_putinserver, try client_authorized or client_connect, else hook the Spawn event with ham.

fysiks 06-09-2010 12:47

Re: random msg
 
Quote:

Originally Posted by shuttle_wave (Post 1203919)
my one or his version?

Your code does what I suggested already (you should know that :)).

Quote:

Originally Posted by FlyingHorse (Post 1204068)
ehm.. i wanted help to fix my code. I would have posted in suggestions, requests if i wanted a new plugin :) .. Im a beginner and im still learning. In fact i started like 2 weeks ago. I'd like help, not a new plugin, could anyone just help me fix whats not working in my code? :)

He didn't post a new plugin, he posted a plugin that shows you how to do it more efficiently. If you notice, his plugin will not do what you are trying to do.

Quote:

Originally Posted by grimvh2 (Post 1204086)
I blame client_putinserver, try client_authorized or client_connect, else hook the Spawn event with ham.

I seriously doubt that is the problem. putinserver is probably one of the better ones to use.

@FlyingHorse, when you post code you can't just say "why doesn't this work," you need to explain what doesn't work about it. Does it compile? Does it have any errors? If it does compile and there are no errors you need to say that. This type of information will get you the best response.

Also, debugging is a skill everybody needs to learn. 1. It creates less posts here. 2. It will usually solve your problem much more promptly than waiting for people to respond to you post.

This is something that I would use:

PHP Code:

#include <amxmodx>
#include <colorchat>

new const szMessages[][] = {
    
"lol",
    
"blah",
    
"Drekes has a ponytail!",
    
"omfg"
}

public 
plugin_init()
{
    
// set_task()
}

public 
advertisements(id)
{
    
ColorChat(0REDszMessages[random(sizeof(szMessages))])
    
// Or loop through players if you want them to have different messages.



drekes 06-09-2010 14:40

Re: random msg
 
Why is my ponytail in there? I don't think it is usefull information to advertise.

grimvh2 06-10-2010 12:25

Re: random msg
 
@fysiks, I know what I say. I make more private then public plugins and when testing those plugins I occur alot of problems with using tasks when people are connecting and I never use client_putinserver since it always gave problems.

Brreaker 06-10-2010 12:59

Re: random msg
 
Quote:

Originally Posted by grimvh2 (Post 1205022)
@fysiks, I know what I say. I make more private then public plugins and when testing those plugins I occur alot of problems with using tasks when people are connecting and I never use client_putinserver since it always gave problems.

As far as I know ( I may be mistaking ):
client_putinserver = client starting to connect ( console connecting )
client_connected = client is on the server, ready to choose the team...


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

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