| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# sell_punisher.py - Punish players for selling items |
| 3 |
# |
| 4 |
# Copyright (C) 2010 Nicolas Weege |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 |
# |
| 20 |
# |
| 21 |
# This script punishes players trying to sell the item it is linked to. |
| 22 |
# The item is then not sold. |
| 23 |
# |
| 24 |
# It should be called from a "selling" event. |
| 25 |
# |
| 26 |
# An optional "punish_sell_in" key can be put in the item (not the event) |
| 27 |
# to specify a base path to punish selling it in maps which path starts with that value. |
| 28 |
# For instance, to restrict selling to Scorn, use "punish_sell_in /scorn/". |
| 29 |
# |
| 30 |
# If no key is defined, trying to sell is punished in the whole world. |
| 31 |
|
| 32 |
import Crossfire |
| 33 |
import random |
| 34 |
|
| 35 |
def sell_is_restricted(): |
| 36 |
map = Crossfire.WhoAmI().ReadKey("punish_sell_in") |
| 37 |
if map == "": |
| 38 |
return 1 |
| 39 |
|
| 40 |
current = Crossfire.WhoIsActivator().Map.Path |
| 41 |
|
| 42 |
if len(current) < len(map): |
| 43 |
return 0 |
| 44 |
|
| 45 |
if map == current[0:len(map)]: |
| 46 |
return 1 |
| 47 |
|
| 48 |
return 0 |
| 49 |
|
| 50 |
def handle_sell(): |
| 51 |
if not sell_is_restricted(): |
| 52 |
return |
| 53 |
|
| 54 |
guard = None |
| 55 |
|
| 56 |
map = Crossfire.WhoIsActivator().Map |
| 57 |
for h in range(0, map.Height): |
| 58 |
for w in range(0, map.Width): |
| 59 |
top = map.ObjectAt(w, h) |
| 60 |
while top != None: |
| 61 |
if top.Type == 69: |
| 62 |
count = random.randint(2, 8) |
| 63 |
while count > 0: |
| 64 |
guard = Crossfire.CreateObjectByName("guard") |
| 65 |
guard.StandStill = 0 |
| 66 |
guard.Unaggressive = 0 |
| 67 |
map.InsertAround(guard, w, h) |
| 68 |
count = count - 1 |
| 69 |
break |
| 70 |
top = top.Above |
| 71 |
|
| 72 |
if guard != None: |
| 73 |
Crossfire.WhoIsActivator().Message("You thief!") |
| 74 |
Crossfire.SetReturnValue(1) |
| 75 |
|
| 76 |
handle_sell() |