ID:2254158
 
Code:
mob
var/list/inQuest=list()
Enemy
inQuests=list("Quest1", "Quest2")

DeathCheck(mob/Killer)
if(src.HP<=0)
if(src.key)
...
else
....

if(src.inQuests.len>=1)
for(var/q in src.inQuests)
if(Killer.HasQuest("[q]"))//any alternative?
...
else
...


Problem description:
I try to check do monster is in the Quest list. Do my method to check it is correct i mean about
for(var/q in src.inQuests)
this part. I know about Find proc, but i don't know how to use it. Can someone help me?

In HasQuest i just try fo find name quest in player quest list.
You are very, very close to a decent solution. Keep up the good work!

I know about Find proc, but i don't know how to use it. Can someone help me?

The `Find` proc returns the index of the result, instead of the result itself.

var/result = src.inQuests.Find("Quest1")

// 0 means there was no result :(
if(0 == result)
del world
return FALSE

world << "Success! Quest was located at src.inQuests\[[result]\]"
return TRUE
Honestly, I would approach this differently.

Your current setup won't allow the flexibility needed for greater quests and you'll just end up having to hard-code quests over and over.

I'd recommend making quests their own datum and handling the quests themselves as lists with quantities and associative values. That'll allow less hard-coded quests and you can even generate "randomly generated quests" or easily make periodical quests in run-time.

Honestly, I would have more to this and more to show but this is some old code I had laying around that I was gonna use but never got around to completing. Should really be used as a "reference" or "you don't have to do this exactly, but here's an ideal I'm brainstorming for ya."




Edit/Updated :
Added this in the last 10 minutes before bed.
quest
var
quest_requirements = list()
quest_details = list("name" = "A Quest", "finished" = 0, "completed" = 0, "required" = 0, "reward" = list())

gather
GET_5_APPLES
quest_requirements = list(/obj/fruit/apple)
New()
..()
src.quest_details["name"] = "GET_5_APPLES"
src.quest_details["finished"] = 0
src.quest_details["completed"] = 0
src.quest_details["required"] = 5
src.quest_details["reward"] = list("gold" = 100)
kill
SLAY_DRAGON
quest_requirements = list(/mob/enemy/dragon)

KILL_5_OGRES
quest_requirements = list(/mob/enemy/ogre)
proc
changeAmount(quantity, mob/player)
if(!src.quest_details["finished"])
src.quest_details["completed"] += quantity
if(src.quest_details["completed"] >= src.quest_details["required"])
src.finishQuest(player)
else
return
finishQuest(mob/player)
src.quest_details["finished"] = 1
// Add reward system.
atom
var
inQuests = list()
obj
fruit
apple
icon = 'test.dmi'
icon_state = "object"
inQuests = list(/quest/gather/GET_5_APPLES)
mob
var
quests = list()

enemy
dragon
inQuests = list(/quest/kill/SLAY_DRAGON)
ogre
inQuests = list(/quest/kill/KILL_5_OGRES)
proc
checkIfQuest(check)
if(istype(check,/obj))
var/obj/target = check
for(var/quest/Q in src.quests)
var/list/check_quest = Q.quest_requirements
if(check_quest.Find(target.type))
Q.changeAmount(1, src)

if(istype(check,/mob))
var/mob/target = check
for(var/quest/Q in src.quests)
var/list/check_quest = Q.quest_requirements
if(check_quest.Find(target.type))
Q.changeAmount(1, src)
verb
gather()
for(var/obj/fruit/target in bounds(src, 16))
src.checkIfQuest(target)
src.contents += target


Again, not perfect but it's a start towards something that's more flexible and I'll probably never finish this since I have no need for it and I'm tired.

Another Edit:

I would also like to add that you could even use .xml or configuration files--hell, even make a separate program/environment that'll create .xml or configuration files with easy click'n'make--for the quest_details for the run-time quests. As in, players or "administrators" can create quests on the fly by changing a template and just have the game import the details and change the quest_details of a new blank quest object to match. Fleeeeeeeexibility.