查看: 2726|回复: 0

冒险岛脚本编写基础教程七

[复制链接]

初级会员

枫币
432
威望
0
贡献
15
在线时间
39 小时
注册时间
2019-3-9
QQ
发表于 2022-9-5 22:31:33 | 显示全部楼层 |阅读模式
第二课: 使用运算符
在这一课,你会学到几种运算符以及如何用他们。运算符可以帮你决定某 A 是
大于、小于还是等于某 B。以下是你最有可能会用到的运算符清单。
运 算 符          名 称           类 型                    描述
    !                   非                   一 元                  Returns true if 右操作数 evaluates to false. Returns false If the 右操作数 is true.

&&               条 件 且        二 元                  If the operand on the left returns false, returns false without evaluating the operand on the right.

  \                 条件或

以上运算符常用在条件句之间。什么是条件句?那是 NPC 脚本常看到的东西。
if (cm.haveItem(itemid, amount)) {
if (cm.getMeso() >= amount) {
if (cm.getPlayer().getLevel() >= amount) {

以上都是条件句。因此,在其中运用运算符,可以让你指定某种条件。例如:
if (cm.haveItem(4001129, 50) && cm.getMeso() >= 1000) { // 此处需要角色拥
有 50 黄金枫叶标志 且 拥有 1000 枫币
if (cm.haveItem(4001129, 50) || cm.getMeso() >= 1000) { // 此处需要角色拥
有 50 黄金枫叶标志 或 拥有 1000 枫币
if (!cm.haveItem(4001129, 50)) { // 此处会检查角色是否 非 拥有 50 黄金枫叶
标志
Using this is a good way to limit players from saving up loads
of an item to cash in at once. 接着,我们还有关系运算符,他们很常
被用在条件当中。列举其中一部分:

运算符号    名称           描述
==               等于          Returns true if the expression on the left evaluates to the same value as the expression on the right.


<                小于           Returns true if the expression on the left evaluates to a value that is less than the value of the expression on the right.

<=            小于或等于  Returns true if the expression on the left evaluates to a value that is less than or equal to the expression on the right.

>               大于            Returns true if the expression on the left evaluates to a value that is greater than the value of the expression on the right.

>=           大于或等于 Returns true if the expression on the left evaluates to a value that is greater than or equal to the expression on the right.
我已经给过范例了,如果你没注意到的话,我再列几个给你:
if (cm.getMeso() >= 1000) { // 如果角色的枫币「大于或等于」1000
if (cm.getPlayer().getLevel() == 120) { // 如果角色的等级「等于」120
if (cm.getJobById() <= 112) { // 如果角色的职业「小于或等于」112 (Hero,
Crusader, Fighter, Warrior, Beginner)

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|枫叶物语冒险岛单机 | 本站已运行:

枫叶物语可能会倒闭,但是绝对不会变质。

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖QQ客服返回顶部