AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Why wont this work? (https://forums.alliedmods.net/showthread.php?t=1228)

Nick 04-19-2004 21:57

Why wont this work?
 
Code:

#include <amxmodx>

new phrase[1][] = { "/hello" }

public say_event(id)
{
        new sid[10]
        num_to_str(id,sid,10)
        new said[192]
        read_args(said,191)
       
        for(new i = 0 ;i < 1; i += 1)
                if(containi(said,phrase[i]) != -1) {
                        set_hudmessage(225, 25, 25, -1.0, 0.32, 0, 2.0, 9.0, 0.8, 0.8, 2)   
            show_hudmessage(0,"Hello and welcome to this server")
            set_task(1.0,"client",0,sid,10)
            break
    }
}

public client(sid[])
{
        new id = str_to_num(sid)
        engclient_cmd(id,"say", "Hello and welcome to server")
    client_cmd(0, "spk ^"you are a ass hole^"")
       
}

public plugin_init()
{
        register_plugin("Say Hello","0.4","SneakerBoots")
        register_clcmd("say","say_event")
    return PLUGIN_CONTINUE
}

When you type /hello nothing happens :( Whats wrong with it?

xeroblood 04-19-2004 22:58

Well, one thing I noticed is you are Declaring a var inside the for loop Declaration [ie: for( new i = 0; .... ) ], which is okay, unless you use break inside of it, then Small won't like it anymore (i think it fails to deallocate the counters memory or something).. Simple fix, declare your counter var outside the for loop structure..

Also, public plugin_init() function doesn't require a return value.. so PLUGIN_CONTINUE was useless.. anyway, no harm there...

Some other stuff I changed around too, look in comments too...

Code:
#include <amxmodx> new phrase[2][] = { "hello", "hi" } public say_event( id ) {     new said[192], sid[2], i     read_args(said,191)     sid[0] = id     for( i = 0; i < 2; i++ )     {         if(containi(said,phrase[i]) > -1)         {             set_hudmessage(225, 25, 25, -1.0, 0.32, 0, 2.0, 9.0, 0.8, 0.8, 2)             show_hudmessage(0,"Hello and welcome to this server")             set_task(1.0,"client",0,sid,1)             break         }     }     return PLUGIN_HANDLED } public client(sid[]) {     new id = sid[0]     //  Using the word 'hello' or 'hi' (from phrase[] above) will cause an infinite loop..     // Think: if the player says hello, you call this function, which makes them say Hello again!     // I changed Hello to Hey..     client_cmd(id,"say ^"Hey! Welcome to This Server!^"")     client_cmd(0, "spk ^"you are a ass hole^"") } public plugin_init() {     register_plugin("Say Hello","0.4","SneakerBoots")     register_clcmd("say","say_event") }

Nick 04-20-2004 00:11

ty lemme look

dragonchaos 04-20-2004 00:34

Well couldn't you use the client_print , and just fake a client "say"

Nick 04-20-2004 00:36

I still got same problem anything thing else I got wrong?

Nick 04-20-2004 00:37

Quote:

Originally Posted by dragonchaos
Well couldn't you use the client_print , and just fake a client "say"

Ill try it

Nick 04-20-2004 00:51

nvm it works now but the speech keeps on repeating and doesnt stop...Whats going on wit that or is it just my server?

Nick 04-20-2004 00:55

nvm it works now but the speech keeps on repeating and doesnt stop...Whats going on wit that or is it just my server?

ts2do 04-20-2004 10:15

Code:
//EASIER: #include <amxmodx> public say_event(id) {    set_hudmessage(225, 25, 25, -1.0, 0.32, 0, 2.0, 9.0, 0.8, 0.8, 2)        show_hudmessage(0,"Hello and welcome to this server")    client(id)    engclient_cmd(id,"say", "Hello and welcome to server")    client_cmd(0, "spk ^"you are a ass hole^"") } public plugin_init() {    register_plugin("Say Hello","0.4","SneakerBoots")    register_clcmd("say /hello","say_event")     return PLUGIN_CONTINUE }

xeroblood 04-20-2004 12:03

@ts2do:
You have the return in the wrong function (return PLUGIN_CONTINUE should be in first function, not plugin_init() it isn't needed there)...

Also, you are calling client(id) which doesn't exist in your version anymore...

Also, for both of you, haw many people join your server and say /hello

In my server, they ussually say hello or hi (without the slash).. anyway...

I didn't alter Nick's original Logic, just pointed out (and fixed) a few spots that were incorrect, as well as point out a possible runtime error (infinite loops)..

I even tested it on my server before posting, and it worked fine..

Nick 04-20-2004 20:58

The speech didnt keep on repeating? It still does for me... :(


All times are GMT -4. The time now is 16:48.

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