Raised This Month: $ Target: $400
 0% 

Help with first work


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-23-2014 , 20:00   Re: [how to]
Reply With Quote #7

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!

__________________

Last edited by Flick3rR; 05-24-2014 at 11:43.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
 



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:35.


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