*
Phần 3 : Xây dựng Stealthbot với Script
Trong phần này ,chúng ta sẽ tìm hiểu cách tạo 1 con BOT cao cấp với các tính năng Addon rất thú vị và hữu ích .+ Điểm cần lưu ý :
Vì script là 1 ngôn ngữ lập trình nhỏ nên tác giả sẽ thiết lập các Access để quy định quyền sử dụng chức năng của script . Để khắc phục ta sẽ thiết lập lại các Access bằng cách tìm những đoạn code trong script có dạng Access = X ( X là giá trị ) và Edit giá trị X = -1 .
Nếu chưa hiểu thì tôi sẽ làm mẫu cho 1 cái Script để minh hoạ .
--------------------------------------
+
Speed Challenge (Script game)
_
Miêu tả : Script sẽ tạo 1 đoạn chử gồm nhiều ký tự ,và ai trong channel gõ nhanh nhất sẽ là người chiến thắng .
_
Lệnh kích hoạt.startsc : bắt đầu cuộc chơi
.stopsc : ngừng cuộc chơi
.clearsc : reset đỉêm về mức 0
.score [username] ; xem điểm của user
_
Cách cài đặtBật Stealthbot lên .Chọn Settings ==> Edit Files ==> Script Files
Xoá hết các đoạn code trong đó và thêm đoạn code này vào
Code:
'// Speed Challenge v5.6
'// by Swent
'// Last Modified by Swent 1:02 AM 3/26/2006
Public spcFSO, spcRandString, spcStringInterval
Public spcCount, timeLimitCounter, spcCounter, spcTickCount '// Counters
Public spcPlayGame, spcGuessActive '// game control bools
Public spcArrScores(2,1000), spcArrChar(90), spcArrNum(12), spcArrLetter(12)
'/*************************
'* PROGRAM SETTINGS *
'*************************/
'// Data File Path
Const spc_path = "C:\Program Files\StealthBot\speedchallenge.dat"
'// General Settings
Const string_length = 4 '// Average Speed Challenge string length. Range: 1-7. Default: 4
Const time_limit = 45 '// Time limit in seconds. Default: 45
Const string_interval = 11 '// Average delay in seconds between each string display. Default: 11
'// Access Requirements
Const clearsc_cmd_access = 100 '// Access required to clear all scores. Default: 100
Const startsc_cmd_access = 60 '// Access required to start Speed Challenge. Default: 60
Const stopsc_cmd_access = 60 '// Access required to stop Speed Challenge. Default: 60
Const score_cmd_access = -1 '// Access required to get a user's score. Default: -1
'// Commands
Const clearsc_command = "clearsc" '// Used to clear all current and saved scores
Const startsc_command = "startsc" '// Used to start Speed Challenge
Const stopsc_command = "stopsc" '// Used to stop Speed Challenge
Const score_command = "score" '// Used to get a user's score
'// Program Components
'// Default for all components: True
Const time_limit_enabled = True
Const clearsc_cmd_enabled = True
Const startsc_cmd_enabled = True
Const stopsc_cmd_enabled = True
Const score_cmd_enabled = True
'/**************************
'* DO NOT EDIT BELOW HERE *
'* DO NOT EDIT BELOW HERE *
'* DO NOT EDIT BELOW HERE *
'**************************/
Sub Event_Load()
spcStringInterval = string_interval
Randomize '// Initialize the RNG
If string_length > 7 or string_length < 1 Then '// String length setting is valid?
string_length = 4
End If
Set spcFSO = CreateObject("Scripting.FileSystemObject")
If Not spcFSO.FileExists(spc_path) Then
Set spcFile = spcFSO.CreateTextFile(spc_path)
End If
Set spcFile = spcFSO.OpenTextFile(spc_path, 1) '// Open scores file
If Not spcFile.AtEndofStream Then
spcLines = Split(spcFile.ReadAll, vbCrLf)
spcCount = 0
'// Add all lines from saved scores file to an array
For Each spcLine in spcLines
If spcLine <> "" then
spcArrScores(0,spcCount) = Left(spcLine, instr(1, spcLine, ":")-1)
spcArrScores(1,spcCount) = Mid(spcLine, instr(1, spcLine, ":")+1)
spcCount = spcCount + 1
End If
Next
End If
spcFile.Close
'// Create and enable timer
scTimer.Interval = 1000
scTimer.Enabled = True
End Sub
Sub Event_UserTalk(Username, Flags, Message, Ping)
GetDBentry Username, MyAccess, MyFlags
'// Is a command?
If Left(Message, 1) = BotVars.Trigger Then
Message = Mid(Message, 2)
End If
'// Get the command and arguments
If Instr(Trim(Message), " ") = 0 Then Message = Message & " "
cmd = Split(Trim(Message), " ")
'// Call the appropriate sub
Select Case cmd(0)
Case clearsc_command: clearsc_cmd cmd, Username, myAccess
Case startsc_command: startsc_cmd cmd, Username, myAccess
Case stopsc_command: stopsc_cmd cmd, Username, myAccess
Case score_command: score_cmd cmd, Username, myAccess
Case Else: is_correct_string cmd, Username
End Select
End Sub
Sub clearsc_cmd(cmd, Username, Access)
If Access < clearsc_cmd_access Or clearsc_cmd_enabled = False Then Exit Sub
If spcPlayGame Then
spcPlayGame = False
AddQ "/w " & Username & " Speed Challenge stopped."
End If
'// Erase current scores
Erase spcArrScores
'// Delete saved scores
If spcFSO.FileExists(spc_path) Then
spcFSO.DeleteFile(spc_path)
End If
AddQ "/w " & Username & " Scores cleared."
End Sub
Sub startsc_cmd(cmd, Username, Access)
If Access < startsc_cmd_access Or startsc_cmd_enabled = False Then Exit Sub
If Not spcPlayGame Then
spcPlayGame = True
AddQ "/w " & Username & " Speed Challenge started."
Else
AddQ "/w " & Username & " Speed Challenge has already been started."
End If
End Sub
Sub stopsc_cmd(cmd, Username, Access)
If Access < stopsc_cmd_access Or stopsc_cmd_enabled = False Then Exit Sub
spcPlayGame = False
AddQ "/w " & Username & " Speed Challenge stopped."
End Sub
Sub score_cmd(cmd, Username, Access)
If Access < score_cmd_access Or score_cmd_enabled = False Then Exit Sub
'// Username arguement exists?
If UBound(cmd) > 0 Then
user = cmd(1)
Else
user = Username
End If
'// Score array is empty?
If spcCount = 0 Then
score = 0
End If
'// Get user's score
For i = 0 to spcCount - 1
If LCase(user) = spcArrScores(0,i) Then
score = spcArrScores(1,i)
Exit For
Else
score = 0
End If
Next
AddQ "/w " & Username & " " & user & "'s score is [" & score & "]"
End Sub
Sub is_correct_string(cmd, Username)
'// There's a game in progress and an active string?
If Not(spcPlayGame And spcGuessActive) Then Exit Sub
'// User has typed correct string?
If cmd(0) <> spcRandString Then Exit Sub
'// Add 1 to user's current score
For i = 0 To spcCount - 1
If LCase(Username) = spcArrScores(0,i) Then
spcArrScores(1,i) = spcArrScores(1,i) + 1
score = spcArrScores(1,i)
spcFlag = 1
End If
Next
If spcFlag = 0 then
spcArrScores(0,spcCount) = Lcase(Username)
spcArrScores(1,spcCount) = 1
score = 1
spcCount = spcCount + 1
End If
'// Get user's response time
ansTime = Int((GetGTC - spcTickCount)/1000)
'// Create time serial
secs = Right("00" & ansTime & ":", 3)
mSecs = Right("000" & ((GetGTC - spcTickCount)/1000 - ansTime) * 1000, 3)
spcTimeSerial = secs & mSecs
AddQ "Well done " & Username & "! Your score is [" & score & "]. Your time was [" & spcTimeSerial & "]."
spcStringInterval = spcStringInterval - 1 + Int(rnd * 3) '// vary the string interval
spcGuessActive = False
spcCounter = 0
timeLimitCounter = 0
End Sub
Sub scTimer_Timer()
'// Game in progress?
If Not spcPlayGame Then Exit Sub
If Not spcGuessActive Then
'// Display strings appx. at the specified interval
spcCounter = spcCounter + 1
If spcCounter = spcStringInterval Then
'// Generate random string
For i = 0 to 25
spcArrChar(i) = Chr(i + 97)
Next
For i = 26 to 89
spcArrChar(i) = ""
Next
For i = 0 to 11
spcArrNum(i) = Int(Rnd * (100 - string_length * 10))
spcArrLetter(i) = spcArrChar(spcArrNum(i))
Next
spcRandString = Join(spcArrLetter, "")
If spcRandString = "" Then '// Generated string is empty?
spcNum = Int(Rnd * 25)
spcRandString = spcArrChar(spcNum)
End If
AddQ "Type this the fastest: [" & spcRandString & "]"
spcTickCount = GetGTC
spcGuessActive = True
End If
Else
If time_limit_enabled = True Then
timeLimitCounter = timeLimitCounter + 1
If timeLimitCounter >= time_limit Then
AddQ "Time's up, you were too slow."
spcGuessActive = False
spcCounter = 0
timeLimitCounter = 0
End If
End If
End If
End Sub
Sub Event_PressedEnter(Text)
Event_UserTalk BotVars.Username, "", Text, 1
End Sub
Sub Event_Close()
If spcFSO.FileExists(spc_path) Then
spcFSO.DeleteFile(spc_path) '// Delete scores file
End If
Set spcFile = spcFSO.OpenTextFile(spc_path, 2, True) '// Create new, empty scores file
'// Write array of current scores to scores file
For j = 0 to spcCount - 1
If spcArrScores(i,j) <> "" Then
spcFile.WriteLine spcArrScores(0,j) & ":" & spcArrScores(1,j)
End If
Next
spcFile.close
End Sub
Để mọi người có thể sử dụng Script này mà không cần Access .Tìm trong Script các đoạn code sau
Trích dẫn:
Const clearsc_cmd_access = 100 '// Access required to clear all scores. Default: 100 Const startsc_cmd_access = 60 '// Access required to start Speed Challenge. Default: 60 Const stopsc_cmd_access = 60 '// Access required to stop Speed Challenge. Default: 60 Const score_cmd_access = -1 '// Access required to get a user's score. Default: -1 |
Và Edit lại như sau
Trích dẫn:
Const clearsc_cmd_access = -1 '// Access required to clear all scores. Default: 100 Const startsc_cmd_access = -1 '// Access required to start Speed Challenge. Default: 60 Const stopsc_cmd_access = -1 '// Access required to stop Speed Challenge. Default: 60 Const score_cmd_access = -1 '// Access required to get a user's score. Default: -1 |
Khi chỉnh sửa xong ,save lại .Trong bảng chính Stealthbot ,Chọn Settings ==> Reload Script .Nếu hiện dòng chữ "
Loaded 1 of 1 script files referenced " thì xem như bạn đã Add code thành công và có thể dụng .Nếu không hiện ra đoạn chữ thì tắt Stealthbot đi và Run lại là được . Còn hiện ra các dỏng chữ màu đỏ thì bạn đã add code sai .
Bạn có thể tìm thêm các Script tại địa chỉ này
Click Here