<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; SAMP: Модификация обработчика команд]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=12573&amp;type=atom" />
	<updated>2017-04-14T07:11:40Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=12573</id>
		<entry>
			<title type="html"><![CDATA[Re: SAMP: Модификация обработчика команд]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=115055#p115055" />
			<content type="html"><![CDATA[<p>Не очень понял вопрос, но, возможно, это имеется в виду:</p><div class="codebox"><pre><code>$~Enter::
if(!isInChat() || isDialogOpen())
     return
sleep 150
chat := readString(hGTA, dwSAMP + 0x12D8F8, 256)
if RegExMatch(chat, &quot;^\/afk\s(\d+)$&quot;, id)
{
	if (id1==1)
	{
	;действия 1
	return
	}
	if (id1==2)
	{
	;действия 2
	return
	}
}
return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Keller]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33755</uri>
			</author>
			<updated>2017-04-14T07:11:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=115055#p115055</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: SAMP: Модификация обработчика команд]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=114465#p114465" />
			<content type="html"><![CDATA[<p><strong>belyankin12</strong>, какой-то странный вопрос. Так еще можно: </p><div class="codebox"><pre><code>1::
x := 1
Return

2::
x := 2
Return

3::
Gosub,Label%x%
Return

Label1:
MsgBox, 1
return

Label2:
MsgBox, 2
return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2017-03-31T16:15:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=114465#p114465</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: SAMP: Модификация обработчика команд]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=114457#p114457" />
			<content type="html"><![CDATA[<p>Сам все сделал, вот код:</p><div class="codebox"><pre><code>
$~Enter::
if(!isInChat() || isDialogOpen())
     return
blockChatInput(), block := false
Sleep, 150
chat := readString(hGTA, dwSAMP + 0x12D8F8, 256)
s := StrSplit(chat)
if(s[1] == &quot;/&quot;)
{
     cmd := StrSplit(chat, A_Space)
	 com := &quot;&quot; . isCommand(cmd[1]) . &quot;&quot;
     if (com != &quot;False&quot;) {
          playerid := cmd[2], i := 0, block := true
          Loop, 20
          param%i% := cmd[i+1], i += 1
          unBlockChatInput()
          gosub, %com%
     }
}
unBlockChatInput()
if(!block &amp;&amp; strlen(chat))
     Sendchat(chat)
return


; #############################
; ########## ‘ункции ##########
; #############################

strrest(cmd, n)
{
     str := &quot;&quot;
     for k, v in cmd
     {
          if(k &gt; n)
               str := str &quot;&quot; v &quot; &quot;
     }
     return SubStr(str, 1, -1)
}

isCommand(string)
{
	;msgbox, string = %string%
	Loop {
	 FileEncoding, UTF-8
     FileReadLine, line, C:\Users\Белочка\Desktop\config.ini, %A_Index%
		if ErrorLevel
		break
	 if RegExMatch(line, &quot;Command(.*)=&quot; . string . &quot;&quot;, end_str)
	 break
	 }
		if (end_str != &quot;&quot;) {
			m := &quot;Command&quot; . end_str1 . &quot;&quot;
		} else {
			m := &quot;False&quot;
		}
	Return %m%
}

callCommand(string, params=&quot;&quot;)
{
     if(cmd_label := isCommand(string))
     {
          param0 := string, i := 1
          Loop, 20
          param%i% := params[i], i += 1
          gosub, %cmd_label%
     }
     return true
}


; Тестовая среда

command3:
sendchat(&quot;3&quot;)
return

command1:
sendchat(&quot;1&quot;)
return

command2:
sendchat(&quot;2&quot;)
return
</code></pre></div><p>Config.ini<br /></p><div class="codebox"><pre><code>
[Commands]
Command1=/gtest1
Command2=/gtest2
Command3=/gtest3
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[belyankin12]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34408</uri>
			</author>
			<updated>2017-03-31T13:50:15Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=114457#p114457</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: SAMP: Модификация обработчика команд]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=114368#p114368" />
			<content type="html"><![CDATA[<p>Хотя бы скажите что это невозможно, не молчите пожалуйста. Для тех, кто не из SAMP, если вы не понимаете системы, скажите, я объясню на пальцах. Мне очень нужна возможность вывода переменной в метку, потому я готов на это потратить сколько угодно времени.</p>]]></content>
			<author>
				<name><![CDATA[belyankin12]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34408</uri>
			</author>
			<updated>2017-03-29T11:06:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=114368#p114368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[SAMP: Модификация обработчика команд]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=114341#p114341" />
			<content type="html"><![CDATA[<p>Здравствуйте, имеется следующий обработчик команд:<br /></p><div class="codebox"><pre><code>
$~Enter::
if(!isInChat() || isDialogOpen())
     return
blockChatInput(), block := false
Sleep, 150
chat := readString(hGTA, dwSAMP + 0x12D8F8, 256)
s := StrSplit(chat)
if(s[1] == &quot;/&quot;)
{
     cmd := StrSplit(chat, A_Space)
     if(cmd_label := isCommand(cmd[1]))
     {
          playerid := cmd[2], i := 0, block := true
          Loop, 20
          param%i% := cmd[i+1], i += 1
          unBlockChatInput()
          gosub, %cmd_label%
     }
}
unBlockChatInput()
if(!block &amp;&amp; strlen(chat))
     Sendchat(chat)
return

strrest(cmd, n)
{
     str := &quot;&quot;
     for k, v in cmd
     {
          if(k &gt; n)
               str := str &quot;&quot; v &quot; &quot;
     }
     return SubStr(str, 1, -1)
}

isCommand(string)
{
     Loop, Read, %A_ScriptName%
     if RegExMatch(A_LoopReadLine, &quot;command\_(.*)\:&quot;, LName)
          if SubStr(string, 2) == LName1
          return SubStr(LName, 1, -1)
     return false
}

callCommand(string, params=&quot;&quot;)
{
     if(cmd_label := isCommand(string))
     {
          param0 := string, i := 1
          Loop, 20
          param%i% := params[i], i += 1
          gosub, %cmd_label%
     }
     return true
}

command_afk:
msgbox, режим AFK включен
return
</code></pre></div><p>Объясняю для тех, кто не знаком с SAMP. С помощью обработчика команд можно вместо хоткеев создавать команды, которые вводятся в игровой чат (нажимаете F6, вводите в чат /&quot;команда&quot; (напр. /afk) и нажимаете ентер). Если такая команда присутствует в скрипте, то выполняется какое-нибудь действие. Например: последние три строчки моего кода, это регистрация команды /afk. Теперь, если я введу в игровом чате /afk и нажму ентер (это принципиальное отличие от автозамены всеми любимой), то вылезет msgbox. Все работает замечательно, но возникла необходимость в качестве аргумента команде представить какую-нибудь переменную. Например:<br /></p><div class="codebox"><pre><code>
Global m := &quot;afk&quot;

command_%m%:
msgbox, режим AFK включен
return
</code></pre></div><p>Но как вы уже догадались, мои попытки не увенчались успехом. Никакой известный мне способ вывода переменной сюда не помог. Но я подозреваю, что если как-нибудь изменить функцию isCommand(string) (в примере первом она есть), то можно будет выводить переменные в command. Обращаюсь к вам за помощью: как можно переделать функцию isCommand(string) или как вообще можно использовать переменную m (из второго примера), чтобы она работала в обработчике команд. Любые костыли устраивают, главное результат.</p>]]></content>
			<author>
				<name><![CDATA[belyankin12]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34408</uri>
			</author>
			<updated>2017-03-28T13:18:19Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=114341#p114341</id>
		</entry>
</feed>
