Script engine for quests

You want to develop content? Create maps, items or quests! Get rewarded!

Moderator: Game Administrators

User avatar
compbatant
Site Admin
Posts: 1946
Joined: Fri Jun 15, 2012 12:00 am
Location: Warsaw, Poland
Contact:

Script engine for quests

Post 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.
Bence
Posts: 556
Joined: Sat Dec 13, 2014 4:43 am

Re: Script engine for quests

Post by Bence »

Python seems to be easyer :|
"We are unity in diversity"
lvl 1006 mage
User avatar
levi pt-br
Posts: 190
Joined: Tue Mar 15, 2016 4:33 pm
Location: Brasil
Contact:

Re: Script engine for quests

Post 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
Last edited by levi pt-br on Tue Feb 21, 2017 11:05 am, edited 1 time in total.
Levi pt-br
Game Translator: Portuguese
Spoken Language: Portuguese, English, Spanish.
Links Úteis: Show
User avatar
DAVEmanda
Posts: 1137
Joined: Fri Jun 24, 2016 11:08 pm
Location: España

Re: Script engine for quests

Post by DAVEmanda »

levi pt-br wrote:LOL. Only 5 lvls?! ahahah
5 lvls and the honor of your quest was choiced, that's sufficient
Accounts :
DAVE_manda
Dave_mago
Dave_pesca
Dave_enano
Dave_shot
Red_Croc
Green_Croc
PurpleCroc
MultiCroc
---

GAME TRANSLATOR (Spanish)

GAME TESTER

Seguir las reglas del juego. Si tenéis alguna duda enviarme un mensaje privado. Gracias
User avatar
levi pt-br
Posts: 190
Joined: Tue Mar 15, 2016 4:33 pm
Location: Brasil
Contact:

Re: Script engine for quests

Post 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
Last edited by levi pt-br on Tue Feb 21, 2017 3:27 pm, edited 1 time in total.
Levi pt-br
Game Translator: Portuguese
Spoken Language: Portuguese, English, Spanish.
Links Úteis: Show
User avatar
levi pt-br
Posts: 190
Joined: Tue Mar 15, 2016 4:33 pm
Location: Brasil
Contact:

Re: Script engine for quests

Post 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..
Levi pt-br
Game Translator: Portuguese
Spoken Language: Portuguese, English, Spanish.
Links Úteis: Show
blitzcraig
Posts: 3032
Joined: Fri Oct 18, 2013 12:00 am
Location: United States of America

Re: Script engine for quests

Post 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+)
Beeware the Spiral Blitzbees...
⬜ 💣 🌏
User avatar
levi pt-br
Posts: 190
Joined: Tue Mar 15, 2016 4:33 pm
Location: Brasil
Contact:

Re: Script engine for quests

Post 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!
Levi pt-br
Game Translator: Portuguese
Spoken Language: Portuguese, English, Spanish.
Links Úteis: Show
User avatar
madmaniacal1
Posts: 1656
Joined: Mon May 23, 2016 12:29 am

Re: Script engine for quests

Post 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.
User avatar
DAVEmanda
Posts: 1137
Joined: Fri Jun 24, 2016 11:08 pm
Location: España

Re: Script engine for quests

Post 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
Accounts :
DAVE_manda
Dave_mago
Dave_pesca
Dave_enano
Dave_shot
Red_Croc
Green_Croc
PurpleCroc
MultiCroc
---

GAME TRANSLATOR (Spanish)

GAME TESTER

Seguir las reglas del juego. Si tenéis alguna duda enviarme un mensaje privado. Gracias
Post Reply