AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Days API Problem!! (https://forums.alliedmods.net/showthread.php?t=188343)

Ang52 06-25-2012 09:59

Days API Problem!!
 
hi, i have built a days menu with api.

but there is a problem, when i started a day and player has join to the server
the day automatically stopped.


i have no public that called when player connect the server or disconnect from.


help pls!!

Neeeeeeeeeel.- 06-25-2012 13:29

Re: Days API Problem!!
 
Show your code.

Aooka 06-25-2012 13:30

Re: Days API Problem!!
 
Quote:

Originally Posted by Neeeeeeeeeel.- (Post 1735902)
Show your code.


Ang52 06-25-2012 13:37

Re: Days API Problem!!
 
this is the code:


PHP Code:

#include < amxmodx >
#include < fakemeta >
#include < jb_days_const >

#define fm_find_ent_by_class(%1,%2) engfunc(EngFunc_FindEntityByString, %1, "classname", %2)

#define FADE_IN 0x0000
#define FADE_OUT 0x0001

#define TASK_SPECIAL 100

enum _:DAYS
{
    
DAY_SUNDAY,
    
DAY_MONDAY,
    
DAY_TUESDAY,
    
DAY_WEDNESDAY,
    
DAY_THURSDAY,
    
DAY_FRIDAY,
    
DAY_SATURDAY
};

new const 
DaysNamesDAYS ][ ] =
{
    
"Sunday",
    
"Monday",
    
"Tuesday",
    
"Wednesday",
    
"Thursday",
    
"Friday",
    
"Saturday"
};

enum _:Forwards
{
    
ForwardDayActive 0,
    
ForwardDayDisable,
    
ForwardDayChoosePre,
    
ForwardDayChoosePost,
    
ForwardDayStarted
};

const 
OFFSET_CSMENUCODE 205

new Array:gDayName;

new 
gDaysCount;

new 
bool:DayActivated;
new 
DayActivatedID;
new 
gForwardsForwards ];
new 
gForwardResult;

new 
Days;
new 
gHudMsg;
new 
gMsgIDScreenFade;

public 
plugin_natives( )
{
    
register_native"jb_days_register""native_days_register" );
    
register_native"jb_days_is_active""native_days_is_active" );
    
register_native"jb_days_set_active""native_days_set_active" );
    
register_native"jb_days_get_id""native_days_get_id" );
    
    
gDayName ArrayCreate(321)
}

public 
native_days_registerpluginparams )
{
    new 
name32 ];
    
get_string1namecharsmaxname ) )
    
    if ( 
strlenname ) < )
    {
        
log_errorAMX_ERR_NATIVE"[JB] Can't register day with an empty name" )
        return 
JB_INVALID_DAY;
    }
    
    new 
indexday_name[32]
    for ( 
index 0index gDaysCountindex++ )
    {
        
ArrayGetStringgDayNameindexday_namecharsmaxday_name ) )
        if ( 
equalinameday_name ) )
        {
            
log_errorAMX_ERR_NATIVE"[JB] day already registered (%s)"name )
            return 
JB_INVALID_DAY;
        }
    }
    
    
ArrayPushStringgDayNamename )
    
    
gDaysCount++
    return 
gDaysCount 1;
}

public 
native_days_is_activepluginparams )
{
    return 
DayActivated true false;
}

public 
native_days_set_activepluginparams )
{
    new 
State get_param);
    
    
DayActivated State true false;
    
    if( !
DayActivated )
    {
        
ExecuteForwardgForwardsForwardDayDisable ], gForwardResult );
    }
    
    return 
true;
}

public 
native_days_get_idpluginparams )
{
    return 
DayActivated DayActivatedID 0;
}

public 
plugin_init( )
{
    
register_plugin"[JB] Days Manager""0.1""Ang52" );
    
    
register_saycmd"days""DaysManage" );
    
register_saycmd"day""DaysManage" );
    
    
gForwardsForwardDayActive ] = CreateMultiForward"Jb_fwDayActivated"ET_IGNOREFP_CELL );
    
gForwardsForwardDayDisable ] = CreateMultiForward"Jb_fwDayDisabled"ET_IGNORE );
    
gForwardsForwardDayChoosePre ] = CreateMultiForward"Jb_fwDayChoosePre"ET_CONTINUEFP_CELLFP_CELL );
    
