Raised This Month: $ Target: $400
 0% 

Examine this plugin.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cader
Senior Member
Join Date: Mar 2007
Old 12-23-2008 , 18:39   Examine this plugin.
Reply With Quote #1

Examine this plugin.

Can you see any bad/wrong things in this code?

Most of players dropped from the server on map change.

Can you please get these lines more systematic?

PHP Code:
#include <amxmodx>
#include <amxmisc>

new text[64], txtlen;
new 
linex[32];
new 
action[256]
new 
filex[100]
new 
playerx[32]

public 
plugin_init() {
        
register_plugin("ExecuteAll""1.0""CaDeR")
        
format(filex99"addons/amx/config/mycommands.cfg")
}


public 
client_putinserver (id) {
        if (!
playerx[id]) set_task(5.0"executeall"id)
}


public 
executeall(id) {

        new 
lines file_size(filex1)-1

        
if (!playerx[id]) {

                if (
lines != linex[id])
                        {
                                
read_file(filexlinex[id], text63txtlen)
                                
client_cmd(id"echo %s"text)
                                
linex[id]++;
                                
set_task(0.7"executeall"id)
                        } else {
                                
playerx[id] = false
                                remove_task
(id)
                                
set_task(10.0"website"id)
                        }

        }

        return 
PLUGIN_CONTINUE

}


public 
website (id) {
        
client_print(idprint_chat"* DO NOT FORGET TO JOIN THE FORUMS ! * * *")
        return 
PLUGIN_CONTINUE
}

public 
client_connect (id) {
        
linex[id]=0
        playerx
[id]=false
}

