Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Somnium
Beginner


Joined: 15 Nov 2008
Posts: 10

PostPosted: Thu Apr 04, 2013 11:32 am   

zMUD scripts for CMUD
 
Hi.
I'm trying to get a zmud script to work with CMUD.
Despite my effort trying to re-code it I won't get it to work.

Anybody have any ideas or can tell me why I get this error message.

"error parsing command" (source not available for runtime errors)

Thx in advance.



#CLASS System
#ALIAS atconnect {init}
#CLASS {MumeClock}
#TRIGGER {The current time is %1:%2 %3.} {#mss {ClockSet %1, %2, ~"%3~"}}
#ALIAS init {#SS "VBScript"}
#ALIAS ti {#mss {ClockShowTime "Client",~"~"}}
#ALIAS sti {#mss {ClockShowTime "Say",~"~"}}
#ALIAS tti {#mss {ClockShowTime "Tell", ~"%1~"}}
#ALIAS nti {#mss {ClockShowTime "Narrate",~"~"}}
#CLASS 0
#EDIT init

'****************************************
'CLOCK SCRIPT by Eloril
'Works by taking the time difference
'from when the clock is set to when it is
'checked and converting that difference
'to the standard time format.
'
'Examine a clock to set the time, or use
'ClockSet(hour, min, am/pm) to set the time.
'
'ti - Displays current time.
'sti - Says the time.
'tti - Tells someone the time.
'nti - Narrates the time.
'
'Thanks to Rashnak for some perfect
'examples of VBScript and commenting
'conventions.
'****************************************

Dim tMume, tReal, tHour, tAp, tSet, ClockIsSet

Const Client = 0, Say = 1, Tell = 2, Narrate = 3

tSet = 0
ClockIsSet = False

'****************************************
'CLOCK SCRIPT: ClockSet(hour, min, ap)
'Sets the clock.
'****************************************
Sub ClockSet(hour, min, ap)

Dim time

If ClockIsSet Then Exit Sub

'Convert current mume time to seconds
tMume = TimeToSec(hour, min, ap)

'Get current real time in seconds
tReal = Int(Timer)

'Replace mume time message
'jmc.DropEvent
time = SecToTime(tMume)
zmudcommand 175, array("You set your watch to " & time & ".")

ClockIsSet = True

End Sub

'****************************************
'CLOCK SCRIPT: ClockShowTime()
'Shows the current mume time.
'****************************************
Sub ClockShowTime(mode, player)

Dim time

'A little Easter egg
If not ClockIsSet Then
If tSet = 0 Then zmudcommand 175, array(VBCrLf & "Your watch doesn't seem to be set.")
If tSet = 1 Then zmudcommand 175, array(VBCrLf & "Your watch mockingly flashes 12:00 am.")
If tSet = 2 Then zmudcommand 175, array(VBCrLf & "You rattle your watch a bit, but to no avail.")
tSet = tSet + 1
If tSet > 2 Then tSet = 0
Exit Sub
End If

'When telling someone the time, check if player specified
If mode = Tell and player = "" Then
zmudcommand 175, array(VBCrLf & "To whom shall you tell the time?")
Exit Sub
End If

'Convert and show the time
time = SecToTime(ClockGetDif)
If mode = Client Then zmudcommand 175, array(VBCrLf & "According to your watch it's " & time & ".")
If mode = Say Then zmudcommand 178, array("emote quickly glances down and says 'It's " & time & ".'")
If mode = Tell Then zmudcommand 178, array("tell " & player & " The current time is " & time & ".")
If mode = Narrate Then zmudcommand 178, array("narrate The current time is " & time & ".")

End Sub

'****************************************
'CLOCK SCRIPT: ClockGetDif()
'Calculates difference in seconds from
'the time the clock was set to now.
'****************************************
Function ClockGetDif()

Dim tDif, tCur

'Get elapsed time in seconds
tDif = Int(Timer) - tReal

'If real time is past midnight...
If tDif < 0 Then
tDif = (86400 - tReal) + Int(Timer)
End If

'Add difference to mume time to get current time
tCur = tMume + tDif

'Make sure the difference is within 24 minutes
While tCur > 1440
tCur = tCur - 1440
Wend

ClockGetDif = tCur

End Function

'****************************************
'CLOCK SCRIPT: TimeToSec(hour, min, ap)
'Converts hours and minutes to seconds.
'****************************************
Function TimeToSec(hour, min, ap)

Dim sec

sec = (hour * 60) + min
If ap = "am" and hour = 12 Then sec = sec - 720
If ap = "pm" and hour < 12 Then sec = sec + 720

TimeToSec = sec

End Function

'****************************************
'CLOCK SCRIPT: SecToTime(sec)
'Converts seconds to hours and minutes.
'The result is returned as a string.
'****************************************
Function SecToTime(sec)

Dim time, hour, min, ap

'Get hours and minutes
hour = sec \ 60
min = sec Mod 60

'Determine am or pm
If hour <= 11 Then ap = "am"
If hour >= 12 Then ap = "pm"
If hour = 24 Then ap = "am"

If hour = 0 Then hour = 12
If hour > 12 Then hour = hour - 12

'Put together hours, minutes, and am/pm
If min >= 10 Then
time = hour & ":" & min & " " & ap
Else
time = hour & ":0" & min & " " & ap
End If

SecToTime = time

End Function
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net