AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Stock problem (https://forums.alliedmods.net/showthread.php?t=224298)

Jhob94 08-22-2013 12:27

Stock problem
 
Hi
This is first stock i try to do so dont put a gun in my head please :3

PHP Code:

public set_age(idlevelcid)
{
    if(!
cmd_access(idlevelcid4))
        return

    new 
age_day[3], age_month[3], age_year[5]
    
read_argv(1age_day2)
    
read_argv(2age_month2)
    
read_argv(3age_year4)
    
    
str_to_num(age_day)
    
str_to_num(age_month)
    
str_to_num(age_year)
    
    
set_user_age(idage_yearage_monthage_day)
}

stock set_user_age(idage_yearage_monthage_day)
{
    new 
today_year[5], today_month[3], today_day[3]
    
get_time("%Y"today_year4)
    
get_time("%m"today_month2)
    
get_time("%d"today_day2)
    
    if(
today_year age_year)
        return
    
    
age[id] = today_year age_year
    
    
if(today_month <= age_month)
    {
        if(
today_month == age_month && today_day age_day || today_month age_month)
            
age[id] -= 1
    
}
    
    if(
today_month == age_month && today_day == age_day)
        
in_birthday[id] = true


well i have no idea what is the problem :grrr:

Errors:
Code:

Error: Argument type mismatch (argument 2) on line 66
Error: Array must be indexed (variable "today_year") on line 76
Error: Array must be indexed (variable "today_year") on line 79
Error: Array must be indexed (variable "today_month") on line 81
Error: Array must be indexed (variable "today_month") on line 83
Error: Array must be indexed (variable "today_month") on line 87

If i delete function set_age, the stock doesnt gets any error.

Arkshine 08-22-2013 12:48

Re: Stock problem
 
today_year - age_year

You can't do that with string. You have to convert them before in integer number, for example with str_to_num().

Jhob94 08-22-2013 13:10

Re: Stock problem
 
lol forgot to convert it :3
Anyway that isnt the problem here...

YamiKaitou 08-22-2013 13:18

Re: Stock problem
 
Code:

set_user_age(id, str_to_num(age_year), str_to_num(age_month), str_to_num(age_day))

.Dare Devil. 08-22-2013 14:01

Re: Stock problem
 
PHP Code:

stock set_user_age(idage_yearage_monthage_day)
{
    new 
a[5], b[3], c[3], today_yeartoday_monthtoday_day
    get_time
("%Y"a 4)
    
get_time("%m"b2)
    
get_time("%d"c2)
    
today_year str_to_num(a)
    
today_month str_to_num(b)
    
today_day str_to_num(c)
    if(
age_year >= today_year) return
    
age[id] = today_year age_year
    age
[id] = today_year age_year
    
if(today_year == age_year && today_month == age_month && today_day == age_dayin_birthday[id] = true


should be fine.

Jhob94 08-22-2013 15:40

Re: Stock problem
 
thanks guys :)

ConnorMcLeod 08-23-2013 00:36

Re: Stock problem
 
PHP Code:

stock set_user_age(idage_yearage_monthage_day

This stock should be named "check _user_age" or check_user_birthday or whatever, but not set_*
Also, if you pass strings to this stock, it should looks like :

PHP Code:

stock set_user_age(idage_year[], age_month[], age_day[]) 

or

PHP Code:

stock set_user_age(idage_year[32], age_month[32], age_day[32]) 


Jhob94 08-23-2013 13:27

Re: Stock problem
 
Well it runs good but now chat has a problem :3

PHP Code:

public hook_say(id)
{
    if(
age[id] >= MIN_AGE)
    {
        static 
say[192]
        
read_args(saycharsmax(say))
        
remove_quotes(say)
    
        
replace_all(saycharsmax(say), "%"" ")
    
        if(
equali(say""))
            return 
PLUGIN_HANDLED
            
        
if(equali(say"/agehelp"))
            
ShowMotd(id)
    
        static 
name[33]; get_user_name(idnamecharsmax(name))
    
        for(new 
index 1index <= g_MaxPlayersindex++)
        {
            if(
is_user_alive(id) && is_user_alive(index))
            {
                if(
in_birthday[id])
                    
ColorChat(indexGREEN"[BIRTHDAY %d Years] ^x03%s^x01: %s"age[id], namesay)
                
                else
                    
ColorChat(indexGREEN"[%d Years] ^x03%s^x01: %s"age[id], namesay)
            }
            
            if(!
is_user_alive(id) && !is_user_alive(index))
            {
                if(
in_birthday[id])
                    
ColorChat(indexYELLOW"*DEAD* ^x04[BIRTHDAY %d Years] ^x03%s^x01: %s"age[id], namesay)
                
                else
                    
ColorChat(indexYELLOW"*DEAD* ^x04[%d Years] ^x03%s^x01: %s"age[id], namesay)
            }
        }
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

// Color Messages

stock ColorChat(idColor:type, const msg[], {Float,Sql,Result,_}:...)
{
    static 
message[256];

    switch(
type)
    {
        case 
YELLOW// Yellow
        
{
            
message[0] = 0x01;
        }
        case 
GREEN// Green
        
{
            
message[0] = 0x04;
        }
        default: 
// White, Red, Blue
        
{
            
message[0] = 0x03;
        }
    }

    
vformat(message[1], 251msg4);

    
message[192] = '^0';

    new 
teamColorChangeindexMSG_Type;
    
    if(!
id)
    {
        
index FindPlayer();
        
MSG_Type MSG_ALL;
    
    } else {
        
MSG_Type MSG_ONE;
        
index id;
    }
    
    
team get_user_team(index);    
    
ColorChange ColorSelection(indexMSG_Typetype);

    
ShowColorMessage(indexMSG_Typemessage);
        
    if(
ColorChange)
    {
        
Team_Info(indexMSG_TypeTeamName[team]);
    }
}

ShowColorMessage(idtypemessage[])
{
    
message_begin(typeg_msgSayText_id);
    
write_byte(id)        
    
write_string(message);
    
message_end();    
}

Team_Info(idtypeteam[])
{
    
message_begin(typeg_TeamInfo_id);
    
write_byte(id);
    
write_string(team);
    
message_end();

    return 
1;
}

ColorSelection(indextypeColor:Type)
{
    switch(
Type)
    {
        case 
RED:
        {
            return 
Team_Info(indextypeTeamName[1]);
        }
        case 
BLUE:
        {
            return 
Team_Info(indextypeTeamName[2]);
        }
        case 
GREY:
        {
            return 
Team_Info(indextypeTeamName[0]);
        }
    }

    return 
0;
}

FindPlayer()
{
    new 
= -1;

    while(
<= g_MaxPlayers)
    {
        if(
IsConnected[++i])
        {
            return 
i;
        }
    }

    return -
1;


Chat when alive works good but if dead chat, it shutdown the server. Error:
Code:

MSG_ONE or MSG_ONE_UNRELIABLE with no target entity
The chat stock i found somewhere in tutorials/snipets forum, so i think that nothing is wrong with it

ConnorMcLeod 08-23-2013 13:39

Re: Stock problem
 
LOL

Jhob94 08-23-2013 13:44

Re: Stock problem
 
I should use the plugin in your signature :3
But i get confused with your colorchat usage because of the second argument :|


All times are GMT -4. The time now is 18:57.

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