Raised This Month: $ Target: $400
 0% 

read args from say


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nyuszy
Senior Member
Join Date: Apr 2009
Old 04-03-2011 , 05:07   read args from say
Reply With Quote #1

i have problems with reading args from a say command
PHP Code:
register_clcmd("say""handle_say")
register_clcmd("say_team""handle_say")


public 
handle_say(id)
{
    new 
arg1[32]
    
read_argv(1arg131)
    if(
equali(arg1"/transfer"))
    {
        new 
arg2[65], arg3[32]
        
read_argv(2arg264)
        
read_argv(3arg331)
        if(!
arg2[0] || !arg3[0])
        {
            
colorchat(id"!gUsage: !nsay !t/transfer <username or #userid> <money>")
            return 
PLUGIN_HANDLED
        
}
        
        new 
player cmd_target(idarg20)
        if(!
player)
        {
            
colorchat(id"!gPlayer not found!")
            return 
PLUGIN_HANDLED
        
}
        if(
get_user_team(id) != get_user_team(player))
        {
            
colorchat(id"!You can transfer money !tonly to teammates!g!")
            return 
PLUGIN_HANDLED
        
}
        
transfering[id] = true
        transfering
[player] = true
        
        
new money_transfer str_to_num(arg3)
        new 
name1[64], name2[64]
        
get_user_name(idname163)
        
get_user_name(playername263)
        if(
money_transfer >= money[id])
        {
            
colorchat(id"!gAll your money ($%i) id transfered to !t%s!g!"money[id], name2)
            
colorchat(player"!t%s transfered all his money ($%i) to you!"name1money[id])
            
money[player] += money[id]
            
update_hud_money(playermoney[id], 1)
            
update_hud_money(playermoney[player], 0)
            if(
money[player] <= 8000)
            {
                
cs_set_user_money(playermoney[player])
            }
            else
            {
                
cs_set_user_money(player8000)
            }
            
money[id] = 0
            cs_set_user_money
(id0)
        }
        else
        {
            
colorchat(id"!t$%i !gis transfered to !t%s!g!"money_transfername2)
            
colorchat(player"!t%s !gtransfered to you !t$%i!g!"name1money_transfer)
            
money[player] += money_transfer
            update_hud_money
(playermoney_transfer1)
            
update_hud_money(playermoney[player], 0)
            if(
money[player] <= 8000)
            {
                
cs_set_user_money(playermoney[player])
            }
            else
            {
                
cs_set_user_money(player8000)
            }
            
money[id] -= money_transfer
            update_hud_money
(id, -money_transfer1)
            
update_hud_money(idmoney[id], 0)
            if(
money[id] <= 8000)
            {
                
cs_set_user_money(idmoney[id])
            }
            else
            {
                
cs_set_user_money(id8000)
            }
        }
        
transfering[id] = false
        transfering
[player] = false
        
return PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE

if i say only /transfer, i get the "usage..." message. but when i say for example /transfer blabla, i don't get any message and nothing happens. what is wrong in my code?
Nyuszy is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 04-03-2011 , 06:37   Re: read args from say
Reply With Quote #2

You need to read the first and second argument
Quote:
Usage: say /transfer <username or #userid> <money>
SpeeDeeR is offline
Nyuszy
Senior Member
Join Date: Apr 2009
Old 04-03-2011 , 07:00   Re: read args from say
Reply With Quote #3

PHP Code:
    new arg1[32
    
read_argv(1arg131// "/transfer"

        
new arg2[65], arg3[32
        
read_argv(2arg264// target user
        
read_argv(3arg331// money ammount 
Nyuszy is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 04-03-2011 , 08:23   Re: read args from say
Reply With Quote #4

IIRC, the say message is always enclosed in quotes ("). That means you can just read_argv(1) or read_args() to get the whole message, but you then need to remove_quotes() it and then parse() or strbreak() it into individual parts..

e.g. if someone types /transfer 555 120, what you would get is "/transfer 555 120" as arg1.

I might be wrong about that, but I do remember reading say commands was different from reading console commands.
Elusive138 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-03-2011 , 08:49   Re: read args from say
Reply With Quote #5

If a player has a bind such as bind "b" "say /command blabla", then arg 1 will be /command and arg 2 will be blabla, but if he types /command blabla via "y" key then arg1 will be "/command blabla"

That's why the only method that should be used is read_args(said, charsmax(said)) + remove_quotes( said ) and then you have to parse args with the method you want.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 04-03-2011 , 10:07   Re: read args from say
Reply With Quote #6

Quote:
Originally Posted by ConnorMcLeod View Post
If a player has a bind such as bind "b" "say /command blabla", then arg 1 will be /command and arg 2 will be blabla, but if he types /command blabla via "y" key then arg1 will be "/command blabla"
I never actually realised there was a difference between a bound "say" and a messagemode "say" - it's interesting how inconsistent HL can be at times...
Elusive138 is offline
Nyuszy
Senior Member
Join Date: Apr 2009
Old 04-03-2011 , 12:35   Re: read args from say
Reply With Quote #7

thanks for help
Nyuszy is offline
Reply


Thread Tools
Display Modes

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 14:36.


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