View Single Post
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-14-2011 , 18:04   Re: [CZ][INC&NATIVE] Czero Tutor
Reply With Quote #5

I also have one version to post
More flexible and support ML and formatting.

Code:
#if defined _cz_tutor_included
  #endinput
#endif
#define _cz_tutor_included

#pragma reqlib cztutor

enum TutorSounds {
	DefaultTutor,
	FriendDied,
	EnemyDied,
	TaskComplete,
	TutorNoSound
}

enum TutorColors
{
	TutorGreen = 1,
	TutorRed = 2,
	TutorBlue = 4,
	TutorYellow = 8
}

native client_tutor(id, TutorColors:iColor=TutorGreen, TutorSounds:iSound=DefaultTutor, Float:flCloseDelay=8.0, const fmt[], any:...);
PHP Code:
/*    Formatright © 2010, ConnorMcLeod

    This plugin is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this plugin; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>

#define VERSION "0.0.1"
#define PLUGIN "TutorText"

#define TASK_OFFSET 1354897

enum TutorSounds {
    
DefaultTutor,
    
FriendDied,
    
EnemyDied,
    
TaskComplete,
    
TutorNoSound
}

new const 
g_szTutorSounds[TutorSounds][] = 
{
    
"sound/events/tutor_msg.wav"// Yellow, Green
    
"sound/events/friend_died.wav"// Red
    
"sound/events/enemy_died.wav"// Blue
    
"sound/events/task_complete.wav" // Green
}

enum TutorColors ( <<= )
{
    
TutorGreen 1,
    
TutorRed,
    
TutorBlue,
    
TutorYellow
}

new 
g_iTutorTextg_iTutorClose

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
g_iTutorText get_user_msgid("TutorText")
    
g_iTutorClose get_user_msgid("TutorClose")
}

public 
plugin_natives()
{
    
register_library("cztutor")
    
register_native("client_tutor""client_tutor")
}

public 
plugin_precache()
{
    new 
szModName[9]
    
get_modname(szModNamecharsmax(szModName))
    if( !
equal(szModName"czero") )
    {
        
set_fail_state("Only works on condition zero")
    }
}

// client_tutor(id, TutorColors:iColor, TutorSounds:iSound, Float:flCloseDelay=8.0, fmt[], any:...)
public client_tutor(iPluginiParams)
{
    new 
id get_param(1)
    new 
TutorColors:iColor TutorColors:get_param(2)
    new 
TutorSounds:iSound TutorSounds:get_param(3)
    new 
Float:flDelay get_param_f(4)
    new 
szText[256]
    if( 
iParams == )
    {
        
get_string(5szTextcharsmax(szText))
        
Send_TutorText(idiColoriSoundflDelayszText)
    }
    else if( 
id || iParams == )
    {
        
vdformat(szTextcharsmax(szText), 56)
        
Send_TutorText(idiColoriSoundflDelayszText)
    }
    else 
// iParams > 6
    
{
        new 
iPlayers[32], iNum
        get_players
(iPlayersiNum"ch")
        if( !
iNum )
        {
            return 
0
        
}
        new 
ij, Array:aStoreML ArrayCreate(), iMlCount
        
for(i=6i<iParamsi++)
        {
            if( 
get_param_byref(i) == LANG_PLAYER )
            {
                
get_string(i+1szTextcharsmax(szText))
                if( 
GetLangTransKey(szText) != TransKey_Bad )
                {
                    
ArrayPushCell(aStoreMLi++)
                    
iMlCount++
                }
            }
        }
        if( !
iMlCount )
        {
            
vdformat(szTextcharsmax(szText), 56)
            
Send_TutorText(idiColoriSoundflDelayszText)
        }
        else
        {
            for(
i=0i<iNumi++)
            {
                
id iPlayers[i]
                for(
j=0j<iMlCountj++)
                {
                    
set_param_byref(ArrayGetCell(aStoreMLj), id)
                }
                
vdformat(szTextcharsmax(szText), 56)
                
Send_TutorText(idiColoriSoundflDelayszText)
            }
        }
        
ArrayDestroy(aStoreML)
    }
    return 
1
}

Send_TutorText(idTutorColors:iTypeTutorSounds:iSoundFloat:flDelay, const szText[])
{
    if( 
iSound != TutorNoSound )
    {
        
client_cmd(id"spk %s"g_szTutorSounds[iSound])
    }

    
message_begin(id MSG_ONE_UNRELIABLE MSG_BROADCASTg_iTutorText, .player=id)
    
write_string(szText)
    
write_byte(0)
    
write_short(-1// TutorMessageEventI
    
write_shortid && !is_user_alive(id) ) 
    
write_short_:iType )
    
message_end()

    
id += TASK_OFFSET
    remove_task
(id)
    if( 
flDelay 0.0 )
    {
        
set_task(flDelay"TutorClose"id)
    }
}

public 
TutorClose(id)
{
    
id -= TASK_OFFSET
    
if( id )
    {
        
message_begin(MSG_ONE_UNRELIABLEg_iTutorClose, .player=id)
        
message_end()
    }
    else
    {
        new 
iPlayers[32], iNum
        get_players
(iPlayersiNum"ch")
        for(new 
ii<iNumi++)
        {
            
id iPlayers[i]
            if( !
task_exists(id+TASK_OFFSET) )
            {
                
message_begin(MSG_ONE_UNRELIABLEg_iTutorClose, .player=id)
                
message_end()
            }
        }
    }

__________________
- tired and retired -

- my plugins -

Last edited by Emp`; 11-15-2011 at 00:38.
ConnorMcLeod is offline