93949413a 发表于 2011-7-23 15:15:20

转帖 【教程】入门脚本教程

打开bi\data\export_descr_advice.txt 这个文件。

要想要脚本工作,首先要添加一个线程。
要添加如下代码:

;------------------------------------------
AdviceThread BackgroundScriptThread
GameArea Campaign

Item BackgroundScriptItem1
Uninhibitable
Verbosity 0
Threshold 1
MaxRepeats 0
RepeatInterval 1
Attitude Normal
Presentation Default
Title BackgroundScriptTitle1
On_display scripts\show_me\background_script.txt
Text BackgroundScriptText1

同样是在export_descr_advice.txt文件,在尾端添加以下代码:

Trigger background_script_trigger_1
WhenToTest ButtonPressed

Condition ButtonPressed faction_button

AdviceThread BackgroundScriptThread 1

;------------------------------------------
Trigger background_script_trigger_2
WhenToTest ButtonPressed

Condition ButtonPressed construction_button

AdviceThread BackgroundScriptThread 1

;------------------------------------------
Trigger background_script_trigger_3
WhenToTest ButtonPressed

Condition ButtonPressed recruitment_button

AdviceThread BackgroundScriptThread 1
以下代码 我做简单的讲解
;------------------------------------------
Trigger background_script_trigger_4
WhenToTest SettlementSelected

AdviceThread BackgroundScriptThread 1

Trigger background_script_trigger_1
WhenToTest ButtonPressed

Condition ButtonPressed faction_button //按下派系的那个按钮 触发这个脚本

AdviceThread BackgroundScriptThread 1

;------------------------------------------
Trigger background_script_trigger_2
WhenToTest ButtonPressed

Condition ButtonPressed construction_button //这个是建设按钮

AdviceThread BackgroundScriptThread 1

;------------------------------------------
Trigger background_script_trigger_3
WhenToTest ButtonPressed

Condition ButtonPressed recruitment_button //这个是招募单位按钮

AdviceThread BackgroundScriptThread 1

;------------------------------------------
Trigger background_script_trigger_4
WhenToTest SettlementSelected //这个是选择城市

AdviceThread BackgroundScriptThread 1

准备工作完成,然后找data\scripts\show_me文件夹里面
新建一个记事本,名字叫background_script.txt

然后把以下代码复制进去:

script

; Anything following a semicolon is a comment.

; Remove the adviser portrait from screen.
select_ui_element advisor_dismiss_button
simulate_mouse_click lclick_up

; Wait for it to go away.
while I_AdvisorVisible
end_while

suspend_unscripted_advice true

; Open the adviser message bubble automatically whenever advance_advice_thread is called.
; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
; Do NOT mix both methods, though, or the advisor will show and then immediately close before
; you get a chance to read the text.
declare_show_me

; Very useful for debugging - uncomment to use
;console_command toggle_perfect_spy

;;;
;;; --- Forced shutdown ---
;;;
;;; Press 'Esc' on the campaign map, then click on the '?' button in the
;;; menu scroll to terminate the script.
;;;
;;; When would this be useful? -- When you are already in a game and
;;; exit back to the main menu to restart the campaign, or reload a saved
;;; game, RTW does not automatically terminate the script, so you have
;;; to do it yourself. If you leave the old script running, you'll have all
;;; sorts of weird problems with the script in the new game.
;;;
monitor_event ScrollAdviceRequested ScrollAdviceRequested end_game_scroll
terminate_script
end_monitor

; Handle saved game reloads
monitor_event GameReloaded TrueCondition
terminate_script
end_monitor

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This is where to put your own code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; For example, this will give you 1 gold at the beginning of every turn
monitor_event FactionTurnStart FactionIsLocal
console_command add_money 1
end_monitor

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of your code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
; In M2TW scripts, this loop is replaced by the wait_monitors command. Unfortunately, this command is not available in RTW.
while I_TurnNumber < 99999
suspend_unscripted_advice true
end_while

end_script
同样,对这段代码简易讲解下:



script

; Anything following a semicolon is a comment.

; Remove the adviser portrait from screen.
select_ui_element advisor_dismiss_button
simulate_mouse_click lclick_up

