Raised This Month: $51 Target: $400
 12% 

! commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-29-2011 , 05:46   ! commands
Reply With Quote #1

Hello i need help i want to make a plugin that lets you do ! commands for example:

!slay deagle
!noclip deag 1
!transfer deag Spec

like so i already tried to look for it couldn't.. also.. im new to this so if you could be detailed.. thanks
Kurosaki12341 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-29-2011 , 06:09   Re: ! commands
Reply With Quote #2

register_clcmd() registers commands, for this you'll need "say" command hooked.
In the function called by that hook, you'll need to get the arguments ( http://www.amxmodx.org/funcwiki.php?..._arg&go=search ), read_argv() would be required here, first argument is your say command, 2nd is the value inputed.

Also, look into other plugins that do the same thing, there are ALOT of plugins that accept say commands, look into those plugin sources.
__________________
Hunter-Digital is offline
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-29-2011 , 06:16   Re: ! commands
Reply With Quote #3

Quote:
Originally Posted by Hunter-Digital View Post
register_clcmd() registers commands, for this you'll need "say" command hooked.
In the function called by that hook, you'll need to get the arguments ( http://www.amxmodx.org/funcwiki.php?..._arg&go=search ), read_argv() would be required here, first argument is your say command, 2nd is the value inputed.

Also, look into other plugins that do the same thing, there are ALOT of plugins that accept say commands, look into those plugin sources.
o_O i only understand the thing about register_clcmd() the rest i dont know what your saying lol
Kurosaki12341 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-29-2011 , 11:26   Re: ! commands
Reply With Quote #4

A quick annotated example:
PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    
// other stuff here like register_plugin()

    
register_clcmd("say""cmd_say"// hook the "say" command with "cmd_say" callback
}

