Jump to content
  • 0

[HELP] Spawn a NPC+Announce!


Question

Posted

This code ws for other Chronicle so i change the Imports and NPC:

 

#Spawn a NPC Script



import sys



from com.l2jserver.gameserver import Announcements

from com.l2jserver.gameserver import GameTimeController

from com.l2jserver.gameserver.model.quest.jython import QuestJython as JQuest



qn = "Spawn_A_NPC"



#Write the ID of the NPC you want to spawn here

NpcSpawn = 40007



#Time before the spawn disappears(duration) in minutes

SpawnDuration = 5



#The spawn times are set to be on the hour exactly

#In this example, the spawn will happen at 5:00,11:00,17:00,23:00

SpawnTimes = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]



#If you want to set a % chance for the NPC to spawn or not

#Set to 100% as default

SpawnChance = 100



class Spawn_A_NPC(JQuest) :



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

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



     self.startQuestTimer("timer_check",60000, None, None, True)



     self.spawnCoords ={

                0: {'name':"in tent village." , 'X':8985 , 'Y':252976 , 'Z':-1933},

                1: {'name':"in ghost town." , 'X':-25436 , 'Y':251767 , 'Z':-3257},

                2: {'name':"near hidden oasis." , 'X':-19767 , 'Y':249873 , 'Z':-3258}, 

                3: {'name':"in caravan encampment." , 'X':-4292 , 'Y':256574 , 'Z':-3135},

                4: {'name':"near ancient temple remnants." , 'X':-28017 , 'Y':257666 , 'Z':-1908},

                5: {'name':"near Hellboound quarry." , 'X':-7666 , 'Y':246367 , 'Z':-1858},

                6: {'name':"near enchanted megaliths." , 'X':-21151 , 'Y':241954 , 'Z':-3124},

                7: {'name':"near Hellbound entrance." , 'X':-11026 , 'Y':238154 , 'Z':-3068},

                }





  def onAdvEvent (self,event,npc,pc) :



    if event == "timer_check" :

       gameTime = GameTimeController.getInstance().getGameTime()

       h = (gameTime/60)%24

       m = gameTime%60

       if h in SpawnTimes and m == 00 :

            rn = Rnd.get(100)

            if rn <= SpawnChance: 

                self.startQuestTimer("Start",100, None, None)



    if event == "Start" :

       spawn = int(Rnd.get(8))

       location = self.spawnCoords[spawn]['name']

       xx,yy,zz = self.spawnCoords[spawn]['X'],self.spawnCoords[spawn]['Y'],self.spawnCoords[spawn]['Z']

       despawn = SpawnDuration * 60000

       npcSpawn = self.addSpawn(NpcSpawn,xx,yy,zz,0,False,despawn)   

       Announcements.getInstance().announceToAll(npcSpawn.getName() + " has spawned " + location)



    return         



QUEST       = Spawn_A_NPC(-1, qn, "Spawn_A_NPC")            



print "Spawn_A_NPC script loaded." 

 

I put this __init_.py in C:\server\gameserver\data\scripts\quests\Spawn_A_NPC

 

and add to:

 

# Quests Section

quests/Spawn_A_NPC/__init__.py

 

No errors in console but NPC is not spawned. what can be?

2 answers to this question

Recommended Posts

  • 0
Posted

WoW this forum really help ppl!

 

What was that supposed to mean?

 

You are not the only one here who need help.

 

If you expect help the same day you requested help - hire your own dev.

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...