AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with first work (https://forums.alliedmods.net/showthread.php?t=240822)

Storas1337 05-22-2014 17:40

Help with first work
 
Hello im making my first plugin and i need some advice on it
main idea is that admin write in chat hp <name> <hpamount> and it gives
how to make it what am doing wrong? i know that i can make it with set_task but then i cant enter specified amount
please as much simplest solution

Code:

public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        register_concmd("hp", "hppakvietimas", ADMIN_BAN, "hp amount")
        register_event("Health", "gyv", "be", "1>0");
       
       
       
       
        public hpkvietimas(client, gyv)
        {
                if(get_user_flags(id) & ADMIN_BAN)
                {
                        set_user_health(id , gyv)
                       
                }


Flick3rR 05-22-2014 18:03

Re: [how to]
 
You will have to hook client_cmd say and say_team, then to read the argvs, remove quotes and parse. The get second arg of the command to be a target and get it's index. Then do what you want. I'll post an example code later.

Storas1337 05-23-2014 03:18

Re: [how to]
 
Thank you post please , i will try method as you explained

aron9forever 05-23-2014 07:13

Re: [how to]
 
Code:
public plugin_init() { register_clcmd( "say", "stop_say" ) } public stop_say( id ) {     new szArgs[106], szCommand[16], szValue[8];     read_args(szArgs, charsmax(szArgs));     remove_quotes(szArgs);         if(equal(szArgs, "hp"))     {         chat_color(id, ".v[prefix].g Syntax error")         return PLUGIN_HANDLED     }         parse(szArgs, szCommand, charsmax(szCommand), szArgs, charsmax(szArgs) ,szValue,charsmax(szValue));         new iPlayer = cmd_target(id, szArgs, 8);             if(equal(szCommand, "hp"))     {         new hashpe=get_user_health(id)         set_user_health(iPlayer, hashpe + szValue)         } }

don't forget to add admin check, and check for syntax error if there is no value

Storas1337 05-23-2014 18:29

Re: [how to]
 
i get :


Error: Array must be indexed (variable "szValue") on line 37

btw if you can please comment every step you write it will be easier for me to understand , thnx.
im defined color_chat that is ok ? because before defining i was getting error undefined symbol , now im getting :

Warning: Expression has no effect on line 25

Flick3rR 05-23-2014 20:00

Re: [how to]
 
Tested and works. I used the colorchat.inc, because it was much easier. If you want, you could replace the ColorMessages with whatever you want, doesn't matter for the functions. I think I explained the important stuff in the code. Take a look :)
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <fun>

#define PLUGIN "Give HP"
#define VERSION "1.0"
#define AUTHOR "Flicker"

new const Prefix[] = {"^3[^4GiveHP^3] "// A prefix constant for all the messages


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
//Registering only say and say_team commands, because otherwise the admin will
    //not be able to write different names and amounts of HP
    
register_clcmd("say","Say")
    
register_clcmd("say_team","Say")
}

public 
Say(id)
{
    
//The new stuff needed
    
new args[129], arg_cmd[11], arg2[32],arg3[32]
    new 
name[32],target_name[32], targetnum_hp
    
    
//Removing quotes and parsing the whole message args
    
read_args(args,128)
    
remove_quotes(args)
    
parse(argsarg_cmd,10arg2,31arg3,31// end of that
    
    
    
num_hp str_to_num(arg3//Here we transform the third arg (the num) to a variable to use
    
target cmd_target(id,arg2,0//Here we get the cmd_target index, in target
    
    //Getting the command writer's and command target's names
    
get_user_name(id,name,31)
    
get_user_name(target,target_name,31)
    
    
    if(
equali(arg_cmd"/hp")) //The main check if the first arg, the arg_cmd, is /hp
    
{
        
//Here is the check for the admin flag for ban. The most important
        //If the player hasn;t got the flag, the message will appear and we return
        
if(!(get_user_flags(id) & ADMIN_BAN))
        {
            
ColorChat(idNORMAL"%s^1Only ^3admins^1 can use the command^4!"Prefix)
            return
        }
        
        
//If the command is writen, but the second arg (the target) is missing
        //The following message will appear to say the amdin, that he should enter a name
        //No that important check, but for info
        
if(equali(arg2""))
        {
            
ColorChat(idNORMAL"%s^1You should enter some name^4!"Prefix)
            return
        }
        
        
//If in the server there is not a player, with the name added in the arg2
        //Important check... The message will say that there is no such a player
        
if(!target)
        {
            
ColorChat(idNORMAL"%s^1There is not a player wit this name^4:^3 %s^4!"Prefixarg2)
            return
        }
        
        
//If the cmd is writen and there is a player with this name, but there is
        //no amount of HP writen. The message will appear to say, and we return again
        
if(equali(arg3""))
        {
            
ColorChat(idNORMAL"%s^1You should enter some amount of ^4HP^1 to give^4!"Prefix)
            return
        }
        
        
//If the amount of HP is 0 or less than 0
        //Very important check, because otherwise, the admin could set negative amounts of 
        //of HP, which will cause errors
        
if(num_hp 1)
        {
            
ColorChat(idNORMAL"%s^1You cant give negative amount of ^4HP^1, or^3 0^4!"Prefix)
            return
        }
        
        
//And this check isn't important. It's about if the admin could give HP to himself
        //In this case, he can't, but if you want your admins to can give themselves HP,
        //just remove the check.
        
if(id == target)
        {
            
ColorChat(idNORMAL"%s^1You cant give ^4HP^1 to yourself^4!"Prefix)
            return
        }
        
        
/* And  in the following lines we set the HP if all the conditions above are OK*/
        //set_user_health(id, arg3) // - In this case you set the player the amount writen in the command
        
set_user_health(targetget_user_health(target) + num_hp//- In this case you add the amount, writen in the command, to the current player HP
        
        //Colormessages to the admin and to the player he gave the HP
        
ColorChat(idNORMAL"%sYou gave ^4%d ^1HP to ^3%s"Prefixnum_hptarget_name)
        
ColorChat(targetNORMAL"%s^3%s ^1gave you ^4%d^1 HP"Prefixnamenum_hp)
    }
    
//I tink that's all!



Storas1337 05-24-2014 07:12

Re: [how to]
 
Thank you very much but i discovered bug when was testing for ex. when im writing hp botname amount it gives hp not for bot but for me :D its after removing checking of admin and one more question how to insert this code in plugin that would work together in chat( i want make same command but only slay)
its from admincmd

im trying to do :

register_clcmd("say","Slay")
register_clcmd("say","Slay")
it compiles but wont work

Code:

        new arg[32]
       
        read_argv(1, arg, 31)
       
        new player = cmd_target(id, arg, 5)
       
        if (!player)
                return PLUGIN_HANDLED
       
        user_kill(player)
       
        new authid[32], name2[32], authid2[32], name[32]
       
        get_user_authid(id, authid, 31)
        get_user_name(id, name, 31)
        get_user_authid(player, authid2, 31)
        get_user_name(player, name2, 31)
       
        log_amx("Cmd: ^"%s<%d><%s><>^" slay ^"%s<%d><%s><>^"", name, get_user_userid(id), authid, name2, get_user_userid(player), authid2)

        switch (get_cvar_num("amx_show_activity"))
        {
                case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_SLAY_2", name, name2)
                case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_SLAY_1", name2)
        }
        console_print(id, "[AMXX] %L", id, "CLIENT_SLAYED", name2)
       
        return PLUGIN_HANDLED


Flick3rR 05-24-2014 08:31

Re: [how to]
 
Just wrong index of giving HP function, fixed! Just insert these functions to your code in cmd say and say_team

Storas1337 05-24-2014 10:33

Re: [how to]
 
I knew that there is mistake with index but where dont know :D so where it should be? :D
and about slay , i tryed that method you said but it wont worked i dont know why maybe there is need to call amx_slay on target , do you have ideas?

Flick3rR 05-24-2014 11:24

Re: [how to]
 
I fixed the index mistake in the code above.
For the slay - if you are trying to do another thing, different of that command with giving HP, better make a new thread and explain more. For slaying user, use user_kill(id, 1). And you may make it with chat command, of course.


All times are GMT -4. The time now is 09:35.

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