ID:1291369
 
(See the best response by Haiji.)
Code:
mob/var/tmp/quest1obtained = 0
mob/var/tmp/quest1killcount = 0


mob
proc
quest1killcheck()
if(quest1obtained==1)
if(istype(src, /mob/Fishman))
usr.quest1killcount++
else
return
else
return


mob
proc
quest1completecheck()
if(quest1killcount>=5)
usr << alert("Thank you so much!")
usr.exp+=1000
usr.Level_Up()
usr.quest1obtained++
else
usr << alert("You haven't killed 5 fishmen...")







mob
NPC
tutorialman
name = "Tutorial Man"
icon='alexbase.dmi'
Health = 1.#INF
Max_Health = 1.#INF
Click()
if(src in view(1,usr))
if(usr.quest1obtained==0)
switch(alert("Kill some Fishmen for me?",,"Yes","No"))
if("Yes")
usr.quest1obtained=1
usr << (alert("That's great!"))
return
if("No")
usr << (alert("That's too bad..."))
return
if(usr.quest1obtained==1)
usr.quest1completecheck()


Problem description:Whenever checking with the NPC, he'll always say you don't have enough kills. There's something wrong with the counter.quest1killcount() proc is called in the deathcheck. Please don't criticize it, that's not what I'm posting this for, I know it's bad, it's my first quest. I just need help fixing it.

Best response
You're using usr instead of src in the procs.

Also in this line:
if(quest1killcount>=5)


Shouldn't it be this?:
if(src.quest1killcount>=5)
I'm pretty sure this'll be a problem with your usage of usr as opposed to src.

As a rule of thumb, always use src unless it's within Click() or some such feature.

usr = The person doing the action
src = What the action is occuring on

Also note that by default src is assumed. So
mob
proc
quest1completecheck()
if(quest1killcount>=5)
usr << alert("Thank you so much!")


Is actually
mob
proc
quest1completecheck()
if(src.quest1killcount>=5)
usr << alert("Thank you so much!")
You're calling usr in the 'quest1killcheck()' you'll probably want to run mob/M through the arguments and set the player as M.

mob/verb/kill(var/mob/m)
m.die(src)//src is the person the verb comes from, you probably only want to use 'usr' here if the verb comes from a NPC or obj.
mob/proc/die(mob/m)
world<<"[src] was killed by [m]."//Relates directly back to the above verb, [src] is the m variable from the previous verb, and [m] here is the src from the previous verb.

