Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

NDW, [Python], hungry check module

Only working scripts
Post Reply
Xor
Neophyte
Neophyte
Posts: 21
Joined: 03.09.2012 7:07

NDW, [Python], hungry check module

Post by Xor »

создаем файл hungry.py

Code: Select all

#hungry.py
"""Модуль проверки голода

	вызывается check() или hungry()
	НЕ обязательный параметр: 1 или 0 - отключать ли чара на грани \
	смерти от сервера. Необходимо для сохранения жизни (шмота) при отсутствии еды. По умолчанию 1 \
	Кушает жареную рыбу до состояния 'You are staffed', рыба лежит где угодно в зоне доступа \
	будь-то сумка или пол или... """

from datetime import datetime as dt
from time import sleep
from stealth import *

def Hungry(do_disconnect=1):
	return Check(do_disconnect)

def Check(do_disconnect=1):
	if not Connected() or Dead():
		AddToSystemJournal("Cannot check hungry state, character is Not connected or dead")
		return 0

	state = [
		'You are absolutely stuffed!',
		'You are stuffed',
		'hungry at all',
		'You are a little hungry',
		'You are somewhat hungry',
		'You are REALLY hungry',
		'Your stomash hurts',
		'Your stomash hurts and you feel dizzy',
		'You are starving',
		'You are almost dying of hunger',
		'You are DYING of hunger...'
	]

	food = 0x097b
	pcs_to_eat = 0

	ts = dt.now()
	UOSay('.hungry')

	if (WaitJournalLine(ts,'|'.join(state),10000)):
		for i in range(2,len(state)):
			if (InJournalBetweenTimes(state[i],ts,dt.now()) > 0):
				pcs_to_eat = i - 1;
				break
	else:
		AddToSystemJournal('Cannod get .hungry state... Lag?')
		return 0
		
	if do_disconnect and pcs_to_eat >= 8 and not FindType(food,-1):
		AddToSystemJournal("No food found. Char will die soon. Disconnecting to prevent loses!")
		SetARStatus(False)
		Disconnect()
		return 0

	if pcs_to_eat > 0:
		for i in range(pcs_to_eat):
			if not FindType(food,-1):
				AddToSystemJournal("No food found!")
				return 0
			UseObject(FindItem())
			sleep(0.1)
	return 1
Импортим модуль к себе в скрипт:
import hungry
используем, где необхоидмо
hungry.Check() # отсоединит чара, если голод достиг уровня "almost dying of hunger" или голоднее только если еда не найдена
hungry.Check(0) # НЕ отсоединит чара, даже если будет умирать

ну, или для эстетствующих...
Импортим модуль к себе в скрипт:
from hungry import Hungry
ну, и используем, где необхоидмо
Hungry() # отсоединит чара, если голод достиг уровня "almost dying of hunger" или голоднее только если еда не найдена
Hungry(0) # НЕ отсоединит чара, даже если будет умирать

p.s. не забываем, что по умолчанию питон кушает русский только в юникоде. Так что либо сохраняем этот скрипт как UTF-8, либо вырезаем весь русский текст вверху - он в принципе не нужен
Post Reply