Crossfire Server, Trunk
hall_of_fame.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # hall_of_fame.py - A script handling 'hall of fame' lists
3 #
4 # Copyright (C) 2010-2012 The Crossfire Development Team
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 is intended to be bound to event objects, generally the apply one.
22 # If the item this script is bound to is a SIGN, then it will display
23 # its list of players, preceded by the own item's message (as header).
24 # For any other item, the player is added to the list, with her title. If the event
25 # object itself has a message, it will be displayed to the player if she is added
26 # to the list.
27 #
28 # The script's parameters is the internal name of the quest.
29 
30 import Crossfire
31 from CFDataFile import CFData
32 
33 player = Crossfire.WhoIsActivator()
34 me = Crossfire.WhoAmI()
35 event = Crossfire.WhatIsEvent()
36 name = 'hall_of_fame_' + Crossfire.ScriptParameters()
37 
38 header = [ 'title' ]
39 file = CFData(name, header)
40 
41 if me.Type == Crossfire.Type.SIGN:
42  message = me.Message + "\n"
43  keys = file.get_keys()
44  for name in keys:
45  message = message + name + " " + file.get_record(name)['title'] + "\n"
46  if len(keys) == 0:
47  message = message + "No one is recorded, will you attempt to be the first?"
48  player.Write(message)
49  Crossfire.SetReturnValue(1)
50 else:
51  record = file.get_record(player.Name)
52  if record == 0:
53  file.put_record({ '#' : player.Name, 'title' : player.Title })
54  if event.Message != None:
55  player.Write(event.Message)
56 
57 
CFDataFile.CFData
Definition: CFDataFile.py:94