In response to Rushnut
:( Trying to steal my spotlight
In response to Haiji
Haiji wrote:
:( Trying to steal my spotlight

If I hadn't of put that note at the end I'd of posted before you =p
In response to Rushnut
Also, *serious mode* - I do not know if you want that to happen, but tmp, which means temporary, will return the var to null once you log off. Right..? (@ MicdogMic)
In response to Rushnut
Same here >:(
In response to Haiji
tmp will not write to a savefile like other vars, if you save players by putting the entire mob into a savefile, it saves all variable outside of tmp vars and vars with the same properties as the default for the var.

You can directly save the tmp vars and load them back out, though.
In response to Haiji
Haiji wrote:
Also, *serious mode* - I do not know if you want that to happen, but tmp, which means temporary, will return the var to null once you log off. Right..? (@ MicdogMic)

That's not quite what tmp does, no. tmp means that the variable will not be written to a savefile using the default methods. A mob with tmp vars will still retain those vars if the client attatched disconnects.

Although I doubt that's what you meant.
Also, I recommend this way to code:


Change this:
if(usr.quest1obtained==0)


to:
if(!usr.quest1obtained)//Faster to write, put a "!" after the first bracket.


and -

Change this:
if(usr.quest1obtained==1)


to:
if(usr.quest1obtained)//Faster to write!


In response to Haiji
That's assuming he doesn't want it specific to those two numbers, if the number is less than or greater than 0, it'll return true when checking for a value on the var(if(var)). If you check for the lack of value in a var(if(!var)), it'll return true if it is null, "", or 0. If he wants to make sure it's 0 or 1, he did it right; cept he might want to use switch(var) to read them.

edit: and if he is just checking if the var has a value or not, he might want to use if()/else instead of two if() statements, though the way he seems to have it; it'll check if he already has the required kills right after accepting the quest. BUT, the var will only be given value after the quest has started.

 mob
proc
quest1killcheck()
if(quest1obtained==1)//see here
if(istype(src, /mob/Fishman))
usr.quest1killcount++


I don't see your kill code anywhere - we would need to see how you kill the monsters in order to determine if it is an issue with use of usr.
















Having to code in quests to variables is a long and tedious process. I know you said this is your first - but I wanted to give you something to look at in order to see how it could be easier.

Instead, quest and requirement datums can be used (and reused) for quests down the road - allowing a reusable, and dynamic quest system such as below.

mob
var/list/complete_quests = new()
var/list/quests = new()
proc/kill_quest(m)
for(var/quest/q in quests)
q.kill(m)
if(q.requirments_complete() && !q.reported_completed)
q.reported_completed = TRUE
src << "You have completed [q.quest_name]"

verb/AddQuestForSlimeAndSpiders()//Lets create a quest!
if("Kill 10 Slimes and 5 Spiders" in complete_quests)
src << "You've already completed quest: Kill 10 Slimes and 5 Spiders"
return
for(var/quest/q in quests)
if(q.quest_name == "Kill 10 Slimes and 5 Spiders")
src << "You already have this quest"
return

var/quest/q = new()
q.quest_name = "Kill 10 Slimes and 5 Spiders"

var/requirement/r1 = new() //add requirment for slimes
r1.path = /mob/monsters/slime
r1.count_need = 10
q.requirements += r1

var/requirement/r2 = new() //add the requirement for spiders
r2.path = /mob/monsters/spider
r2.count_need = 5
q.requirements += r2

//Now our rewards!
q.experience = 100 //Stronger!
q.gold = 25 //Wealth $.$

//two health, and three mana potions! YAY
q.item += /obj/potion/health
q.item += /obj/potion/health
q.item += /obj/potion/mana
q.item += /obj/potion/mana
q.item += /obj/potion/mana
q.item += /obj/oldbook //noone wants a book, but maybe a nice treat!

quests += q //now lets add it to our quest list!

src << "Go kill some slimes and some spiders. (10, 5)"

verb/KillMonster()//for testing, as we don't want to really kill anything - waste of time!
var/kill = input("Kill what?") in list("/mob/monsters/slime","/mob/monsters/spider")
kill = text2path(kill)
kill_quest(new kill)

verb/FinishQuestForSlimeAndSpiders()
for(var/quest/q in quests)
if(q.quest_name == "Kill 10 Slimes and 5 Spiders")
complete_quest(src)
complete_quests+= q.quest_name
level_check()

quest
var/list/requirements = new()
var/reported_completed = FALSE
var/quest_name = ""
var/gold = 0
var/experience = 0
var/list/item = new()

proc/kill(m)
if(requirments_complete()) return //if we are done, no need to add
for(var/requirement/r in requirements)
r.kill(m)


proc/requirments_complete() //check if we are done
for(var/requirement/r in requirements)
if(!r.complete())
return FALSE
return TRUE

proc/complete_quest(mob/m)
if(reported_completed)
m.gold += src.gold //add gold
m.experience += src.experience //add experience
for(var/x in item) //for each item
var/obj/o = new(m.contents) //create in the inventory




requirement
var/kill_path
var/count_need
var/count_have

proc/kill(m)
if(istype(m,kill_path) && !complete()) //if it's the path, and we are not done
count_have++ //increment how many

proc/complete()
return (count_have >= count_need)
Thank you guys for all the help, I'm changing around quite a few things. Here's the death check if it helps. Please don't puke, I know it's disgusting.



        Death_Check()
if(src.Health<=0)
if(src.client)
src.Health=src.Max_Health
Load_Stats()
usr << output("<font color = #00FFFF>You have killed [src]!","output2")
src << output("<font color = #00FFFF>[usr] has killed you!","output2")
src.loc=locate(248,220,1)//respawn them?
usr.Kills+= 1
src.Deaths+= 1
src<<sound(null)
if(usr.Faction=="Pirate")
usr.Pirate_Rank_Check()
else
attacker << output("<font color = #00FFFF>You have killed [src]!","output2")
attacker.exp +=src.giveexp
attacker.Load_Stats()
attacker.quest1killcheck()
attacker.Doubloons+=src.Doubloons
attacker.UpdateDoubloons()
src.loc = locate(500,500,5)
sleep(src.respawn_delay)
src.loc = locate(src.home_x,src.home_y,src.home_z)
src.Health = src.Max_Health
src.attacked=0
                else
attacker << output("<font color = #00FFFF>You have killed [src]!","output2")
attacker.exp +=src.giveexp
attacker.Load_Stats()
attacker.quest1killcheck()
attacker.Doubloons+=src.Doubloons
attacker.UpdateDoubloons()
src.loc = locate(500,500,5)
sleep(src.respawn_delay)
src.loc = locate(src.home_x,src.home_y,src.home_z)
src.Health = src.Max_Health
src.attacked=0

In this proc, you're calling quest1killcheck() on the ATTACKER

But in HERE you are checking if the SRC (the ATTACKER from the previous proc becomes the SRC here) is the FISHMAN.
        quest1killcheck()
if(quest1obtained==1)
if(istype(src, /mob/Fishman))
usr.quest1killcount++
else
return
else
return


One would think you'd check the thing that DIED if it's the fishman, not the thing that did the attacking.
You would want to do this, really:

            DeathCheck()
if(bleh)
//insert bad code here
else
//insert bad code here
attacker.quest1killcheck(src)
//insert more bad code here


        quest1killcheck(mob/THINGTHATDIED)
if(quest1obtained==1)
if(istype(THINGTHATDIED, /mob/Fishman))
quest1killcount++