public 
cmd_say(idlevelcid// the callback for "say" command"
{
    new 
szCmd[24// a 24-cell array for the command string (argument 1)

    
read_argv(1szCmdcharsmax(szCmd)) // argument 1 assigned to szCmd, charsmax() is sizeof szCmd - 1, meaning 23, but it's good to use charsmax() instead of hardcoded sizes.

    
if(equali(szCmd"!slay")) // check if it's "!slay" (case insensitive, equal() is case sensitive)
    
{
        if(!(
get_user_flags(id) & ADMIN_SLAY)) // a simple way to check if admin doesn't have a specific access flag
        
{
            
client_print(idprint_chat"You don't have access to that command"// print a message

            
return PLUGIN_HANDLED // block the command from showing in chat
        
}

        new 
szTarget[32// a 32-cell array for the target player (argument 2)

        
read_argv(2szTargetcharsmax(szTarget)) // argument 2 assigned to szTarget

        
new target cmd_target(idszTargetCMDTARGET_OBEY_IMMUNITY CMDTARGET_ALLOW_SELF// create variable target and find a player with the string in szTarget, the 3rd argument are flags for what players to find... this one doesn't return immune players and allows you to specify your own name.

        
if(target 0// checks if player is 1 or more, that means cmd_target() found a valid player
        
{
            
user_kill(target// kill the target player

            
new szName[32// string for a name

            
get_user_name(idszNamecharsmax(szName)) // get the admin name

            
client_print(targetprint_chat"You've been slain by %d"szName// print a message to the slain target

            
return PLUGIN_HANDLED // returning this blocks the command, so it won't show you saying "!slay player" that in chat.
        
}
    }

    return 
PLUGIN_CONTINUE // if the say message isn't a command, just leave it alone

PS: I wrote this in the browser, I don't know how correct is it since I didn't script such things in a long while :} you'd have to test it first
__________________
Hunter-Digital is offline
Old 08-30-2011, 08:20
Kurosaki12341
This message has been deleted by Kurosaki12341.
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-30-2011 , 08:21   Re: ! commands
Reply With Quote #5

Quote:
Originally Posted by Hunter-Digital View Post
A quick annotated example:
PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    
// other stuff here like register_plugin()

    
register_clcmd("say""cmd_say"// hook the "say" command with "cmd_say" callback
}

public 
cmd_say(idlevelcid// the callback for "say" command"
{
    new 
szCmd[24// a 24-cell array for the command string (argument 1)

    
read_argv(1szCmdcharsmax(szCmd)) // argument 1 assigned to szCmd, charsmax() is sizeof szCmd - 1, meaning 23, but it's good to use charsmax() instead of hardcoded sizes.

    
if(equali(szCmd"!slay")) // check if it's "!slay" (case insensitive, equal() is case sensitive)
    
{
        if(!(
get_user_flags(id) & ADMIN_SLAY)) // a simple way to check if admin doesn't have a specific access flag
        
{
            
client_print(idprint_chat"You don't have access to that command"// print a message

            
return PLUGIN_HANDLED // block the command from showing in chat
        
}

        new 
szTarget[32// a 32-cell array for the target player (argument 2)

        
read_argv(2szTargetcharsmax(szTarget)) // argument 2 assigned to szTarget

        
new target cmd_target(idszTargetCMDTARGET_OBEY_IMMUNITY CMDTARGET_ALLOW_SELF// create variable target and find a player with the string in szTarget, the 3rd argument are flags for what players to find... this one doesn't return immune players and allows you to specify your own name.

        
if(target 0// checks if player is 1 or more, that means cmd_target() found a valid player
        
{
            
user_kill(target// kill the target player

            
new szName[32// string for a name

            
get_user_name(idszNamecharsmax(szName)) // get the admin name

            
client_print(targetprint_chat"You've been slain by %d"szName// print a message to the slain target

            
return PLUGIN_HANDLED // returning this blocks the command, so it won't show you saying "!slay player" that in chat.
        
}
    }

    return 
PLUGIN_CONTINUE // if the say message isn't a command, just leave it alone

PS: I wrote this in the browser, I don't know how correct is it since I didn't script such things in a long while :} you'd have to test it first

How did you know its user_"SLAY" though? Where'd you get that.. hmm and yes , it works i'm trying ot make a !heal too and i tried doing user_heal and i got one error saying undefined symbol user_heal and also how would i add the thing where it goes !heal playername <AMOUNT>
Kurosaki12341 is offline
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-30-2011 , 08:22   Re: ! commands
Reply With Quote #6

#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
// other stuff here like register_plugin()

register_clcmd("say", "cmd_say") // hook the "say" command with "cmd_say" callback
}

public cmd_say(id, level, cid) // the callback for "say" command"
{
new szCmd[24] // a 24-cell array for the command string (argument 1)

read_argv(1, szCmd, charsmax(szCmd)) // argument 1 assigned to szCmd, charsmax() is sizeof szCmd - 1, meaning 23, but it's good to use charsmax() instead of hardcoded sizes.

if(equali(szCmd, "!heal")) // check if it's "!slay" (case insensitive, equal() is case sensitive)
{
if(!(get_user_flags(id) & ADMIN_SLAY)) // a simple way to check if admin doesn't have a specific access flag
{
client_print(id, print_chat, "You don't have access to that command") // print a message

return PLUGIN_HANDLED // block the command from showing in chat
}

new szTarget[32] // a 32-cell array for the target player (argument 2)

read_argv(2, szTarget, charsmax(szTarget)) // argument 2 assigned to szTarget

new target = cmd_target(id, szTarget, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF) // create variable target and find a player with the string in szTarget, the 3rd argument are flags for what players to find... this one doesn't return immune players and allows you to specify your own name.

if(target > 0) // checks if player is 1 or more, that means cmd_target() found a valid player
{
user_health(target) // heals the target player

new szName[32] // string for a name

get_user_name(id, szName, charsmax(szName)) // get the admin name

client_print(target, print_chat, "You've been healed by %d", szName) // print a message to the healed target

return PLUGIN_HANDLED // returning this blocks the command, so it won't show you saying "!heal player" that in chat.
}
}

return PLUGIN_CONTINUE // if the say message isn't a command, just leave it alone
}


Is what i got, i copied most from yours so of course i'd do shit wrong, but please help

EDIT: How did you make it so you put the code in the "PHP CODE:" thing? and white background
Kurosaki12341 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-30-2011 , 09:20   Re: ! commands
Reply With Quote #7

Quote:
Originally Posted by Kurosaki12341 View Post
How did you know its user_"SLAY" though?
eh ... ?

Quote:
Originally Posted by Kurosaki12341 View Post
for example:

!slay deagle
I got from your example... and what's with "user_" there ? the function is user_kill()

You can use [php]code here[/php] or [code]code here[/code] to post code.

And in your code, the user_health(target) function doesn't exist, use set_user_health() and get_user_health().
__________________

Last edited by Hunter-Digital; 08-30-2011 at 09:25.
Hunter-Digital is offline
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-30-2011 , 16:18   Re: ! commands
Reply With Quote #8

Quote:
Originally Posted by Hunter-Digital View Post
eh ... ?


I got from your example... and what's with "user_" there ? the function is user_kill()

You can use [php]code here[/php] or [code]code here[/code] to post code.

And in your code, the user_health(target) function doesn't exist, use set_user_health() and get_user_health().
Alright but how would i add it so you can do !heal playername 'AMOUNT"
to make it so u can give whatever hp amount u want to
Kurosaki12341 is offline
Kurosaki12341
Junior Member
Join Date: Aug 2010
Old 08-30-2011 , 16:23   Re: ! commands
Reply With Quote #9

Quote:
Originally Posted by Hunter-Digital View Post
eh ... ?


I got from your example... and what's with "user_" there ? the function is user_kill()

You can use [php]code here[/php] or [code]code here[/code] to post code.

And in your code, the user_health(target) function doesn't exist, use set_user_health() and get_user_health().
So yeah, this is what i got, what would i add?

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

public plugin_init()
{
    // other stuff here like register_plugin()

    register_clcmd("say", "cmd_say") // hook the "say" command with "cmd_say" callback
}

public cmd_say(id, level, cid) // the callback for "say" command"
{
    new szCmd[24] // a 24-cell array for the command string (argument 1)

    read_argv(1, szCmd, charsmax(szCmd)) // argument 1 assigned to szCmd, charsmax() is sizeof szCmd - 1, meaning 23, but it's good to use charsmax() instead of hardcoded sizes.

    if(equali(szCmd, "!heal")) // check if it's "!slay" (case insensitive, equal() is case sensitive)
    {
        if(!(get_user_flags(id) & ADMIN_SLAY)) // a simple way to check if admin doesn't have a specific access flag
        {
            client_print(id, print_chat, "You don't have access to that command") // print a message

            return PLUGIN_HANDLED // block the command from showing in chat
        }

        new szTarget[32] // a 32-cell array for the target player (argument 2)

        read_argv(2, szTarget, charsmax(szTarget)) // argument 2 assigned to szTarget

        new target = cmd_target(id, szTarget, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF) // create variable target and find a player with the string in szTarget, the 3rd argument are flags for what players to find... this one doesn't return immune players and allows you to specify your own name.

        if(target > 0) // checks if player is 1 or more, that means cmd_target() found a valid player
        {
            set_user_health // heals the target player

            new szName[32] // string for a name

            get_user_name(id, szName, charsmax(szName)) // get the admin name

            client_print(target, print_chat, "You've been healed by %d", szName) // print a message to the healed target

            return PLUGIN_HANDLED // returning this blocks the command, so it won't show you saying "!heal player" that in chat.
        }
    }

    return PLUGIN_CONTINUE // if the say message isn't a command, just leave it alone
}
Kurosaki12341 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-30-2011 , 18:39   Re: ! commands
Reply With Quote #10

just "set_user_health"... really ? you want it to guess who to give and how much health ?

Well, I see that you don't understand basic stuff, so read this first:
http://wiki.amxmodx.org/Pawn_Tutorial and the tutorials/codes section.

Also do some practice yourself.
__________________
Hunter-Digital 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 12:40.


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