Jump to content
  • 0

[Help] Print to a txt (from quest script)


Question

Posted

Hi all,

 

This is the code i'm trying to use to write to a text from a quest script

import math
import sys
from java.io import *
from com.l2jserver.gameserver              import Announcements
from com.l2jserver.util                    import Rnd
from java.lang                      import System
from com.l2jserver.gameserver.model.quest          import State
from com.l2jserver.gameserver.model.quest          import QuestState
from com.l2jserver.gameserver.model.quest.jython       import QuestJython as JQuest
from com.l2jserver.gameserver.model.actor.instance     import L2PcInstance
from com.l2jserver.gameserver.model.actor.instance     import L2NpcInstance
from com.l2jserver.gameserver.network.serverpackets    import PlaySound
from com.l2jserver.gameserver.model.itemcontainer import Inventory
from com.l2jserver.gameserver.network.serverpackets import MagicSkillUse 
from com.l2jserver.gameserver.network.serverpackets import MagicSkillLaunched
from com.l2jserver.gameserver.network.serverpackets import NpcHtmlMessage
from com.l2jserver.gameserver.network.serverpackets import ActionFailed
from com.l2jserver.gameserver.network.serverpackets import ExShowScreenMessage
from com.l2jserver.gameserver.model            import L2World
from com.l2jserver.gameserver.network.serverpackets import ExRedSky
from com.l2jserver.gameserver.network.serverpackets import Earthquake
from com.l2jserver.gameserver.datatables import SkillTable

#Enter information about NPCs interested in the event
MANAGER = 654321

#Quest Name
qn = "Lottery"

class Lottery (JQuest):

    def __init__(self,id,name,descr):
      JQuest.__init__(self,id,name,descr)


    def onTalk (self,npc,player):
      return "answerme.htm"

    def onAdvEvent (self,event,npc,player):
      if event.startswith("numbers"):
        output = BufferedWriter(FileWriter("numbers.txt"))
        output.write( "Hello" )


QUEST       = Lottery(-1, qn, "custom")


QUEST.addStartNpc(MANAGER)
QUEST.addTalkId(MANAGER)

print "[EVENT] Lottery LOADED SUCCESFULLY"

 

The event load succesfully, NPC is working. When i click on the event (to activate the onAdvEvent) nothing happens. With nothing i mean the text is not printed into the file.

 

The event is correctly triggered because i tried it by adding a <return "Hello"> into the <if event.startswith("numbers"):>

 

I tried using also python modules for file writing without succes...i really need some help from pro ppl :P

 

Thanks in advance

 

PS: The numbers.txt files already exixst and is not "Read Only"

 

 

EDIT

 

This is not working either

    def onAdvEvent (self,event,npc,player):
      if event.startswith("numbers"):
        f = open("numbers.txt","w")
        f.write("ciao")
        f.close()

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...