AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   read args from say (https://forums.alliedmods.net/showthread.php?t=154120)

Nyuszy 04-03-2011 05:07

read args from say
 
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?

SpeeDeeR 04-03-2011 06:37

Re: read args from say
 
You need to read the first and second argument
Quote:

Usage: say /transfer <username or #userid> <money>

Nyuszy 04-03-2011 07:00

Re: read args from say
 
PHP Code:

    new arg1[32
    
read_argv(1arg131// "/transfer"

        
new arg2[65], arg3[32
        
read_argv(2arg264// target user
        
read_argv(3arg331// money ammount 


Elusive138 04-03-2011 08:23

Re: read args from say
 
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.

ConnorMcLeod 04-03-2011 08:49

Re: read args from say
 
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.

Elusive138 04-03-2011 10:07

Re: read args from say
 
Quote:

Originally Posted by ConnorMcLeod (Post 1443731)
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...

Nyuszy 04-03-2011 12:35

Re: read args from say
 
thanks for help :)


All times are GMT -4. The time now is 14:36.

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