ID:263813
 
Code:
mob/var/list/questdone = list() //holds the list of finished quest npc id

mob/proc
Getitem(obj/get,getamount) //insert an item and amount
var/obj/New = get
for(var/i=0,i < getamount,i++)
src.Items+= New

Delitem(obj/reqitem,reqamount)
var/obj/M = reqitem
if(src.Items.Find(M))
for(var/i=0,i<reqamount,i++)
src.Items.Remove(M)

proc/Getitemname(obj/item)
return item.name

mob/proc/Countitem(obj/item)
//This proc will return the number of items for the specified item that the
//invoking character has in the inventory.
var/tmp/C = 0
var/obj/M = item
for(M in src.Items)
C+=1
return C

mob/Questnpcs
icon = 'NPC.dmi';icon_state="Quest"
name = "Quest NPC"
//note the item require and rewards must have objs in the same element as the amount
//ex: Rewards = list(obj/noob)
// RewardsAmount = list(10) must be lined up in the same order or else you get different amount
var/list/Rewards = list(/obj/dummyitem) //list of objs, rewarded after a quest
var/list/RewardAmount = list(2) //the quantity of the reward
var/list/Itemrequire = list(/obj/dummyitem)//a list of objs required for the reward
var/list/Reqitemamount = list(2)//the amount of the objs required for the reward
var/doable//still under construction
var/goldreq = 1000 //amount of gold required to get items
var/id = 1
var/alreadydonemes = "Hey, You already done my quest before!"
var/rewardedmes = "Thanks, Here is your reward"
var/getmes = "Ok, Ill wait here for you to bring the items"
var/noitems = "You Liar!, You don't have the items I asked you to get!"
proc
Quest(mob/M)
var/itemlist = ""
var/rewardslist = ""

for(var/n = 0, n<Itemrequire.len,n++) //a loop to get the text list
itemlist += "[text2num(Reqitemamount[n])] [Getitemname(Itemrequire[n])]<BR>"//amount and itemname

for(var/n = 0, n<Rewards.len,n++) //a loop to get the text list
rewardslist += "[RewardAmount[n]] [Getitemname(Rewards[n])]<BR>" //amount and itemname

if(id in usr.questdone) //make sure they dont do the quest again
alert(M,alreadydonemes)
return
var/mes
if(goldreq > 0)
alert(M,itemlist)
alert(M,rewardslist)
alert(M,"Dont forget to bring [goldreq] GP")
if(goldreq <= 0)
goldreq = 0 //if there was a ever a negitive number, go to 0
alert(M,itemlist)
alert(M,rewardslist)
switch(alert(M,mes,"","I got those Items!","I'll get those items right away"))
if("I got those Items!")
if(goldreq > 0) {if(M.gold < goldreq) Nomoney(M)}
for(var/q = 0,q < Itemrequire.len,q++)
if(M.Countitem(Itemrequire[q]) < Reqitemamount[q]) Noitems(M)
for(var/i = 0,i < Itemrequire.len,i++) //loop through the item list and delete the items
M.Delitem(Itemrequire[i],Reqitemamount[i])
for(var/s = 0,s < Rewards.len,s++)//loop through the rewards list and reward the items
M.Getitem(Rewards[s],RewardAmount[s])
if(goldreq > 0) {if(goldreq) usr.gold -= goldreq} //take away the gold
alert(M,rewardedmes)
M.questdone += id //put the npc's id, making it so you cant do this quest over again
if(usr.gold < goldreq) Nomoney(M)
alert(M,"Alright here is your [rewardslist]","[src.name]")
if("I'll get those items right away")
alert(M,getmes,"[src.name]")

Noitems(mob/M)
alert(M,noitems)
return
Nomoney(mob/M)
alert(M,"hmmm, didn't i mention to bring [goldreq]")
return

DblClick()
src.Quest(usr)


Problem description:

A runtime error saying invaild list index or something appears. Also i dont think i did this right
Considering you have about five million list references there, it would help if you enabled debugging (that would be under build -> preferences in DM) and told us what line the error was on.
In response to Garthor
itemlist += "[text2num(Reqitemamount[n])] [Getitemname(Itemrequire[n])]<BR>"


The error points here. What im trying to do here is to make a list and pop it up and tell the use which items to get and how many of that item to get. In the code i used alert but im gonna switch onto browse.
In response to Max Omega
Oh, I see. List indexing in BYOND goes from 1 to len, not 0 to len-1. Change the for() loops accordingly.
In response to Garthor
Alright I fixed the loops but alert isnt showing the list of items. Im not sure how this would work.