-1

これに対する答えは恥ずかしいほど簡単だと思いますが、それでもわかりません (これらの言語をまったく知らないという事実が当てはまる可能性があります)。私が必要としているのは、次のように機能するスクリプトです。

  1. まず、!random のようなコマンドと 1 から 100 の範囲の数字 (数字は成功確率を % で表す) を入力します [このように: !random 78]
  2. 次に、与えられた確率に基づいて、成功したか失敗したかを選択します [たとえば、!random 78 の場合、結果が「成功」になる確率は 78% です]。
  3. 次に、結果が何であるか(「成功」または「失敗」)がチャネルに公開メッセージを表示します。

オンライン テキスト RPG セッション用にこれが必要です。また、私の下手な英語で申し訳ありません。

コードがどのように見えるか:

    __module_name__ = "HexChat Randomiser"
    __module_version__ = "0.1"
    __module_description__ = "A randomiser for HexChat."
      
    import random
    import xchat

def callback(word, world_eol, userdata):
    number = word[1]
    if random_chance(number):
        print ("Success")
    else:
        print ("Failure")


    def random_chance(percent_chance):
        return random.randrange(1, 101) > (100 - percent_chance)


    xchat.hook_command("random", callback, help="/random <number>")

エラー:

Traceback (most recent call last):
File "<string>", line 10, in callback
File "<string>", line 17, in random_chance
TypeError: unsupported operand type(s) for -: 'int' and 'str'
4

1 に答える 1

1

まず、hexchat に関するPythonまたはPerlのドキュメントを参照してください。

Python で先に進みたい場合は、開始するための小さなスクリプトを作成しました。

import random
import xchat

def callback(word, world_eol, userdata):
    number = word[1]
    if random_chance(number):
        print "Success"
    else:
        print "Failure"


def random_chance(percent_chance):
    return random.randrange(1, 101) > (100 - int(percent_chance))
       

xchat.hook_command("random", callback, help="/random <number>")

自分で hexchat で動作させる必要があります。スクリプトをロードするには、最初にスクリプトをどこかに保存してから、load コマンドを呼び出す必要があります。

ロード

指定されたファイル名でスクリプトをロードします。/load も機能します。

于 2015-02-24T13:31:33.247 に答える