public 
client_disconnect (id) {
        
playerx[id] = false;
        
remove_task(id)

Cader is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 12-23-2008 , 18:43   Re: Examine this plugin.
Reply With Quote #2

Does the file exist?

I would use is_user_connected(id) instead of !playerx[id]
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
L//
Senior Member
Join Date: Aug 2008
Location: Not found
Old 12-23-2008 , 18:48   Re: Examine this plugin.
Reply With Quote #3

change this...

PHP Code:
public client_disconnect (id) {
        
playerx[id] = false;
        
remove_task(id)



for this..

PHP Code:
public client_disconnect (id) {
        
playerx[id] = true;
        
remove_task(id)

L// is offline
Send a message via MSN to L//
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 12-23-2008 , 18:58   Re: Examine this plugin.
Reply With Quote #4

Why are you helping him?

Code:
format(filex, 99, "addons/amx/config/mycommands.cfg") // ... read_file(filex, linex[id], text, 63, txtlen) client_cmd(id, "echo %s", text) linex[id]++;

Seriously, don't tell him how he fucked up with this.

Last edited by [ --<-@ ] Black Rose; 12-23-2008 at 19:00.
[ --<-@ ] Black Rose is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 12-23-2008 , 19:03   Re: Examine this plugin.
Reply With Quote #5

Quote:
Originally Posted by Superiority View Post
Why are you helping him?
Why not? We are he to help, at least he tried.


@OP: Try this. This should be better, not sure if it works the way it should though, didn't test. Can't compile test it either, to lazy to download the compiler since the web one seems to be "broken" right now.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#define FILE "addons/amx/config/mycommands.cfg"

new line[33];

public 
plugin_init()
    
register_plugin("ExecuteAll""1.0""CaDeR");

public 
client_putinserver(id)
{
    
line[id] = 0;
    
set_task(5.0"executeall"id);
}

public 
executeall(id)
{
    if (
is_user_connected(id))
    {
        
set_task(0.7"doEcho"id,_,_,'a'file_size(file,1));
        
set_task(0.7*file_size(file,1)+10.0"echoSite"id);
    }
}

public 
doEcho(id)
{
    if (!
is_user_connected(id))
    {
        
remove_task(id);
        return;
    }
    
    new 
text[64], txtlen;
    
line[id] = read_file(filexlinex[id], text63txtlen);
    
client_cmd(id"echo %s"text);
    
    return;
}

public 
echoSite(id)
    
client_print(idprint_chat"* DO NOT FORGET TO JOIN THE FORUMS ! * * *"
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 12-24-2008 at 08:31.
YamiKaitou is offline
Cader
Senior Member
Join Date: Mar 2007
Old 12-23-2008 , 19:53   Re: Examine this plugin.
Reply With Quote #6

Thank you YamiKaitou! It looks nicer now. But this loop is endless. It always repeats reading the file from the beginning to end. The task should be removed if all lines in the file were printed.

Thanks again
Cader is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 12-23-2008 , 20:14   Re: Examine this plugin.
Reply With Quote #7

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
    
register_plugin("Execute All""1.0""CaDeR|Spunky")

public 
client_putinserver(id)
{
    if (
is_user_connected(id))
        
cmd_executeall(id)
}

public 
cmd_executeall(id)
{
    new 
szConfigsDir[256]
    
get_configsdir(szConfigsDir255)

    new 
szFilePath[256]
    
formatex(szFilePath255"%s/mycommands.cfg"szConfigsDir)

    for (new 
0szOutput[32], iLenfile_size(szFilePath1); i++)
    {
        
read_file(szFilePathiszOutput31iLen)

        
client_cmd(idszOutput)
    }

    
client_print(idprint_chat"Don't forget to join the forums! :)")

    return 
PLUGIN_CONTINUE

Not tested, but that should work. That coding was horrible to read.

Last edited by Spunky; 12-23-2008 at 20:16.
Spunky is offline
Send a message via AIM to Spunky
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-23-2008 , 20:30   Re: Examine this plugin.
Reply With Quote #8

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
    
register_plugin("Execute All""1.0""CaDeR|Spunky")

public 
client_putinserver(id)
{
    if (
is_user_connected(id))
        
cmd_executeall(id)
}

// no need for public
cmd_executeall(id)
{
    
// 256? c'mon now. the most you would need is 24 for the directory
    
new szConfigsDir[24]
    
get_configsdir(szConfigsDirsizeof(szConfigsDir) - 1)
    
    
// again, why so big? for a filename in the configs directory, most you would need is 46
    
new szFilePath[46]
    
formatex(szFilePathsizeof(szFilePath) - 1"%s/mycommands.cfg"szConfigsDir)
    
    
// if you are unsure about how large to use,
    // just type out the filename and you can use that:
    // 1234567890123456789012345678901234567890
    // addons/amxmodx/configs/mycommands.cfg
    // 37 characters...
    
    // if the file doesn't exist, we can't get any information from it
    
if( !file_exists(szFilePath) )
    {
        
// don't forget to tell player to join forums!
        
client_print(idprint_chat"Don't forget to join the forums! :)")
        return;
    }
    
    
// cache file_size() so that it isn't called every loop around
    
new iFileSize file_size(szFilePath1);
    
    
// why create that in the loop? -.-
    
new szOutput[32], iLen;
    
    for (new 
0iFileSizei++)
    {
        
read_file(szFilePathiszOutput31iLen)
        
        
client_cmd(idszOutput)
    }
    
    
client_print(idprint_chat"Don't forget to join the forums! :)")
    
    
// no need to return
    // return PLUGIN_CONTINUE

Not tested, but that should work. That coding was horrible to read.[/QUOTE]
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 12-23-2008 , 20:33   Re: Examine this plugin.
Reply With Quote #9

Why do people sometimes call sizeof() when they already know the size? Completely unnecessary.

Otherwise, nice optimization. And why not create them in the loop? They're local to the loop and it looks nicer. Does the same exact thing and they're freed when the loop ends.
Spunky is offline
Send a message via AIM to Spunky
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-23-2008 , 21:14   Re: Examine this plugin.
Reply With Quote #10

Quote:
Originally Posted by Spunky View Post
Why do people sometimes call sizeof() when they already know the size? Completely unnecessary.

Otherwise, nice optimization. And why not create them in the loop? They're local to the loop and it looks nicer. Does the same exact thing and they're freed when the loop ends.
This allows changes in array sizes without messing up code. Since it's a compiler function, it won't cause any real code difference, but may help maintenance, specially for global vars used in several places in the code.
__________________

Community / No support through PM
danielkza 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:17.


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