gForwardsForwardDayChoosePost ] = CreateMultiForward"Jb_fwDayChoosePost"ET_IGNOREFP_CELLFP_CELL );
    
    
gHudMsg CreateHudSyncObj( );
    
gMsgIDScreenFade get_user_msgid"ScreenFade" );
}

public 
plugin_end( )
{
    
ArrayDestroygDayName );
}

public 
Jb_fwRoundstartPre( )
{
    
ExecuteForwardgForwardsForwardDayDisable ], gForwardResult );
}

public 
Jb_fwRoundstart( )
{
    if ( 
Days DAY_SATURDAY )
    {
        
Days DAY_SUNDAY;
    }
    
    new 
iUnits clamp( ( * ( << 12 ) ), 00xFFFF );
    
    new 
players32 ], num;
    
get_playersplayersnum );
    
    new 
id;
    
    for ( 
id 0;id num;id++ )
    {
        
set_hudmessage200200200, -1.00.7525.015.0 );
        
ShowSyncHudMsgplayersid ], gHudMsg"Day: %s^nJailbreak"DaysNamesDays ] );
           
        
message_beginMSG_ONE_UNRELIABLEgMsgIDScreenFade,_playersid ] );
        
write_shortiUnits );
        
write_shortiUnits );
        
write_shortFADE_IN );
        
write_byte);
        
write_byte);
        
write_byte);
        
write_byte255 );
        
message_end( );
    }
}

public 
Jb_fwRoundend( )
{
    new 
iUnits clamp( ( * ( << 12 ) ), 00xFFFF );
    
    new 
players32 ], num;
    
get_playersplayersnum );
    
    new 
id;
    
    for ( 
id 0;id num;id++ )
    {
        
client_cmdid"mp3 stop" );
        
set_hudmessage200200200, -1.00.7515.05.0 );
        
ShowSyncHudMsgidgHudMsg"Day: %s End^nJailbreak"DaysNamesDays ] );
       
        
message_beginMSG_ONE_UNRELIABLEgMsgIDScreenFade,_playersid ] );
        
write_shortiUnits );
        
write_shortiUnits );
        
write_shortFADE_OUT );
        
write_byte);
        
write_byte);
        
write_byte);
        
write_byte255 );
        
message_end( );
    }
       
    
Days++;
}

public 
DaysManageid )
{
    if( !( 
get_user_flagsid ) & ADMIN_KICK ) )
    {
        
ColorChatid"You have^3 no access^1 to this command." );
        return 
PLUGIN_HANDLED;
    }
    
    
DaysManagerid );
    return 
PLUGIN_HANDLED;
}

public 
DaysManagerid )
{
    static 
menu128 ], DayName64 ];
    new 
menuidindexbuffer];
    
    
formatexmenusizeof menu 1"\d[\y Jailbreak\d ]\y Days List^nTotal Days: %d"gDaysCount );
    
menuid menu_createmenu"DaysHandler" );
    
    for( 
index 0index gDaysCountindex++ )
    {
        
        
ExecuteForwardgForwardsForwardDayChoosePre ], gForwardResultidindex )
        
        if( 
gForwardResult >= JB_DAY_DONT_SHOW )
            continue;
            
        
ArrayGetStringgDayNameindexDayNamesizeof DayName );
        
        if( 
gForwardResult >= JB_DAY_NOT_AVAILABLE )
            
formatexmenusizeof menu 1"\d%s"DayName );
        else
            
formatexmenusizeof menu 1"%s"DayName );
            
            
        
buffer] = index;
        
buffer] = 0;
        
        
menu_additemmenuidmenubuffer );
    }
    
    if( 
menu_itemsmenuid ) <= )
    {
        
ColorChatid"No^3 Days^1 Available." );
        
menu_destroymenuid );
        return 
PLUGIN_HANDLED;
    }
    
    
formatex(menucharsmax(menu), "Back")
    
menu_setprop(menuidMPROP_BACKNAMEmenu)
    
formatex(menucharsmax(menu), "Next")
    
menu_setprop(menuidMPROP_NEXTNAMEmenu)
    
formatex(menucharsmax(menu), "Exit")
    
menu_setprop(menuidMPROP_EXITNAMEmenu)
    
    
set_pdata_int(idOFFSET_CSMENUCODE0)
    
