############Lottery by Golgorth##V2.0###########################################
################################################################################
##1.- 妳需要在主目錄下創建壹個目錄,名叫"lottery"
##2.- 妳應該檢查每個配置的內容以適合妳的需要
## 妳可以自定義NPC所說的話,獎勵物品使用的時間
## 獲獎中獎號碼的彩票
##3.- 妳需要添加這些: [lotsystem::winnumber $player] :this check ##
## 將其放到 startup.tcl 的 OnPlayerDeath 中 ##
## 以檢查是否到了運行 winnernumber proc 的時候 ##
## 請小心地放入到正確的命名域(namespace)中 ,命名域是指妳將代碼放入到的目標腳本位置,而不是文件名
################################################################################
################################################################################
#這是 creatures.scp 中的彩票員,復制並修改id, 陣營以及模型,使其針對大部分的玩家
################################################################################
[creature 900101]
attack=2000 2000
name=彩券發行員
model=7311
faction=12
guild=國有彩券發行
type=7
family=7
questscript=lotterynpc
npcflags=07
faction=12
elite=3
level=60
maxhealth=10370
damage=1037 1659
maxmana=0
sell=30033 # 必須和 items.scp中添加的彩券ID壹致
###################################################################
#這是在 items.scp 中的物品 #
###################################################################
[item 30033]
name=彩券
buyprice=10000
startquest=123002 # 必須和添加到 quest.scp 中的quest ID壹致,其實就是壹個獲得以後激活的任務
questscript=lottery
stackable=1
class=12
classes=07FFF
flags=0800
material=-1
maxcount=1
model=31744
quality=1
races=01FF
sellprice=0
subclass=0
#########################################################
#添加到 quest.scp 中的內容(不要問為什麽需要這個) #
#########################################################
[quest 123002]
name=彩券
objectives=獲取妳的彩券號碼。
desc=準備好測試妳的幸運指數了嗎?
deliver=30033 1
src_item=30033
###########################################################
# 在tcl目錄中創建文件 lotsystem.tcl,並將以下內容復制到該文件中 #
###########################################################
namespace eval lotsystem {
proc lotterynum { player } {
set pname [GetName $player]
set n1_list "1 2 3 4 5 6 7 8 9 0"
set n2_list "1 2 3 4 5 6 7 8 9 0"
set n3_list "1 2 3 4 5 6 7 8 9 0"
set num1 [lindex $n1_list [expr {int(rand()*[llength $n1_list])}]]
set num2 [lindex $n2_list [expr {int(rand()*[llength $n2_list])}]]
set num3 [lindex $n3_list [expr {int(rand()*[llength $n3_list])}]]
set number "$num1$num2$num3"
set file "lottery/$number"
if { [file exists "lottery/$number"] != 1} {
set id [open $file a+]
puts $id "$pname"
close $id
return "妳的彩券號碼是 $number"
}
set id [open $file a+]
puts $id "$pname"
close $id
return "妳的彩券號碼是 $number"
}
# You should change the hours and day to check if is time to run lotto and to delete the folder
proc winnumber { player } {
set hourtime [clock format [clock seconds] -format {%H}]
set daytime [clock format [clock seconds] -format {%u}]
set checkfile "lottery/checkfile"
if { [file exists "lottery/checkfile"] != 1 } {
if { ($hourtime == 16) && ($daytime == 1) } {
set n1_list "1 2 3 4 5 6 7 8 9 0"
set n2_list "1 2 3 4 5 6 7 8 9 0"
set n3_list "1 2 3 4 5 6 7 8 9 0"
set num1 [lindex $n1_list [expr {int(rand()*[llength $n1_list])}]]
set num2 [lindex $n2_list [expr {int(rand()*[llength $n2_list])}]]
set num3 [lindex $n3_list [expr {int(rand()*[llength $n3_list])}]]
set number "$num1$num2$num3"
set file "lottery/winnernumber"
if { [file exists "lottery/winnernumber"] != 1 } {
set id [open $file w+]
puts $id "$number"
close $id
set cf [open $checkfile w+]
puts $cf ""
close $cf
}
set id [open $file w+]
puts $id "$number"
close $id
set cf [open $checkfile w+]
puts $cf ""
close $cf
}
}
if { ($daytime == 7) && ($hourtime == 23) } {
file delete -force "lottery"
file mkdir "lottery"
}
return
}
proc readwinner { player } {
set pname [GetName $player]
set yes "lottery/$pname"
set thewinneris "winnernumber"
set file "lottery/$thewinneris"
if { [file exists "lottery/$thewinneris"] != 1 } { return "中獎號碼還沒有生成" }
set id [open $file r]
gets $id data
close $id
set secondfile "lottery/$data"
if { [file exists "lottery/$data"] != 1 } { return "本期沒有任何人中獎." }
set secondid [open $secondfile r]
gets $secondid seconddata
close $secondid
set lines [split $seconddata \n]
set youwin [lsearch $seconddata $pname]
if { $youwin != -1 } {
if { [file exists "lottery/$pname"] != 1 } {
#Here you put the reward, use Item id.
AddItem $player 7
set cut [open $yes w+]
puts $cut "1"
close $cut
Say $player 0 "我中獎了!!"
}
}
return "中獎號是 $data,中獎的玩家有:$lines"
}
}
############################################################
#在tcl目錄下創建文件 lottery.tcl,並將以下代碼復制到文件中#
############################################################
namespace eval lottery {
proc QueryQuest { obj player questid } {
if { [GetQuestStatus $player $questid] != 4 } {
SendQuestReward $player $obj $questid "最棒的獎勵!" "妳是否真的想賭賭?"
SendGossipComplete $player
#SendQuestRequestItems $player $obj $questid "" "Activate your bet."
} else {
SendQuestDetails $player $obj $questid
}
}
proc QuestAccept { obj player questid } {
SendQuestReward $player $obj $questid "最棒的獎勵!" "妳是否真的想賭賭?"
SendGossipComplete $player
}
proc RequestReward { npc player questid } {
}
proc QuestChooseReward { obj player questid choose } {
lotsystem::lotterynum $player
}
proc OnOpen { obj player lootid } {
}
}
###########################################################
#在tcl目錄下創建文件 lotterynpc.tcl,並將以下內容復制到該文件中 #
###########################################################
#--------------------------------------------------------
namespace eval lotterynpc {
}
#--------------------------------------------------------
proc lotterynpc::GossipHello { npc player } {
SendGossip $player $npc { text 0 "我想購買壹張彩券" }\
{ text 0 "我中獎了嗎?" }\
{ text 1 "我需要壹些相關資料" }
}
#--------------------------------------------------------
# the lotsystem::winnumber $player is not very good here, so its better to put it in startup tcl in for example on playerdeath proc.
proc lotterynpc::GossipSelect { npc player option } {
switch $option {
0 { VendorList $player $npc }
1 { SendGossipComplete $player
lotsystem::winnumber $player
set win [lotsystem::readwinner $player ]
set resp "$win"
set news "text 0 \"$resp \n\n\n\""
set footer "text 2 \"Visit http://orangevirus.de for more
Informations\""
SendGossip $player $npc $news \
$footer }
2 { SendGossip $player $npc { text 0 "妳需要購買壹張彩券(我正在販賣),然後激活它。當彩券生效時,中獎號碼將被通知並且發布在這裏。如果妳是中獎者,那麽妳將自動獲得獎品。開獎時間在每周日 16:00。祝妳中獎!!"} }
}
}
#--------------------------------------------------------
proc lotterynpc::QueryQuest { npc player questid } {
}
#--------------------------------------------------------
proc lotterynpc::QuestStatus { npc player } {
}
#--------------------------------------------------------
proc lotterynpc::QuestHello { npc player } {
}
#--------------------------------------------------------
proc lotterynpc::QuestSelect { npc player questid } {
}
#--------------------------------------------------------
proc lotterynpc::QuestAccept { npc player questid } {
}
#--------------------------------------------------------
proc lotterynpc::QuestChooseReward { npc player questid choose } {
}
#--------------------------------------------------------
proc lotterynpc::RequestReward { npc player questid } {
}