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

Help with first work


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Storas1337
Senior Member
Join Date: Apr 2009
Location: Lithuania
Old 05-22-2014 , 17:40   Help with first work
Reply With Quote #1

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)
			
		}

Last edited by Storas1337; 05-26-2014 at 15:22.
Storas1337 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-22-2014 , 18:03   Re: [how to]
Reply With Quote #2

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.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Storas1337
Senior Member
Join Date: Apr 2009
Location: Lithuania
Old 05-23-2014 , 03:18   Re: [how to]
Reply With Quote #3

Thank you post please , i will try method as you explained
Storas1337 is offline
Old 05-23-2014, 07:11
aron9forever
This message has been deleted by aron9forever.
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-23-2014 , 07:13   Re: [how to]
Reply With Quote #4

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
aron9forever is offline
Storas1337
Senior Member
Join Date: Apr 2009
Location: Lithuania
Old 05-23-2014 , 18:29   Re: [how to]
Reply With Quote #5

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

Last edited by Storas1337; 05-23-2014 at 18:31.
Storas1337 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-23-2014 , 20:00   Re: [how to]
Reply With Quote #6

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
Storas1337
Senior Member
Join Date: Apr 2009
Location: Lithuania
Old 05-24-2014 , 07:12   Re: [how to]
Reply With Quote #7

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 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

Last edited by Storas1337; 05-24-2014 at 08:22.
Storas1337 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-24-2014 , 08:31   Re: [how to]
Reply With Quote #8

Just wrong index of giving HP function, fixed! Just insert these functions to your code in cmd say and say_team
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Storas1337
Senior Member
Join Date: Apr 2009
Location: Lithuania
Old 05-24-2014 , 10:33   Re: [how to]
Reply With Quote #9

I knew that there is mistake with index but where dont know so where it should be?
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?

Last edited by Storas1337; 05-24-2014 at 10:36.
Storas1337 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-24-2014 , 11:24   Re: [how to]
Reply With Quote #10

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.
__________________

Last edited by Flick3rR; 05-24-2014 at 11:24.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
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 20:51.


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