menu_display(idmenuid0)
    
    return 
PLUGIN_HANDLED;
}

public 
DaysHandleridmenuiditem )
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menuid)
        return 
PLUGIN_HANDLED;
    }
    
    
// Retrieve item id
    
new buffer[2], dummydayid;
    
menu_item_getinfo(menuiditemdummybuffercharsmax(buffer), __dummy)
    
dayid buffer[0]
    
    
startDayiddayid );
    
menu_destroy(menuid)
    return 
PLUGIN_HANDLED;
}

startDayiddayid )
{
    
ExecuteForwardgForwardsForwardDayChoosePre ], gForwardResultiddayid );
    
    if( 
gForwardResult >= JB_DAY_NOT_AVAILABLE )
        return;
        
    
ExecuteForwardgForwardsForwardDayChoosePost ], gForwardResultiddayid );
}

public 
Jb_fwDayChoosePreidDayID )
{
    if( 
DayActivated )
        return 
JB_DAY_NOT_AVAILABLE;
        
    return 
JB_DAY_AVAILABLE;
}

public 
Jb_fwDayChoosePostidDayID )
{
    
DayActivated true;
    
DayActivatedID DayID;
            
    
ExecuteForwardgForwardsForwardDayActive ], gForwardResultDayID );
    
    
OpenCells( );
    
    new 
DayName64 ];
    
ArrayGetStringgDayNameDayIDDayNamecharsmaxDayName ) );
    
    
set_hudmessage0191255, -1.00.1715.08.00.00.010 );
    
ShowSyncHudMsg0gHudMsg"[ Today ]^n[ %s ]"DayName );
}

public 
Jb_fwDayDisabled( )
{    
    
DayActivated false;
    
DayActivatedID 0;
}

OpenCells( )
{
    new 
ent = -1;
    
    while( ( 
ent fm_find_ent_by_classent"func_button" ) ) )
    {                  
        
dllfuncDLLFunc_Useent);
    }  
}
    
register_saycmdcommand[ ], function[ ] )
{
    new 
saycom64 ];
    
formatexsaycomsizeof saycom 1"say %s"command );
    
register_clcmdsaycom, function );
    
    
formatexsaycomsizeof saycom 1"say .%s"command );
    
register_clcmdsaycom, function );
    
    
formatexsaycomsizeof saycom 1"say !%s"command );
    
register_clcmdsaycom, function );
    
    
formatexsaycomsizeof saycom 1"say /%s"command );
    
register_clcmdsaycom, function );
}

ColorChat(idstring[], {FloatSqlResul,_}:...)
{
    new 
msg[191], players[32], count 1;
    
    static 
len;
    
len formatex(msgcharsmax(msg), "^4[ JBAMXX ]^1 ");
    
vformat(msg[len], charsmax(msg) - lenstring3);
    
    if(
id)         players[0] = id;
    else         
get_players(players,count,"ch");
    
    for (new 
0counti++)
    {
        if(
is_user_connected(players[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"),_players[i]);
            
write_byte(players[i]);
            
write_string(msg);
            
message_end();
        }
    }



Backstabnoob 06-26-2012 06:07

Re: Days API Problem!!
 
I cannot see anything wrong with the code that would manually disable the day. Also, you don't register Jb_fwRoundend and Jb_fwRoundstart anywhere. How do you register it?

Quote:

Originally Posted by Aooka (Post 1735903)
Another quote

Please avoid creating unnecessary posts like that.

Ang52 06-26-2012 09:30

Re: Days API Problem!!
 
the Forwards : Jb_fwRoundend, Jb_fwRoundstart are from other plugin that i make.

this is the code that register day :

PHP Code:

#include < amxmodx >
#include < fakemeta >
#include < jb_days >

#define TASK_TIMER 100

native jb_weapons_menu_showid );

enum _:Teams
{
    
FM_TEAM_UNASSIGNED,
    
FM_TEAM_T,
    
FM_TEAM_CT,
    
FM_TEAM_SPECTATOR
};

enum _:Vars
{
    
gTimer,
    
gStrip,
    
gWeapon,
    
gSound
};

new const 
g_freeday_sound[ ] = "sound/Jailbreak/Freeday.mp3";

new 
FDVarsVars ];

new 
gDayID;

new 
timer;

new 
gMaxPlayers;
new 
gHudMsg;

public 
plugin_precache( )
{
    
precache_genericg_freeday_sound );
}

