Skip to content

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

Featured Replies

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()

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.