Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Python ➜ Python Plugins / File Handling

Python Plugins / File Handling

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by LupusFatalis   (154 posts)  Bio
Date Thu 16 Apr 2009 01:41 AM (UTC)
Message
Ok, so its been a couple years since I've played a mud/programmed/etc...

I just coded a script in python for the mud I'm playing. Works great, etc... I'd like to make it into a plugin, and I'd like the plugin to read/write variables to another file that is character specific. This way I can use the same plugin with every character, share it with other players, etc...

I have no idea where to start with this, and would appreciate any suggestions/assistance that could be offered to this end.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 16 Apr 2009 07:50 AM (UTC)
Message
See: http://www.gammon.com.au/mushclient/plugins/

There is a plugin wizard that converts your triggers etc. plus your script file into a plugin.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #2 on Thu 16 Apr 2009 02:45 PM (UTC)
Message
Heya, thanks Nick...

The Plugin Wizard is great, but in that case I need the plugin have two capacities that I can't seem to figure out.

1) Other plugins, etc... must be able to read the variable values.

2) The plugin must be able to create new variables within itself.

Are these doable?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Thu 16 Apr 2009 03:55 PM (UTC)

Amended on Thu 16 Apr 2009 03:57 PM (UTC) by Twisol

Message
1)
GetPluginVariable: http://www.gammon.com.au/scripts/doc.php?function=GetPluginVariable";
GetPluginVariableList: http://www.gammon.com.au/scripts/doc.php?function=GetPluginVariableList";

2)
SetVariable: http://www.gammon.com.au/scripts/doc.php?function=SetVariable";

Plugins save their state separately per world file as far as I'm aware; you don't need to do anything special if you use separate worlds for each character.

To Nick: Any chance you can write/have written a forum code for hyperlinks?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #4 on Thu 16 Apr 2009 05:46 PM (UTC)
Message
Alrighty, I made it into a plugin. I made an alias to check the variable listing function, that works great. The problem I am having is still that it doesn't store the variables from session to session.

It stores them when it is a script, as the world variables. But once I make it into a plugin it doesn't. Once I close the sessions, they are all lost, etc...

I'll post the things here so you can have a look at it, thanks again! All I really have in there is 2 triggers and a script for each of them. When I query the mud for my skills it gives me them in a descriptive manner, I need to track the actual numbers though.


<triggers>
  <trigger
   enabled="y"
   match="^(.*)\:(\s+)(Unskilled|A Tyro|A Novice|A Beginner|Poor|Not Very Good|Below Average|Average|Above Average|Able|Fair|Proficient|Good|Adroit|Very Good|Excellent|An Expert|Superb|A Master|Eminent|An Adept|Renowned|A High Master|Consummate|A Virtuoso|A Grand Master|Legendary)\.$"
   omit_from_output="y"
   regexp="y"
   script="SkillCheck"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^\* You think your (.*) skill has improved\. \*$"
   regexp="y"
   script="OnSkillGain"
   sequence="100"
  >
  </trigger>
</triggers>

