AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can someone break this down ? (https://forums.alliedmods.net/showthread.php?t=58321)

Sllipindk 07-23-2007 19:11

Can someone break this down ?
 
Hello, I am understanding the very basics of PAWN coding, Now for me to get better and into further depth of the coding world I will need to look at other peoples plugins and analyze and examine it, Especially the plugins that relate to the type of plugins that I will be making.

If anyone will be so kind of enough to break down the, "Pepper Spray" plugin by James J Kelly Jr. which is used as a Item in Harbu's RP mod.

Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <engine_stocks>
#include <fun>
#include <harbu>

#define FFADE_STAYOUT 0x0004

#define SPRAY_DISTANCE 100

#define SPRAY_SOUND "player/sprayer.wav"

new playerTask[32];

public plugin_init()
{

    register_plugin("Pepper Spray","0.0.0.0","James J Kelly Jr");

    register_srvcmd("item_pepperspray","item_pepperspray");   

}

public client_connect(id)
{

    playerTask[id] = 0;

}

public client_disconnect(id)
{

    playerTask[id] = 0;

}

public plugin_precache()
{

    precache_sound(SPRAY_SOUND);

}

public item_pepperspray()
{

    new strArguments[2][32];
   
    read_argv(1,strArguments[0],31);
    read_argv(2,strArguments[1],31);
   
    if( equali(strArguments[0],"") ) return PLUGIN_HANDLED;
    if( equali(strArguments[1],"") ) return PLUGIN_HANDLED;
   
    new numArguments[2];
   
    numArguments[0] = str_to_num(strArguments[0]);
    numArguments[1] = str_to_num(strArguments[1]);
   
    if( !(is_user_connected(numArguments[0]) && is_user_alive(numArguments[0])) ) return PLUGIN_HANDLED;
    if( !(is_user_connected(numArguments[1]) && is_user_alive(numArguments[1])) ) return PLUGIN_HANDLED;
   
    /*
    new target, body;
   
    get_user_aiming(numArguments[0],target,body,SPRAY_DISTANCE);
    */
   
    new target = numArguments[1];
   
    if( !(is_user_connected(target) && is_user_alive(target)) )
    {
   
        client_print(numArguments[0],print_chat,"[PepperSprayMod] You need to be looking at someone to spray!^n");
       
        return PLUGIN_HANDLED;
   
    }
   
    if( playerTask[target] ) remove_task(playerTask[target],0);
   
    playerTask[target] = random_num(1,1000000);
   
    message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},target);
    write_short(1<<15);
    write_short(1<<12);
    write_short(FFADE_STAYOUT);
    write_byte(177);
    write_byte(177);
    write_byte(20);
    write_byte(250);
    message_end();
   
    new params[2];
       
    params[0] = target;
    params[1] = playerTask[target]
    set_task(10.0,"task_undo",playerTask[target],params,2);
   
    new name[2][32];
   
    get_user_mask(numArguments[0],name[0],31);
    get_user_mask(target,name[1],31);
   
    client_print(numArguments[0],print_chat,"[PepperSprayMod] You have sprayed %s in the eyes!^n",name[1]);
    client_print(target,print_chat,"[PepperSprayMod] %s has sprayed you in the eyes!^n",name[0]);
   
    emit_sound(numArguments[0],CHAN_ITEM,SPRAY_SOUND,1.0,ATTN_NORM,0,PITCH_NORM);
   
    return PLUGIN_HANDLED;

}

public task_undo(params[],id)
{

    new player = params[0];
   
    if( !(is_user_connected(player) && is_user_alive(player) && playerTask[player] == params[1]) ) return PLUGIN_HANDLED;

    message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},player);
    write_short(1<<15);
    write_short(1<<12);
    write_short(1<<12);
    write_byte(177);
    write_byte(177);
    write_byte(20);
    write_byte(250);
    message_end();

    return PLUGIN_HANDLED;

}

Thanks you very much.

-Sllipindk

awwhailnaw 07-23-2007 20:55

Re: Can someone break this down ?
 
thats kind of a lot to break down on here so i doubt you'll get what your looking for...
i can help you out a lil though...just message me

DotNetJunkie 07-23-2007 21:33

Re: Can someone break this down ?
 
I wrote this plugin so any questions you have I should be able to answer.

I should note though that this mod fails to function properly in TS 3.0 due to a non-functioning ScreenFade message.

Sllipindk 07-23-2007 22:15

Re: Can someone break this down ?
 
Well, It's okay if few codes does not work, because I am just learning coding. I am not going to directly implicate those codes into my codes. Above all, the main reason I am specifically choosing this plugin is due to my fascination with how the RP plugins for "The Specialists" work.

The bottom half of the code is what I am most confused with, all those intense looking coding such as the, "Params" or whatnot.

If you would be so kind..please break it down or at least explain the main function of each section.

Thanks alot.

-Sllipindk

DotNetJunkie 07-25-2007 12:52

Re: Can someone break this down ?
 
Code:

    new params[2];
       
    params[0] = target;
    params[1] = playerTask[target]
    set_task(10.0,"task_undo",playerTask[target],params,2);

The params simply pass a list of numbers to the function task_undo which
will then proceed to utilitize those numbers.

I haven't looked at this mod in a long time so I'm not sure what everything does
off the top of my head.


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

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