Crossfire Server, Trunk
ship.py
Go to the documentation of this file.
1 # ship.py -- sailing around the world takes time
2 # Created by: Kevin Zheng <kevinz5000@gmail.com>
3 #
4 # This script should be used in specially designed ship maps. Please see the
5 # ship from Scorn to Santo Dominion for a working example. Note that connection
6 # 10 and 11 must be used for the entrance and exit gates, respectively.
7 import Crossfire
8 
9 player = Crossfire.WhoIsActivator()
10 whoami = Crossfire.WhoAmI()
11 sailtime = 15
12 
13 # Get a previously set value, otherwise return zero.
14 def getValue(key):
15  value = Crossfire.WhoAmI().ReadKey(key)
16 
17  if (len(value) != 0):
18  return value
19  else:
20  return 0
21 
22 # Set a value.
23 def setValue(key, value):
24  Crossfire.WhoAmI().WriteKey(key, str(value), 1)
25 
26 # Check ship state.
27 def getState():
28  return int(getValue("ship_state"))
29 
30 # Set ship state.
31 def setState(state):
32  setValue("ship_state", state)
33 
34 # Check if the ship is already sailing.
35 def isSailing():
36  if getState() != 0:
37  return 1
38  else:
39  return 0
40 
41 # Set a timer for the specified amount of time.
42 def setTimer(time):
43  setValue("ship_timer", str(whoami.CreateTimer(time, 1)))
44 
45 # Clear the previously set timer.
46 def clearTimer():
47  Crossfire.DestroyTimer(int(getValue("ship_timer")))
48 
49 # Start sailing if the ship isn't already sailing.
50 if Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.APPLY:
51  if isSailing() == 0:
52  setState(1)
53 
54  # Close the entrance and notify the players onboard.
55  whoami.Map.TriggerConnected(10, 1)
56  whoami.Map.Print("\"Ahoy, the ship is ready to set sail!\" You feel the ship beginning to move.")
57  setTimer(sailtime)
58  else:
59  player.Message("The ship has already set sail, be patient!")
60 
61 # Handle the timer event based on what state the ship is in.
62 elif Crossfire.WhatIsEvent().Subtype == Crossfire.EventType.TIMER:
63  if getState() == 1:
64  # Open the exit and tell players that they've arrived.
65  setState(2)
66  whoami.Map.TriggerConnected(11, 1)
67  whoami.Map.Print("The ship has arrived at its destination.")
68 
69  # Clear and reset timer for another 15 seconds.
70  clearTimer()
71  setTimer(15)
72  elif getState() == 2:
73  # Reset the ship.
74  clearTimer()
75  whoami.Map.TriggerConnected(10, 0)
76  whoami.Map.TriggerConnected(11, 0)
77  whoami.Map.Print("The ship is ready to board.")
78  setState(0)
ship.isSailing
def isSailing()
Definition: ship.py:35
ship.setValue
def setValue(key, value)
Definition: ship.py:23
ship.setState
def setState(state)
Definition: ship.py:31
ship.getValue
def getValue(key)
Definition: ship.py:14
ship.getState
def getState()
Definition: ship.py:27
make_face_from_files.str
str
Definition: make_face_from_files.py:30
ship.setTimer
def setTimer(time)
Definition: ship.py:42
make_face_from_files.int
int
Definition: make_face_from_files.py:32
ship.clearTimer
def clearTimer()
Definition: ship.py:46