<script>
<![CDATA[
def OnSkillGain(TriggerName, trig_line, wildcards):

	VariableName = ''.join([wildcards[x] for x in range(len(wildcards)-1)])
	VariableName = VariableName.replace(' ', '_').replace('\'', '').replace('-', '_').replace('#', '_')

	if not world.GetVariable(VariableName):
		VariableValue = 1
	else:
		VariableValue = int(world.GetVariable(VariableName)) + 1

	world.SetVariable(VariableName, str(VariableValue))
	world.note(VariableName + ': ' + str(VariableValue))


def SkillCheck(TriggerName, trig_line, wildcards):

	VariableStringName = wildcards[0]
	TempSpace = wildcards[1]
	VariableDesc = wildcards[2]

	VariableName = VariableStringName.replace(' ', '_').replace('\'', '').replace('-', '_').replace('#', '_')

	if not world.GetVariable(VariableName):
		VariableValue = 1
	else:
		VariableValue = int(world.GetVariable(VariableName))

	if VariableDesc == "Unskilled": 
		if VariableValue > 3: world.SetVariable(VariableName, '3')
		else: world.SetVariable(VariableName, '1')
	elif VariableDesc == "A Tyro": 
		if VariableValue < 3: world.SetVariable(VariableName, '4')
	elif VariableDesc == "A Novice": 
		if VariableValue < 9: world.SetVariable(VariableName, '10')
	elif VariableDesc == "A Beginner": 
		if VariableValue < 17: world.SetVariable(VariableName, '18')
	elif VariableDesc == "Poor": 
		if VariableValue < 29: world.SetVariable(VariableName, '30')
	elif VariableDesc == "Not Very Good": 
		if VariableValue < 49: world.SetVariable(VariableName, '50')
	elif VariableDesc == "Below Average": 
		if VariableValue < 69: world.SetVariable(VariableName, '70')
	elif VariableDesc == "Average": 
		if VariableValue < 89: world.SetVariable(VariableName, '90')
	elif VariableDesc == "Above Average": 
		if VariableValue < 109: world.SetVariable(VariableName, '110')
	elif VariableDesc == "Able": 
		if VariableValue < 134: world.SetVariable(VariableName, '135')
	elif VariableDesc == "Fair": 
		if VariableValue < 164: world.SetVariable(VariableName, '165')
	elif VariableDesc == "Proficient": 
		if VariableValue < 199: world.SetVariable(VariableName, '200')
	elif VariableDesc == "Good": 
		if VariableValue < 239: world.SetVariable(VariableName, '240')
	elif VariableDesc == "Adroit": 
		if VariableValue < 284: world.SetVariable(VariableName, '285')
	elif VariableDesc == "Very Good": 
		if VariableValue < 334: world.SetVariable(VariableName, '335')
	elif VariableDesc == "Excellent": 
		if VariableValue < 389: world.SetVariable(VariableName, '390')
	elif VariableDesc == "An Expert": 
		if VariableValue < 449: world.SetVariable(VariableName, '450')
	elif VariableDesc == "Superb": 
		if VariableValue < 514: world.SetVariable(VariableName, '515')
	elif VariableDesc == "A Master": 
		if VariableValue < 584: world.SetVariable(VariableName, '585')
	elif VariableDesc == "Eminent": 
		if VariableValue < 659: world.SetVariable(VariableName, '660')
	elif VariableDesc == "An Adept": 
		if VariableValue < 739: world.SetVariable(VariableName, '740')
	elif VariableDesc == "Renowned": 
		if VariableValue < 824: world.SetVariable(VariableName, '825')
	elif VariableDesc == "A High Master": 
		if VariableValue < 919: world.SetVariable(VariableName, '920')
	elif VariableDesc == "Consummate": 
		if VariableValue < 1049: world.SetVariable(VariableName, '1050')
	elif VariableDesc == "A Virtuoso": 
		if VariableValue < 1199: world.SetVariable(VariableName, '1200')
	elif VariableDesc == "A Grand Master": 
		if VariableValue < 1399: world.SetVariable(VariableName, '1400')
	elif VariableDesc == "Legendary": 
		if VariableValue <1700: world.SetVariable(VariableName, '1700')

	world.ColourTell ('#CCCCCC', '', VariableStringName + ':' + TempSpace + VariableDesc)
	world.ColourTell('#FFFFFF', '', ' [')
	world.ColourTell('#FF0000', '', world.GetVariable(VariableName))
	world.ColourNote('#FFFFFF', '', ']')


]]>
</script>


Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #5 on Thu 16 Apr 2009 05:55 PM (UTC)
Message
I'm pretty sure you just need to add the save_state="y" flag in the <plugin> XML tag near the top. MUSH automatically saves variables set via SetVariable as a statefile.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #6 on Thu 16 Apr 2009 06:44 PM (UTC)
Message
Wow, I feel like an idiot. I just saw that option in there. Of course after I changed it, I somehow messed something up and my default plugin and world directories gave me some trouble. But I'm up and running now, thank you.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #7 on Thu 16 Apr 2009 06:53 PM (UTC)

Amended on Thu 16 Apr 2009 06:55 PM (UTC) by Twisol

Message
Sure! Glad to help.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #8 on Thu 16 Apr 2009 07:16 PM (UTC)
Message
An update, everything seems to be working now. But just incase you thought of doing it... be careful if you want to just copy those .mcl files... trying to save time and copy characters I didn't realize I was shooting myself in the foot, as it also copied the id used for the save state variables ;)

On another note, do you happen to know if my fix of just generating new id's and copying them in is going to hold up, or will I have to redo everything?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #9 on Thu 16 Apr 2009 07:49 PM (UTC)
Message
Oh, you can just do File -> New World, which will pop up a dialog asking if you want to load a pre-existing world to base the new one off of. :) But I think your ID-changing thing should work OK, though that's mostly just an educated guess.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #10 on Fri 17 Apr 2009 11:00 AM (UTC)
Message
Quote:

Any chance you can write/have written a forum code for hyperlinks?


Without more sophisticated parsing of forum codes than I currently do, it could make a mess if you have the opening tag but not the closing one.

Quote:

But just incase you thought of doing it... be careful if you want to just copy those .mcl files... trying to save time and copy characters I didn't realize I was shooting myself in the foot, as it also copied the id used for the save state variables ;)


Just open a world file and do File -> Save As - that makes a copy and the copy will (should?) get a new ID automatically.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


27,433 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.