Unique Spawn Logging

Since there is not API for the Unique Spawns I have to use the 0x300C opcode to detect unique spawns.
My current problem is the data.
It looks something like b’\x06\x0c\xc8\xa1\x00\x00\x08\x00Mszecsod’.

How do I convert it to a ascii or utf-8 string?
I have tried many things but nothing actually worked.

There is no unique name in that packet. There is a model ID that you can use with get_monster(id).

1 Like

parse uniqe data id from hex data for example get_monster(int(“Parsed Data”, 16))

1 Like

Since march, 23… It exists. Just look at it.

3 Likes

did u look at my pm ? @JellyBitz

import phBot import *    
def handle_event(t,data):
	if t==0:
		log("Uniqe "+data+" Spawned");

event_handle

docs sainyg handle_event

I made a list of the events for a reason.

EVENT_UNIQUE_SPAWN = 0 # data = monster name
EVENT_HUNTER_SPAWN = 1 # data = player name (includes traders)
EVENT_THIEF_SPAWN = 2 # data = player name
EVENT_TRANSPORT_DIED = 3 # data = transport id (includes horses)
EVENT_PLAYER_ATTACKING = 4 # data = player name
EVENT_RARE_DROP = 5 # data = item model (equippable only)
EVENT_ITEM_DROP = 6 # data = item model (equippable only)
EVENT_DIED = 7 # data = empty string
EVENT_ALCHEMY_FINISHED = 8 # data = empty string

def handle_event(t, data):
	if t == EVENT_UNIQUE_SPAWN:
		log('%s spawned' % (data))
1 Like

Well been running this now for 35min and not a single log yet … even tho a lot of uniques appeared already. What am I doing wrong?

from phBot import *

# Called for specific events. data field will always be a string.
def handle_event(t, data):
	if t == EVENT_UNIQUE_SPAWN:
		log('%s spawned' % (data))

log('Loaded plugin!')

From my experience the event is only triggered if a unique spawns close to you.

1 Like

Correct. It’s not based off the notice.

So you are looking for something like this?

from phBot import *

SERVER_NOTICE_UNIQUE_UPDATE = 0x300C

# All packets received from Silkroad will be passed to this function
# Returning True will keep the packet and False will not forward it to the game server
def handle_joymax(opcode, data):
	if opcode == SERVER_NOTICE_UNIQUE_UPDATE:
		byte type
		if type == 5:
			byte unkByte
			uint uniqueModelID
			// Do stuffs
			unique = get_monster(int(uniqueModelID))
			log("["+unique['name']+"] appeared.")
		elif type == 6:
			byte unkByte
			uint uniqueModelID
			ushort killerNameLength
			ascii killerName
			// Do stuffs
			unique = get_monster(int(uniqueModelID))
			log("["+unique['name']+"] killed by ["+killerName+"]")
	return True

It doesn’t work actually, but you will figure out all the rest, I left at my sources examples about how to.

3 Likes

I got it working - thanks!

However the next step is sending it to Discord via a webhook.
Somehow whenever I wanna import anything within my script then it is not loading anymore by phbot.

For example if i write import aiohttp on top of the script then it is failing to load

I guess aiohttp is not available in the phbot python lib.
If it is not available, you need to install it yourself.
Check the following post of lucius, may it helps you.

I have done that already. However I still can’t load the script if i import aiohttp.
image

this is my phBot Testing\Plugins\python34\Lib directory

Plugin: uniques.py has failed to load

I tried to remove the json folder from python34/Libs and then import json in a plugin file.
It is still loading … how can that be?

Sorry, I just started with python as well. I can´t help you further anymore :frowning:

It is working - forgot to check back :smiley:

Logging Globals:

Logging Unique Kills and Unique Spawns:

Logging WTT-WTS-WTB from Globals:

Logging Job (also ingame pm)

This is unique af - took me quite a while to code it

3 Likes