Script to drop items only if a certain quest step is reached.

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@13411 282e977c-c81d-0410-88c4-b93c2d0d6712
master
ryo_saeba 2010-06-19 15:06:29 +00:00
parent ebe261f533
commit 39ae6d7f86
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# QuestConditionalDrop.py - A script to let items be dropped only if a quest
# reached a certain step.
#
# This script should be called for the 'death' event of a living thing.
# Each item in inventory will be checked for a 'drop_if_quest' key, which format is:
# - quest name
# - a list of steps, either single value (x) or range (x-y)
# If any matches, then the item will be dropped, else it won't.
# Items without the 'drop_if_quest' key are not affected.
import Crossfire
whoami = Crossfire.WhoAmI()
killer = Crossfire.WhoIsActivator()
def matches(rule):
if rule == '':
return True
args = rule.split()
currentstep = killer.QuestGetState(args[0])
for rule in args[1:]:
if rule.find("-") == -1:
startstep = int(rule)
endstep = startstep
else:
startstep = int(rule.split("-")[0])
endstep= int(rule.split("-")[1])
if currentstep >= startstep and currentstep <= endstep:
return True
return False
inv = whoami.Inventory
while inv != None:
key = inv.ReadKey('drop_if_quest')
if not matches(key):
inv.GodGiven = True
inv = inv.Below