Crossfire Server, Trunk
takeitem.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # takeitem.py
3 # This is one of the files that can be called by an npc_dialog,
4 # The following code runs when a dialog has a post rule of 'takeitem'
5 # The syntax is ["takeitem", "itemtotake", "quantitytotake"]
6 # "quantitytotake" is optional, if it is missing, then 1 is assumed.
7 # if it is 0, then *all* instances of the item are taken.
8 # The player must have a sufficiant quantity of the item being taken
9 # This should normally be determined by doing an "item" check in the
10 # pre-block of the rule
11 # items are matched by item name, not arch name.
12 
18 
19 itemname = args[0]
20 if len(args) == 2:
21  quantity = int(args[1])
22 else:
23  quantity = 1
24 Crossfire.Log(Crossfire.LogDebug, "CFDialog: trying to take: %s of item %s from character %s" %(quantity, itemname, character.Name ))
25 if itemname == "money":
26  paid = character.PayAmount(int(quantity))
27  if paid == 0:
28  Crossfire.Log(Crossfire.LogError, "Tried to make player %s pay more than they had" %(character.Name))
29  character.Write("You give {} to {}".format(Crossfire.CostStringFromValue(int(quantity)), speaker.Name))
30 else:
31  inv = character.CheckInventory(itemname)
32  if inv:
33  if quantity == 0:
34  character.Write("You give {} {} to {}".format(inv.Quantity, inv.NameSingular if inv.Quantity == 1 else inv.NamePl, speaker.Name))
35  inv.Remove()
36  else:
37  character.Write("You give {} {} to {}".format(int(quantity), inv.NameSingular if quantity == 1 else inv.NamePl, speaker.Name))
38  status = CFItemBroker.Item(inv).subtract(int(quantity))
39  if status == 0:
40  Crossfire.Log(Crossfire.LogError, "Dialog script tried to remove more items than available from player %s" %(character.Name))
41  # we might have been wearing an item that was taken.
42  character.Fix()
43  else:
44  Crossfire.Log(Crossfire.LogError, "Dialog script tried to remove non-existant item from player %s" %(character.Name))
CFItemBroker.Item
Definition: CFItemBroker.py:15
make_face_from_files.int
int
Definition: make_face_from_files.py:32