Groovy is very similar to Java and can use Java functions. You don't need to be expert in programming, the basics of basics will be enough
to create more complicated quests. You could learn from examples.
From script you can access to the following functions:
Code: Select all
long getGold();
void addGold(long gold);
int getLevel();
boolean hasItem(int itemId);
boolean hasItem(ItemType itemType, ItemParam itemParam, int minimumValue);
void removeItem(ItemType itemType, ItemParam itemParam, int minimumValue);
int countItem(int itemId);
void removeItem(int itemId);
void addItem(int itemId);
void addXp(long xp);
WeaponType getWeaponType();
boolean isQuestFinished(int questId);
void finishQuest(int questId);
void resetQuest(int questId);
void markQuestFinished(int questId);
ArrayList<Integer> getFollowers();
void createEntity(int entityId);
void follow(int entityId);
void unfollow(int entityId);
void teleport(String destination);
void setFactor(String name, int value);
boolean hasFactor(String name);
int getFactor(String name);
ArrayList<QuestInterface> getNearPlayers(int range);
void changeFactor(String name, int value);
void playSound(String soundName);
void runCommand(String cmd);
You put script quest in the same files as regular quests. The quest can be mixed with regular and script quests in one file.
Here is example script quest:
Code: Select all
id 1671
chat_npc Congratulations!
check
if(isQuestFinished(1670) && (hasItem(560) || hasItem(561))) {
return true;
} else {
return false;
}
execute
addXp(10);
end
In the above quest we check if player already finished quest with id 1670 and if he has item 560 or item 561.
If all conditions are fulfilled then we can add 10xp when the quest is activated. Also the message "Congratulations!" will be displayed.
With function getFactor the quest can get access to most of the parameters of player, like dexterity, max_mana, damage, armor, max_hp, etc
To read it use:
You can also use random generator to generate random number and make different behavior based on that number.int armor = getFactor("armor");
To create random number you can use my FT function. First import it:
import com.rts.game.util.RandomGenerator;
next:
int value = RandomGenerator.nextInt(MAX_VALUE);
and the output will be from 0 to MAX_VALUE-1
You can store this number using setFactor("quest_data", value) function and read it later in different quest.
You could check also all players in specified range:
ArrayList<QuestInterface> getNearPlayers(int range);
You can iterate over them and execute some methods like adding everybody some xp or teleporting them.
We are able now to create quests which require more players. For example quest can be activated only if there is archer and mage and swordsman near the quest activator.
To add everybody near activated NPC (in range 10) xp we can use:
Code: Select all
for(QuestInterface player : getNearPlayers(10)) {
player.addXp(100);
}
The latest version of map editor support scripting engine. You can test there your scripts.