; Wait for it to go away.
while I_AdvisorVisible
end_while

suspend_unscripted_advice true

; Open the adviser message bubble automatically whenever advance_advice_thread is called.
; I recommend using this method instead of the select_ui_element + simulate_mouse_click approach.
; Do NOT mix both methods, though, or the advisor will show and then immediately close before
; you get a chance to read the text.
declare_show_me

; Very useful for debugging - uncomment to use
;console_command toggle_perfect_spy

;;;
;;; --- Forced shutdown ---
;;;
;;; Press 'Esc' on the campaign map, then click on the '?' button in the
;;; menu scroll to terminate the script.
;;;
;;; When would this be useful? -- When you are already in a game and
;;; exit back to the main menu to restart the campaign, or reload a saved
;;; game, RTW does not automatically terminate the script, so you have
;;; to do it yourself. If you leave the old script running, you'll have all
;;; sorts of weird problems with the script in the new game.
;;;
monitor_event ScrollAdviceRequested ScrollAdviceRequested end_game_scroll
terminate_script
end_monitor

; Handle saved game reloads
monitor_event GameReloaded TrueCondition
terminate_script
end_monitor

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This is where to put your own code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; For example, this will give you 1 gold at the beginning of every turn
;举个例子 这个代码 在每回合初 将给你的派系一块钱

monitor_event FactionTurnStart FactionIsLocal //这行开始
console_command add_money 1 //这个就是传说中的秘籍了。
end_monitor //到这边,这三行就是脚本的主要内容了。脚本代码都将放在这边。

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of your code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Spin forever - Do not let the script terminate or any monitors you have set up will immediately get thrown away.
; In M2TW scripts, this loop is replaced by the wait_monitors command. Unfortunately, this command is not available in RTW.

//在游戏中 第10万回合之前,脚本有效。
while I_TurnNumber < 99999
suspend_unscripted_advice true


在data\text\export_advice.txt 这个文件底部加以下代码:

{BackgroundScriptTitle1}脚本//名字随便起
{BackgroundScriptText1}脚本启动。。。
以上就是一个简单脚本的制作
简单的暴兵脚本


monitor_event FactionTurnStart FactionType carthage
and I_TurnNumber = 1

spawn_army
faction carthage

character Hannibal Barca, named character, age 16, , x 80, y 45
unit carthaginian general's cavalry, 10 exp 3 armour 3 weapon_lvl 3
unit carthaginian sacred band infantry, 10 exp 3 armour 3 weapon_lvl 3
unit carthaginian sacred band infantry, 10 exp 3 armour 3 weapon_lvl 3
unit carthaginian sacred band infantry, 10 exp 3 armour 3 weapon_lvl 3
unit carthaginian sacred band infantry, 10 exp 3 armour 3 weapon_lvl 3

end

terminate_monitor
end_monitor

end_while

end_script

出处http://tieba.baidu.com/p/1124542393?pn=1

key999 发表于 2011-7-23 17:55:18

感谢,研究研究

freefen 发表于 2011-7-24 13:37:27

提个建议 转帖 在正文开头写就行了不要在标题写了

027846 发表于 2011-8-6 15:48:05

很想学习呀,就是看不懂!!!!

qw232698727 发表于 2011-8-11 08:07:28

貌似在哪里看到过很多次,怎么这么多人转载啊?~!

fthmo1983 发表于 2011-8-19 15:45:47

研究研究

syhkn 发表于 2011-9-5 22:44:09

好深奥的东西!晕了!!:$

汉威 发表于 2011-11-30 14:26:55

喜欢三国,喜欢三国全面战争
21世纪什么最缺
人才
娃哈哈
:P:P:P:P:P:P

masche 发表于 2011-12-2 10:53:06

真难懂啊。。。顶一下

zjj1977 发表于 2012-1-22 17:32:10

很想学习呀,就是看不懂

浮澴柒裟 发表于 2012-6-10 22:51:41

好像蛮有技术的    hh

bushiyonghu1 发表于 2012-11-3 20:05:48

很好很强大,有空来研究!

清v水 发表于 2013-10-23 01:27:21

路过学习~
页: [1]
查看完整版本: 转帖 【教程】入门脚本教程