|
不知道有人发过没有,最近朋友需要所以做了个,希望能对大家有帮助
本系统由secret.sea制作,欢迎用到你的地图中,不过请在F9里注明Credit
- 输入ESC开始输入密码,密码是8位有序的方向键
- 按方向键时,最长间隔为1秒
- 输入错误或者超时均算一次错误,错误/超时 后按ESC从第一位重新输入
- 错误达到3次便失去再输入机会
- 演示地图的密码为 右右右右右右右右
演示下载:
PWSystem.w3x
(20 KB, 下载次数: 86)
移植方法:
1.复制自定义地图脚本 (需要Handle Local Vars 系统,在自定义地图脚本里,点击触发器编辑窗口左上角的w3x地图图标可以看到)
2.复制KeyPasswordSystem触发中的内容到自定义脚本,或者创建一个名为“KeyPasswordSystem”的触发,将内容复制进去
3.初始化,使用触发动作的自定义脚本 call PressKeysPW(p,trg,x1,x2,x3,x4,x5,x6,x7,x8)
参数解释: p 为玩家序号,红色玩家为0,依次加1 (本例为0,也就是说只有红色玩家才能按ESC输入密码)
trg 为密码输入成功后你要执行的触发动作的触发名 (本例为final)
x1-x8 为方向键密码序列, 0=左 1=右 2=下 3=上 如果代入其他数字,则这次密码初始化为无效
4.用T或者Jass创建你的目标动作,也就是密码输入正确后要执行的动作,并把触发名改为和参数trg一致
5.需要用到的全局变量 (注意大小写!)
integer array udg_fault 整数 数组 fault
boolean array udg_haveInitKey 布尔 数组 haveInitKey
trigger array udg_startKey 触发器 数组 startKey
[jass]
//============================================================================================//
// Press Arrow Keys for a password system, Author: Secret.Sea. //
// function conv10to4 by Red_Wolf //
// please give me credit if you use it in your w3x maps //
//============================================================================================//
// bj_KEYEVENTKEY_LEFT =0 //
// bj_KEYEVENTKEY_RIGHT =1 //
// bj_KEYEVENTKEY_DOWN =2 //
// bj_KEYEVENTKEY_UP =3 //
// ESC event=TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_END_CINEMATIC) //
// ******** Globle Vars ******* //
// integer array udg_fault (store times of input fault for each player) //
// boolean array udg_haveInitKey (switch the ESC trigger status) //
// trigger array udg_startKey (trigger for ESC) //
//============================================================================================//
// function conv10to4 convers a mod-10 integer to a mod-4 integer bit (Red_Wolf presents)
function conv10to4 takes integer num,integer bit returns integer
loop
exitwhen bit<=0
set num=num/4
set bit=bit-1
endloop
return num-num/4*4
endfunction
function PressKeyDisable takes nothing returns nothing
local timer tm = GetExpiredTimer()
local trigger t = GetHandleTrigger(tm,"keyTrigger")
local integer p = GetHandleInt(tm,"player")
call DisableTrigger(t)
set udg_fault[p] = udg_fault[p]+1
call DisplayTimedTextToPlayer( Player(p), 0, 0, 5.00, "输入超时! 已经错误"+I2S(udg_fault[p])+"次!" )
if udg_fault[p] >= 3 then
call FlushHandleLocals(t)
call DestroyTrigger(t)
endif
call FlushHandleLocals(tm)
call DestroyTimer(tm)
set tm = null
set udg_haveInitKey[p]=false
endfunction
function PressKeyCondition takes nothing returns boolean
local integer i = GetHandleInt(GetTriggeringTrigger(),"key")
local integer p = GetPlayerId(GetTriggerPlayer())
local timer tm = GetHandleTimer(GetTriggeringTrigger(),"timer")
if i == 0 then
if GetTriggerEventId() == EVENT_PLAYER_ARROW_LEFT_DOWN then
set tm=null
return true
endif
endif
if i == 1 then
if GetTriggerEventId() == EVENT_PLAYER_ARROW_RIGHT_DOWN then
set tm=null
return true
endif
endif
if i == 2 then
if GetTriggerEventId() == EVENT_PLAYER_ARROW_DOWN_DOWN then
set tm=null
return true
endif
endif
if i == 3 then
if GetTriggerEventId() == EVENT_PLAYER_ARROW_UP_DOWN then
set tm=null
return true
endif
endif
call DisableTrigger(GetTriggeringTrigger())
set udg_haveInitKey[p] = false
set udg_fault[p] = udg_fault[p] + 1
call DisplayTimedTextToPlayer( GetTriggerPlayer(), 0, 0, 5.00, "密码错误! 已经错误"+I2S(udg_fault[p])+"次! (请重新按ESC再输入密码)" )
if tm != null then
call FlushHandleLocals(tm)
call DestroyTimer(tm)
set tm=null
endif
if udg_fault[p] >= 3 then
call FlushHandleLocals(GetTriggeringTrigger())
call DestroyTrigger(GetTriggeringTrigger())
endif
set tm=null
return false
endfunction
function PressKeyAction takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local integer bit = GetHandleInt(t,"bit")
local timer tm = GetHandleTimer(t,"timer")
local integer pw = GetHandleInt(t,"pw")
call DisableTrigger(t)
if tm != null then
call FlushHandleLocals(tm)
call DestroyTimer(tm)
set tm=null
endif
if bit==7 then
call TriggerExecute( GetHandleTrigger(t,"final") )
call FlushHandleLocals(t)
call DestroyTrigger (t)
return
endif
if bit<7 then
call DisplayTimedTextToPlayer( GetTriggerPlayer(), 0, 0, 5.00, "输入正确! (第"+I2S(bit+1)+"位)" )
call SetHandleInt(t,"key",conv10to4(pw,bit+1))
call SetHandleInt(t,"bit",bit+1)
call EnableTrigger(t)
endif
set bj_lastStartedTimer = CreateTimer()
call SetHandleHandle(bj_lastStartedTimer,"keyTrigger",t)
call SetHandleInt(bj_lastStartedTimer,"player",GetPlayerId(GetTriggerPlayer()))
call SetHandleHandle(t,"timer",bj_lastStartedTimer)
call TimerStart(bj_lastStartedTimer,1.0,false,function PressKeyDisable)
set t= null
set tm= null
endfunction
function ESCTrigger_Condition takes nothing returns boolean
return not udg_haveInitKey[GetPlayerId(GetTriggerPlayer())]
endfunction
function ESCTrigger_Action takes nothing returns nothing
local integer p = GetPlayerId(GetTriggerPlayer())
local integer int_key = GetHandleInt(udg_startKey[p],"pw")
local trigger trg = GetHandleTrigger(udg_startKey[p],"final")
local trigger keyTrigger = GetHandleTrigger(udg_startKey[p],"keyTrigger")
local integer p0 = conv10to4(int_key,0)
if udg_fault[p] >=3 then
call DisplayTimedTextToPlayer( GetTriggerPlayer(), 0, 0, 5.00, "不好意思,您已经没有机会输入密码了...88" )
return
endif
set udg_haveInitKey[p] = true
call SetHandleInt(keyTrigger,"key",p0)
call SetHandleInt(keyTrigger,"bit",0)
call SetHandleHandle(keyTrigger,"final",trg)
call SetHandleInt(keyTrigger,"pw",int_key)
call DisplayTimedTextToPlayer( GetTriggerPlayer(), 0, 0, 5.00, "请输入密码,每次按键最大间隔为1秒" )
call EnableTrigger(keyTrigger)
set keyTrigger = null
set trg=null
endfunction
function PressKeysPW takes integer p , trigger trg, integer p0 , integer p1 , integer p2 , integer p3, integer p4, integer p5, integer p6, integer p7 returns nothing
local real key = I2R(p0) + I2R(p1)*4.0 + I2R(p2)*Pow(4.0,2.0) + I2R(p3)*Pow(4.0,3.0) + I2R(p4)*Pow(4.0,4.0) + I2R(p5)*Pow(4.0,5.0) + I2R(p6)*Pow(4.0,6.0) + I2R(p7)*Pow(4.0,7.0)
local integer j
local integer int_key =R2I(key)
local trigger keyTrigger = CreateTrigger()
if (p0>4 or p0<0) or (p1>4 or p1<0) or (p2>4 or p2<0) or (p3>4 or p3<0) or (p4>4 or p4<0) or (p5>4 or p5<0) or (p6>4 or p6<0) or (p7>4 or p7<0) then
return
endif
set udg_startKey[p] = CreateTrigger()
call SetHandleInt(udg_startKey[p],"pw",int_key)
call SetHandleHandle(udg_startKey[p],"final",trg)
call SetHandleHandle(udg_startKey[p],"keyTrigger",keyTrigger)
call TriggerRegisterPlayerEvent(udg_startKey[p], Player(p), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddCondition(udg_startKey[p],Condition (function ESCTrigger_Condition))
call TriggerAddAction(udg_startKey[p],function ESCTrigger_Action)
call TriggerRegisterPlayerEvent(keyTrigger, Player(p), EVENT_PLAYER_ARROW_LEFT_DOWN)
call TriggerRegisterPlayerEvent(keyTrigger, Player(p), EVENT_PLAYER_ARROW_RIGHT_DOWN)
call TriggerRegisterPlayerEvent(keyTrigger, Player(p), EVENT_PLAYER_ARROW_DOWN_DOWN)
call TriggerRegisterPlayerEvent(keyTrigger, Player(p), EVENT_PLAYER_ARROW_UP_DOWN)
call TriggerAddCondition(keyTrigger,Condition(function PressKeyCondition))
call TriggerAddAction(keyTrigger,function PressKeyAction)
call DisableTrigger(keyTrigger)
endfunction
//====================================================================================
function InitTrig_KeyPasswordSystem takes nothing returns nothing
endfunction
[/jass] |
评分
-
查看全部评分
|