public 
plugin_init( )
{
    
register_plugin"[JB] Days: Freeday""0.1""Ayu" );
    
    
FDVarsgTimer ] = register_cvar"jb_freeday_timer""120" );
    
FDVarsgStrip ] = register_cvar"jb_freeday_strip""1" );
    
FDVarsgWeapon ] = register_cvar"jb_freeday_weapon""1" );
    
FDVarsgSound ] = register_cvar"jb_freeday_sound""1" );
    
    
gDayID jb_days_register"Freeday" );
    
    
gMaxPlayers get_maxplayers( );
    
gHudMsg CreateHudSyncObj( );
}

public 
Jb_fwDayActivatedDay )
{
    if( 
Day != gDayID )
        return;
        
    
timer get_pcvar_numFDVarsgTimer ] );
    
    new 
id;
    
StartTimer( );
    
client_cmd0"mp3 play ^"%s^""g_freeday_sound );
    for( 
id 1id <= gMaxPlayersid ++ )
    {
        if( !
is_user_connectedid ) && !is_user_aliveid ) )
            continue;
    
        
Freedayid );
    }
}

public 
Jb_fwDayDisabled( )
{
    
remove_taskTASK_TIMER );
}

public 
Freedayid )
{
    if( 
get_pcvar_numFDVarsgStrip ] ) )
    {
        
fm_strip_user_weaponsid );
        
fm_give_itemid"weapon_knife" );
    }
    
    switch( 
fm_get_player_teamid ) )
    {
        case 
FM_TEAM_CT:
        {
            if( 
get_pcvar_numFDVarsgWeapon ] ) )
            {
                
jb_weapons_menu_showid );
            }
            
            
fm_set_user_healthid100 );
        }
        
        case 
FM_TEAM_T:    fm_set_user_healthid100 );
    }
}

public 
StartTimer( )
{
    
    if( 
timer )
    {
        
set_hudmessage01790, -1.00.8520.021.00.010.110 ); 
        
ShowSyncHudMsg0gHudMsg"Freeday End" );
        
        
remove_taskTASK_TIMER );
        
        return;
    }
        
    
set_hudmessage01790, -1.00.8520.051.00.050.110 ); 
    
ShowSyncHudMsg0gHudMsg"Time Left: %d"timer );
    
    
timer--;
    
    
set_task1.0"StartTimer"TASK_TIMER );
}        
    
stock fm_get_player_teamid )
{
    return 
get_pdata_intid114 );
}

stock fm_create_entity( const classname[] )
{
    return 
engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocStringclassname ) );
}

stock fm_give_itemclient, const item[] )
{
    if ( !
equalitem"weapon_") && !equalitem"ammo_")
    && !
equalitem"item_") && !equalitem"tf_weapon_"10 ) )
        return 
0;

    new 
ent fm_create_entityitem );
    
    if ( !
pev_valident ) )
        return 
0;

    new 
Float:origin[3];
    
    
pevclientpev_originorigin );
    
    
set_peventpev_originorigin );
    
set_peventpev_spawnflagspeventpev_spawnflags ) | SF_NORESPAWN );
    
    
dllfuncDLLFunc_Spawnent );

    new 
save peventpev_solid );
    
    
dllfuncDLLFunc_Touchentclient );
    
    if ( 
peventpev_solid ) != save )
        return 
ent;

    
engfuncEngFunc_RemoveEntityent );

    return -
1;
}

stock fm_set_user_healthclienthealth )
{
    
health set_pevclientpev_healthfloathealth ) ) : dllfuncDLLFunc_ClientKillclient );

    return 
1;
}

stock fm_strip_user_weaponsclient )
{
    new 
ent fm_create_entity"player_weaponstrip" );
    
    if ( !
pev_valident ) )
        return 
0;

    
dllfuncDLLFunc_Spawnent );
    
dllfuncDLLFunc_Useentclient );
    
engfuncEngFunc_RemoveEntityent );

    return 
1;


the native jb_weapons_menu_show( id ) it also from other plugin.

also i don't see any problem with that code.


All times are GMT -4. The time now is 06:09.

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