Bars
Пользователь
- Регистрация
- 10 Июн 2017
- Сообщения
- 76
- Симпатии
- 4
- Пол
- Мужской
В чате выдает: s1 и s2, знатоки кто сможет отредактировать эту проблему?
Код:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <sqlx>
new iOneStepKills = 10
new iUserKillsStep = 15
new iUserLevel[33], iUserKills[33], iLevelNext[33]
new iMaxPlayers, gMsgSayText
new Host[] = ""
new User[] = ""
new Pass[] = ""
new Db[] = ""
new Handle:g_SqlTuple
new g_Error[512]
public plugin_init()
{
register_plugin("LVL System [MySQL]", "1.0", "MaJIou' / Remake by Pain")
register_message(get_user_msgid("SayText"),"Tekst") // Отлавливаем событие написания игроком сообщения
RegisterHam(Ham_Killed, "player", "fw_Killed", 1)
iMaxPlayers = get_maxplayers()
gMsgSayText = get_user_msgid("SayText")
set_task(1.0, "MySql_Init")
}
public plugin_precache() precache_sound("MG_SOUND/levelup.wav" )
public plugin_natives()
{
register_native("get_level", "native_get_level", 1)
register_native("set_level", "native_set_level", 1)
}
public native_get_level(id)
{
return iUserLevel[id]
}
public native_set_level(id, level)
{
iUserLevel[id] = level
Save_MySql(id)
}
public client_putinserver(id)
{
iUserLevel[id] = 0
iUserKills[id] = 0
iLevelNext[id] = 0
Load_MySql(id)
set_task(2.0, "CheckLevel", id)
}
public client_disconnect(id)
{
Save_MySql(id)
remove_task(id + 123321)
}
public MySql_Init()
{
// we tell the API that this is the information we want to connect to,
// just not yet. basically it's like storing it in global variables
g_SqlTuple = SQL_MakeDbTuple(Host, User, Pass, Db)
// ok, we're ready to connect
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple, ErrorCode, g_Error, charsmax(g_Error))
if(SqlConnection == Empty_Handle)
// stop the plugin with an error message
set_fail_state(g_Error)
new Handle:Queries
// we must now prepare some random queries
Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS tutorial (name varchar(32),next INT(11),kills INT(11),level INT(11))")
if(!SQL_Execute(Queries))
{
// if there were any problems
SQL_QueryError(Queries, g_Error, charsmax(g_Error))
set_fail_state(g_Error)
}
// close the handle
SQL_FreeHandle(Queries)
// you free everything with SQL_FreeHandle
SQL_FreeHandle(SqlConnection)
}
public Load_MySql(id)
{
new szName[32], szTemp[512]
get_user_name(id, szName, charsmax(szName))
new Data[1]
Data[0] = id
//we will now select from the table `tutorial` where the steamid match
format(szTemp, charsmax(szTemp), "SELECT * FROM `tutorial` WHERE (`tutorial`.`name` = '%s')", szName)
SQL_ThreadQuery(g_SqlTuple, "register_client", szTemp, Data, 1)
}
public register_client(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
{
log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
new id
id = Data[0]
if(SQL_NumResults(Query) < 1)
{
//.if there are no results found
new szName[32]
get_user_name(id, szName, charsmax(szName)) // get user's name
// if its still pending we can't do anything with it
if (equal(szName,"ID_PENDING"))
return PLUGIN_HANDLED
new szTemp[512]
// now we will insturt the values into our table.
format(szTemp, charsmax(szTemp), "INSERT INTO `tutorial` ( `name` , `level`, `kills`, `next`) VALUES ('%s',%i,%i,%i);", szName, iUserLevel[id], iUserKills[id], iLevelNext[id])
//DEBUG
server_print("%s", szTemp)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
}
else
{
new iNext, sNext[11],
iLevel, sLevel[11],
iKills, sKills[11]
iNext = SQL_FieldNameToNum(Query, "next")
iLevel = SQL_FieldNameToNum(Query, "level")
iKills = SQL_FieldNameToNum(Query, "kills")
SQL_ReadResult(Query, iNext, sNext, charsmax(sNext))
SQL_ReadResult(Query, iLevel, sLevel, charsmax(sLevel))
SQL_ReadResult(Query, iKills, sKills, charsmax(sKills))
iLevelNext[id] = str_to_num(sNext)
iUserLevel[id] = str_to_num(sLevel)
iUserKills[id] = str_to_num(sKills)
}
return PLUGIN_HANDLED
}
public Save_MySql(id)
{
new szName[32], szTemp[512]
get_user_name(id, szName, charsmax(szName))
// Here we will update the user hes information in the database where the steamid matches.
format(szTemp, charsmax(szTemp), "UPDATE `tutorial` SET `Level` = '%i' , `kills` = '%i', `next` = '%i' WHERE `tutorial`.`name` = '%s';", iUserLevel[id], iUserKills[id], iLevelNext[id], szName)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", szTemp)
}
public IgnoreHandle(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
SQL_FreeHandle(Query)
return PLUGIN_HANDLED
}
public plugin_end() SQL_FreeHandle(g_SqlTuple)
public CheckLevel(id)
{
if(iUserLevel[id] < 1)
{
iUserLevel[id] = 1
iLevelNext[id] = iOneStepKills
}
Task_Player(id, 1.0)
}
public fw_Killed(victim, attacker, corpse)
{
new gName[32]
get_user_name(attacker, gName, charsmax( gName ))
if(!is_user_connected(victim) || !is_user_connected(attacker) || victim == attacker)
return
iUserKills[attacker]++
if(iUserKills[attacker] >= iLevelNext[attacker])
{
iLevelNext[attacker] += iUserKillsStep
iUserLevel[attacker]++
if(iUserLevel[attacker] == (2 | 3 | 4 | 5 | 8 | 10 | 15 | 20))
colored_print(attacker, "^x03[LEVEL] Достижение^x04 %d ^x03уровня. Вам стали доступны новые товары в магазине!", iUserLevel[attacker], iLevelNext[attacker])
else
colored_print(attacker, "^x03[LEVEL] Вы достигли^x04 %d ^x03уровня. Следующий через^x04 %d ^x03убийств", iUserLevel[attacker], iLevelNext[attacker])
colored_print(0, "^x03[LEVEL] ^x01Игрок^x04 %s ^x03достиг уровня^x04 %i", gName, iUserLevel[attacker])
iUserKills[attacker] = 0
client_cmd(attacker, "spk MG_SOUND/levelup.wav")
}
}
public Tekst(msgId,msgDest,msgEnt)
{
new id = get_msg_arg_int(1) // сокращаем ид игрока который пишет сообщения
if(!is_user_connected(id)) return PLUGIN_CONTINUE;
new szTmp[256],szTmp2[256], szPrefix[64];
get_msg_arg_string(2,szTmp, charsmax( szTmp ) ) // поулчаем написаное сообщение
if(get_user_flags(id) & ADMIN_BAN)
{
formatex(szPrefix, charsmax( szPrefix ), "^x03[ADMIN]^x04[%i LVL]", iUserLevel[id])
}
else
{
formatex(szPrefix, charsmax( szPrefix ), "^x04[%i LVL]", iUserLevel[id])
}
if(!equal(szTmp,"#Cstrike_Chat_All")) // Если чат между коммандой
{
add(szTmp2,charsmax(szTmp2),szPrefix); // Ставим наш префикс
add(szTmp2,charsmax(szTmp2)," ");
add(szTmp2,charsmax(szTmp2),szTmp); // Сообщение
}
else
{ // Если чат общий
add(szTmp2,charsmax(szTmp2),szPrefix); //наш префикс
add(szTmp2,charsmax(szTmp2)," ^x03%s1^x01: ^x01%s2") // Имя игрока и сообщение
}
set_msg_arg_string(2,szTmp2); //Устанавливаем вид который мы сделали выше
return PLUGIN_CONTINUE // Продолжаем работу плагина
}
public PlayerInfo(id)
{
id -= 123321
set_hudmessage(0, 255, 255, -1.0, 0.10, 0, 6.0, 1.1);
show_hudmessage(id, "Уровень: %d^nУбийств: %i | До сл. уровня: %i ^nНаша Группа: vk.com/r", iUserLevel[id], iUserKills[id], iLevelNext[id] - iUserKills[id])
}
stock colored_print( target, const message[], any:... )
{
static buffer[ 512 ]
if( !target )
{
static player
for( player = 1; player <= iMaxPlayers; player++ )
{
if ( !is_user_connected( player ) )
continue;
vformat( buffer, charsmax( buffer ), message, 3 )
message_begin( MSG_ONE_UNRELIABLE, gMsgSayText, _, player )
write_byte( player )
write_string( buffer )
message_end()
}
}
else
{
vformat( buffer, charsmax( buffer ), message, 3 )
message_begin( MSG_ONE, gMsgSayText, _, target )
write_byte( target )
write_string( buffer )
message_end()
}
}
stock Task_Player(const id, Float:TIME)
{
if(task_exists(id + 123321))
remove_task(id + 123321)
set_task(TIME, "PlayerInfo", id + 123321, _, _, "b")
}
Вложения
-
8,6 KB Просмотры: 3