Page 1 of 2

Script engine for quests

Posted: Wed Feb 01, 2017 8:26 pm
by compbatant
The quests can be now much more complex because the quests engine supports now scripts written in Groovy language.
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
The code between "check" and "execute" is run to check if the quest can be executed. If we return true then it can be executed. The blue icon will appear over npc/quest entity. After we click on that npc then the code between "execute" and "end" will be executed.
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:
int armor = getFactor("armor");
You can also use random generator to generate random number and make different behavior based on that number.
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);
}
If you have ideas which require more functions to be added then tell me and I will add them. With scripting engine almost everything is possible now :)
The latest version of map editor support scripting engine. You can test there your scripts.

Re: Script engine for quests

Posted: Wed Feb 01, 2017 11:55 pm
by Bence
Python seems to be easyer :|

Re: Script engine for quests

Posted: Mon Feb 20, 2017 10:26 pm
by levi pt-br
Interesting.. may you Show the code for needed level?
I want to make up a quest with lvl diference for acquire pets

Re: Script engine for quests

Posted: Tue Feb 21, 2017 12:58 am
by DAVEmanda
levi pt-br wrote:LOL. Only 5 lvls?! ahahah
5 lvls and the honor of your quest was choiced, that's sufficient

Re: Script engine for quests

Posted: Tue Feb 21, 2017 10:37 am
by levi pt-br
compbatant wrote:The quests can be now much more complex because the quests engine supports now scripts written in Groovy language.
...
Yeah... I know this code engine! Similar to Java, you may send me the Resa's quest code . I want to fix it if possible

Re: Script engine for quests

Posted: Tue Feb 21, 2017 11:35 am
by levi pt-br
DAVEmanda wrote:
levi pt-br wrote:LOL. Only 5 lvls?! ahahah
5 lvls and the honor of your quest was choiced, that's sufficient
Yes, I'm just laughing, because when you do a bad little thing, you're permanent jailed, banned, took your gold / items / levels, outlawed, muted and more. The reward is good, okay, but .. could be better as well as punishment.. but you're right, sorry the coment..

Re: Script engine for quests

Posted: Tue Feb 21, 2017 4:37 pm
by blitzcraig
levi pt-br wrote:Interesting.. may you Show the code for needed level?
I want to make up a quest with lvl diference for acquire pets
you actually don't need to write this with groovy script - it is already written into quest mechanics... simple example:

id 351
needed_level 100
chat_npc Hello strong Adventurer

(he will only say that to players level 100+)

Re: Script engine for quests

Posted: Tue Feb 21, 2017 8:04 pm
by levi pt-br
blitzcraig wrote:
levi pt-br wrote:Interesting.. may you Show the code for needed level?
I want to make up a quest with lvl diference for acquire pets
you actually don't need to write this with groovy script - it is already written into quest mechanics..
Ok , ty for the explanation bro!

Re: Script engine for quests

Posted: Sun Sep 17, 2017 5:44 pm
by madmaniacal1
I'm not the best programmer by any stretch of the imagination, but perhaps this idea could be used for a quest that all players would do.

Int getlevel()

If (quest complete)
then (reward×(level))

This idea would allow players of all levels to gain an appropriate reward for the quest, without being too powerful for new players, or seen as pitiful by higher levels.

Re: Script engine for quests

Posted: Thu Sep 21, 2017 7:39 am
by DAVEmanda
madmaniacal1 wrote:I'm not the best programmer by any stretch of the imagination, but perhaps this idea could be used for a quest that all players would do.

Int getlevel()

If (quest complete)
then (reward×(level))

This idea would allow players of all levels to gain an appropriate reward for the quest, without being too powerful for new players, or seen as pitiful by higher levels.
This is idea is already implement in some of the new quests. Maybe no a Multiplication but yes different XP depending of lvl.

In the ice cave for example some quests gives you 1 lvl no matter what lvl you are