User Tools

Site Tools


lua:scripting:examples:qtimerluavals

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua:scripting:examples:qtimerluavals [2014/12/31 22:18] vodurlua:scripting:examples:qtimerluavals [2015/01/01 00:53] (current) vodur
Line 1: Line 1:
 ====== Original ====== ====== Original ======
- +<code lua> 
-<code lua>-- Kain GRALL code for sack of rice +-- Kain GRALL code for sack of rice 
-say("Keep counting kid... We'll work some of that fight out of you."+say("Keep counting kid... We'll work some of that fight out of you.")
 emote("puts some bricks on Cloud's back, JUST to make sure he gets a work out.") emote("puts some bricks on Cloud's back, JUST to make sure he gets a work out.")
 -- Kain greet code to start quest -- Kain greet code to start quest
Line 25: Line 25:
 local ricevnum=7326 local ricevnum=7326
 local qvnum=14800 local qvnum=14800
 + 
 -- Does he want it? -- Does he want it?
 if not(obj1.vnum==ricevnum) then if not(obj1.vnum==ricevnum) then
-    say("I don't want this."    mdo("give '%s' %s", obj1.name, ch.name)     mdo("drop %s", obj1.name)     return end   -- check if their timer is still running if ch:qtimer(qvnum)>0 then     say("You should give someone else a turn. Come back in %d hours", ch:qtimer(qvnum))     mdo("give '%s' %s", obj1.name, ch.name)     mdo("drop %s", obj1.name)     return end   -- check if already gave that one tracker=tracker or {} if tracker[ch.name] and tracker[ch.name][obj1.vnum] then     say("You already gave me that!"    mdo("give '%s' %s", obj1.name, ch.name)     mdo("drop %s", obj1.name)     return end   -- He really wants it! if tracker[ch.name]==nil then     tracker[ch.name]={} end tracker[ch.name][obj1.vnum]=true say("Thanks %s!", ch.name)   -- Now see if finished if tracker[ch.name][ricevnum] then -- Has the rice     qset(ch, qvnum, 1, 24)     say("Haha! Cloud will be strong in no time with this kind of weight!"    mdo("mob junk '%s'", obj1.name)     reward(ch, "qp", 15)     tracker[ch.name]=nil else     say("I still need a %s", getobjproto( (not(tracker[ch.name][ricevnum]))).shortdescr) end   -- End Kain give code+    say("I don't want this.") 
 +    mdo("give '%s' %s", obj1.name, ch.name) 
 +    mdo("drop %s", obj1.name) 
 +    return 
 +end 
 +  
 +-- check if their timer is still running 
 +if ch:qtimer(qvnum)>0 then 
 +    say("You should give someone else a turn. Come back in %d hours", ch:qtimer(qvnum)) 
 +    mdo("give '%s' %s", obj1.name, ch.name) 
 +    mdo("drop %s", obj1.name) 
 +    return 
 +end 
 +  
 +-- check if already gave that one 
 +tracker=tracker or {} 
 +if tracker[ch.name] and tracker[ch.name][obj1.vnum] then 
 +    say("You already gave me that!") 
 +    mdo("give '%s' %s", obj1.name, ch.name) 
 +    mdo("drop %s", obj1.name) 
 +    return 
 +end 
 +  
 +-- He really wants it! 
 +if tracker[ch.name]==nil then 
 +    tracker[ch.name]={} 
 +end 
 +tracker[ch.name][obj1.vnum]=true 
 +say("Thanks %s!", ch.name) 
 +  
 +-- Now see if finished 
 +if tracker[ch.name][ricevnum] then -- Has the rice 
 +    qset(ch, qvnum, 1, 24) 
 +    say("Haha! Cloud will be strong in no time with this kind of weight!") 
 +    mdo("mob junk '%s'", obj1.name) 
 +    reward(ch, "qp", 15) 
 +    tracker[ch.name]=nil 
 +else 
 +    say("I still need a %s", getobjproto( (not(tracker[ch.name][ricevnum]))).shortdescr) 
 +end 
 +  
 +-- End Kain give code
 </code> </code>
  
 ===== With luavals ===== ===== With luavals =====
- +<code lua> 
-<code lua>-- Kain GRALL code for sack of rice +-- Kain GRALL code for sack of rice 
-say("Keep counting kid... We'll work some of that fight out of you.") emote("puts some bricks on Cloud's back, JUST to make sure he gets a work out.")+say("Keep counting kid... We'll work some of that fight out of you.") 
 +emote("puts some bricks on Cloud's back, JUST to make sure he gets a work out.")
 -- Kain greet code to start quest -- Kain greet code to start quest
 local ricevnum=7326 local ricevnum=7326
Line 40: Line 82:
 local time_current=os.time() local time_current=os.time()
 local time_quest=ch:getval("kain_timer") or 0 local time_quest=ch:getval("kain_timer") or 0
-if time_quest>time_current then+if time_quest>time_current then 
     say("You should give someone else a turn. Come back in %d hours", math.ceil((time_quest-time_current)/3600))     say("You should give someone else a turn. Come back in %d hours", math.ceil((time_quest-time_current)/3600))
-    return+    return 
 end end
 -- Don't talk them if already gave something -- Don't talk them if already gave something
 tracker=tracker or {} tracker=tracker or {}
 if tracker[ch.name] then return end if tracker[ch.name] then return end
 + 
 say("Hey %s! I need some more weights for cloud. Can you bring me a '%s'?", say("Hey %s! I need some more weights for cloud. Can you bring me a '%s'?",
     ch.name,     ch.name,
Line 54: Line 96:
 </code> </code>
  
-<code lua>-- Kain give code+<code lua> 
 +-- Kain give code
 local ricevnum=7326 local ricevnum=7326
 +local qvnum=14800
  
 -- Does he want it? -- Does he want it?
 if not(obj1.vnum==ricevnum) then if not(obj1.vnum==ricevnum) then
-    say("I don't want this."    mdo("give '%s' %s", obj1.name, ch.name)     mdo("drop %s", obj1.name)     return end   -- check if their timer is still running local time_current=os.time() local time_quest=ch:getval("kain_timer") or 0 if time_quest>time_current then     say("You should give someone else a turn. Come back in %d hours", math.ceil((time_quest-time_current)/3600))     mdo("give '%s' %s", obj1.name, ch.name)     mdo("drop %s", obj1.name)     return end   -- check if already gave that one tracker=tracker or {} if tracker[ch.name] and tracker[ch.name][obj1.vnum] then     say("You already gave me that!"    mdo("give '%s' %s", obj1.name, ch.name)     mdo("drop %s", obj1.name)     return end   -- He really wants it! if tracker[ch.name]==nil then     tracker[ch.name]={} end tracker[ch.name][obj1.vnum]=true say("Thanks %s!", ch.name)   -- Now see if finished if tracker[ch.name][ricevnum] then -- Has the rice     qset(ch, qvnum, 1, 24)     ch:setval("kain_timer", time_current + 3600*24, true) -- Now + 24hrs     say("Haha! Cloud will be strong in no time with this kind of weight!"    mdo("mob junk '%s'", obj1.name)     reward(ch, "qp", 15)     tracker[ch.name]=nil else     say("I still need a %s", getobjproto( (not(tracker[ch.name][ricevnum]))).shortdescr) end   -- End Kain give code+    say("I don't want this.") 
 +    mdo("give '%s' %s", obj1.name, ch.name) 
 +    mdo("drop %s", obj1.name) 
 +    return 
 +end 
 +  
 +-- check if their timer is still running 
 +local time_current=os.time() 
 +local time_quest=ch:getval("kain_timer") or 0 
 +if time_quest>time_current then 
 +    say("You should give someone else a turn. Come back in %d hours", math.ceil((time_quest-time_current)/3600)) 
 +    mdo("give '%s' %s", obj1.name, ch.name) 
 +    mdo("drop %s", obj1.name) 
 +    return 
 +end 
 +  
 +-- check if already gave that one 
 +tracker=tracker or {} 
 +if tracker[ch.name] and tracker[ch.name][obj1.vnum] then 
 +    say("You already gave me that!") 
 +    mdo("give '%s' %s", obj1.name, ch.name) 
 +    mdo("drop %s", obj1.name) 
 +    return 
 +end 
 +  
 +-- He really wants it! 
 +if tracker[ch.name]==nil then 
 +    tracker[ch.name]={} 
 +end 
 +tracker[ch.name][obj1.vnum]=true 
 +say("Thanks %s!", ch.name) 
 +  
 +-- Now see if finished 
 +if tracker[ch.name][ricevnum] then -- Has the rice 
 +    qset(ch, qvnum, 1, 24) 
 +    ch:setval("kain_timer", time_current + 3600*24, true) -- Now + 24hrs 
 +    say("Haha! Cloud will be strong in no time with this kind of weight!") 
 +    mdo("mob junk '%s'", obj1.name) 
 +    reward(ch, "qp", 15) 
 +    tracker[ch.name]=nil 
 +else 
 +    say("I still need a %s", getobjproto( (not(tracker[ch.name][ricevnum]))).shortdescr) 
 +end 
 +  
 +-- End Kain give code
 </code> </code>
  
lua/scripting/examples/qtimerluavals.1420064302.txt.gz · Last modified: 2014/12/31 22:18 by vodur