1.
/********
Character saving example.
This demo uses Deadron's CharacterHandling library,
which automatically handles saving and loading player mobs.
Player mobs are saved when the player logs out.
This demo saves the player and their last location on the map.
The library is a part of BaseCamp, Deadron's game infrastructure system.
Full documentation for the library can be found by double-clicking
on Lib/Deadron.CharacterHandling, then viewing the characterhandling.dm file.
If you have questions or suggestions, please email ron@deadron.com.
BaseCamp: From here you can reach Everest!
***********/
// How many characters is a player allowed to have?
client/base_num_characters_allowed = 3
/***
Turning off automatic features
------------------------------
By default, the CharacterHandling library automatically loads and saves characters
for you. There are settings that will turn off the automatic behavior if you wish.
client/base_autoload_character = 0
----------------------------------
This turns off auto-loading when a player logs in.
Whenever you do want the player to load a character, call that player's
client.base_ChooseCharacter() function.
client/base_autosave_character = 0
----------------------------------
This turns off auto-saving when a player logs out.
If you turn off auto-saving or also want to save at other times, use
the player's client.base_SaveMob() function, as shown in the save_me()
verb below.
client/base_autodelete_mob = 0
------------------------------
This stops the library from deleting the player's mob after they log out.
Without this, the mob will stay in the game until you delete it yourself.
mob/base_save_location = 0
------------------------------
This turns off the location saving, which means you will need to manually
place the mob after it is read in from the savefile.
Uncomment one or more of the following lines to turn off a feature.
***/
// client/base_autoload_character = 0
// client/base_autosave_character = 0
// client/base_autodelete_mob = 0
// mob/base_save_location = 0
/***
Specifying the mob type
-----------------------
When a new character needs to be created, the CharacterHandling library
creates a mob of type world.mob and logs the player into it.
You can choose any mob type and anything you want with this mob.
This example sets the default mob to /mob/creating_character.
When the player is logged into the creating_character class, they are asked
questions about their character's attributes. When they are done, a new
mob is created with those attributes and the player is logged into it.
This is just one possible way you could do things. It's provided as an example.
None of it is required for the library to work.
***/
world/mob = /mob/creating_character
/***********
Example character creation
--------------------------
The code below gives an example of setting up a character.
This is just to give you ideas for how you can do it yourself.
************/
mob/creating_character
base_save_allowed = 0 // If player quits before choosing, don't want to save this mob.
Login()
// Spawn here to avoid problems with calling prompts during login.
spawn()
src.CreateCharacter()
proc/CreateCharacter()
// In this case, the code creates a /mob/human or /mob/ogre with the specified attributes.
// Get the character information from them. (You would probably want to do with this a browser page.)
var/prompt_title = "New Character"
var/help_text = "What will people call u by"
var/default_value = key
var/char_name = input(src, help_text, prompt_title, default_value) as null|text
var/rank = "Trainer"
if (!char_name)
// Guess they don't want to create a new character after all, so send them to choose a character.
client.base_ChooseCharacter()
return
// Make sure there isn't already a character named that.
// Character names are stored as ckey, so get the ckey version of the name.
var/ckey_name = ckey(char_name)
var/list/characters = client.base_CharacterNames()
if (characters.Find(ckey_name))
alert("You already have a character named that! Please choose another name.")
src.CreateCharacter()
return
var/list/classes = list("Male", "Female")
help_text = "Which gender are you?"
default_value = "Cop"
var/char_class = input(src, help_text, prompt_title, default_value) in classes
// Okay we have enough information, so it's time to create the character and switch the player to it.
var/mob/new_mob
switch(char_class)
if ("Female")
new_mob = new /mob/female1()
if ("Male")
new_mob = new /mob/male1()
// Set the attributes.
new_mob.name = char_name
new_mob.rank = rank
// Now switch the player client over to the new mob and delete myself since I'm no longer needed.
src.client.mob = new_mob
var/turf/first_location = locate(171,52,1)
new_mob.Move(first_location)
del(src)
mob
verb
Save()
// This demonstrates verb saving and how to manually save the mob whenever you want..
// This proc gets added and saved as a verb only if add_verb is called by the player.
src.client.base_SaveMob()
src << "\red You have been saved."
mob/male1
icon = 'Pokemon XD Icons.dmi'
icon_state = "Brendan"
mob/female1
icon = 'Pokemon XD Icons.dmi'
icon_state = "Yellow"
2.
/********
Character saving example.
This demo uses Deadron's CharacterHandling library,
which automatically handles saving and loading player mobs.
Player mobs are saved when the player logs out.
This demo saves the player and their last location on the map.
The library is a part of BaseCamp, Deadron's game infrastructure system.
Full documentation for the library can be found by double-clicking
on Lib/Deadron.CharacterHandling, then viewing the characterhandling.dm file.
If you have questions or suggestions, please email ron@deadron.com.
BaseCamp: From here you can reach Everest!
***********/
// How many characters is a player allowed to have?
client/base_num_characters_allowed = 3
/***
Turning off automatic features
------------------------------
By default, the CharacterHandling library automatically loads and saves characters
for you. There are settings that will turn off the automatic behavior if you wish.
client/base_autoload_character = 0
----------------------------------
This turns off auto-loading when a player logs in.
Whenever you do want the player to load a character, call that player's
client.base_ChooseCharacter() function.
client/base_autosave_character = 0
----------------------------------
This turns off auto-saving when a player logs out.
If you turn off auto-saving or also want to save at other times, use
the player's client.base_SaveMob() function, as shown in the save_me()
verb below.
client/base_autodelete_mob = 0
------------------------------
This stops the library from deleting the player's mob after they log out.
Without this, the mob will stay in the game until you delete it yourself.
mob/base_save_location = 0
------------------------------
This turns off the location saving, which means you will need to manually
place the mob after it is read in from the savefile.
Uncomment one or more of the following lines to turn off a feature.
***/
// client/base_autoload_character = 0
// client/base_autosave_character = 0
// client/base_autodelete_mob = 0
// mob/base_save_location = 0
/***
Specifying the mob type
-----------------------
When a new character needs to be created, the CharacterHandling library
creates a mob of type world.mob and logs the player into it.
You can choose any mob type and anything you want with this mob.
This example sets the default mob to /mob/creating_character.
When the player is logged into the creating_character class, they are asked
questions about their character's attributes. When they are done, a new
mob is created with those attributes and the player is logged into it.
This is just one possible way you could do things. It's provided as an example.
None of it is required for the library to work.
***/
world/mob = /mob/creating_character
/***********
Example character creation
--------------------------
The code below gives an example of setting up a character.
This is just to give you ideas for how you can do it yourself.
************/
mob/creating_character
base_save_allowed = 0 // If player quits before choosing, don't want to save this mob.
Login()
// Spawn here to avoid problems with calling prompts during login.
spawn()
src.CreateCharacter()
proc/CreateCharacter()
// In this case, the code creates a /mob/human or /mob/ogre with the specified attributes.
// Get the character information from them. (You would probably want to do with this a browser page.)
var/prompt_title = "New Character"
var/help_text = "What will people call u by"
var/default_value = key
var/char_name = input(src, help_text, prompt_title, default_value) as null|text
var/rank = "Trainer"
if (!char_name)
// Guess they don't want to create a new character after all, so send them to choose a character.
client.base_ChooseCharacter()
return
// Make sure there isn't already a character named that.
// Character names are stored as ckey, so get the ckey version of the name.
var/ckey_name = ckey(char_name)
var/list/characters = client.base_CharacterNames()
if (characters.Find(ckey_name))
alert("You already have a character named that! Please choose another name.")
src.CreateCharacter()
return
var/list/classes = list("Male", "Female")
help_text = "Which gender are you?"
default_value = "Cop"
var/char_class = input(src, help_text, prompt_title, default_value) in classes
// Okay we have enough information, so it's time to create the character and switch the player to it.
var/mob/new_mob
switch(char_class)
if ("Female")
new_mob = new /mob/female1()
if ("Male")
new_mob = new /mob/male1()
// Set the attributes.
new_mob.name = char_name
new_mob.rank = rank
// Now switch the player client over to the new mob and delete myself since I'm no longer needed.
src.client.mob = new_mob
var/turf/first_location = locate(171,52,1)
new_mob.Move(first_location)
del(src)
mob
verb
Save()
// This demonstrates verb saving and how to manually save the mob whenever you want..
// This proc gets added and saved as a verb only if add_verb is called by the player.
src.client.base_SaveMob()
src << "\red You have been saved."
mob/male1
icon = 'Pokemon XD Icons.dmi'
icon_state = "Brendan"
mob/female1
icon = 'Pokemon XD Icons.dmi'
icon_state = "Yellow"
3.
#include "implementation.dm"
/////////////////////////////////////////////
// WELCOME TO BASECAMP: CHARACTER HANDLING //
/////////////////////////////////////////////
/*
For a fully working example using this library, download:
byond://Deadron.SimpleSaving
or
byond://Deadron.CharacterSaving
Everything you need to read about the library is in this file.
You don't need to look at anything else in the library, unless
you have a good understanding of BYOND and want to see how it
works.
*/
/****
USING THE LIBRARY
To use the library, you only need to include it, with this line:
#include <deadron/characterhandling>
You don't need to copy/paste any library code or anything.
By including it, it will automatically add itself to your game.
You don't need to do anything else special to use the library.
The only requirement is the same as for any BYOND game:
Specify the mob type for new mobs in world.mob, as discussed
in detail below.
What it does
------------
When a player logs in, the library checks to see if they have
any characters saved. If they do, and if you only allow for
one character, then the player is immediately logged into that
character and all their attributes and inventory are restored.
When the player logs out, their character is automatically saved.
The character is saved based on its name.
Choosing a character
--------------------
If you allow for multiple characters, then the library lets the
player choose which character they want to play, or to create
or delete a character. When the player chooses a character,
they are logged into it. By default he library handles the choosing
process automatically. You don't need to do anything.
You can customize the menus used for choosing and deleting characters,
as discussed below.
If you want to change the default behavior, look at the client
variables discussed further down in this file.
Creating a character
--------------------
If a character needs to be created, then the library creates
a mob of type world.mob and logs the character into it.
Whatever you specify as world.mob is what is created.
For example, if this is how world.mob is set:
world
mob = /mob/new_character
Then when a brand new character is created, it will be of type
/mob/new_character. You can make this any class you want, and
can do anything you want with the class. The library just creates
a mob of that class and logs the player into it.
If you want the player to specify attributes when their character
is created, then you might have a mob class designed just to
ask them what kind of character they want. See the CharacterSaving
demo for a complete example of this.
***/
/*
Setting the number of characters
--------------------------------
You can specify how many characters a player is allowed to have.
using the client variable, base_num_characters_allowed.
If you set it to 1, then players will be immediately logged into
their one character. If you allow more than one, then players will
automatically be given a choice of which character to they want to play,
as well as options for creating and deleting characters.
*/
client/base_num_characters_allowed = 1
/*
Automatically loading/saving player characters
---------------------------------------
By default, CharacterHandling will automatically load the player's
character on login, and save a player's character and delete the mob
on logout. If you don't want one or more of these to happen by default,
then set the appropriate "auto" variable(s) to 0.
If you don't want the character autoloaded, call the player's
client.base_ChooseCharacter() when you DO want it loaded.
*/
client/base_autoload_character = 1
client/base_autosave_character = 1
client/base_autodelete_mob = 1
/*
Saving verbs
------------
BYOND does not save verbs, but the library takes care of this for you
by default. If you don't want verbs saved, then set this to 0 in
your code.
*/
client/base_save_verbs = 1
client/base_ChooseCharacter()
/*
Choosing a character
--------------------
This function is called automatically on login if
client.base_autoload_character is 1. If only one
character is allowed, it immediately logs the player
into a character. If multiple characters are allowed,
it gives the player a menu to create/choose/delete
characters.
*/
return ..()
mob/BaseCamp/ChoosingCharacter
ChooseCharacterMenu(list/menu)
/*
Customizing Choose menu
-----------------------
This function receives the list of menu items for choosing
a character. It can display these any way it wishes,
then send the player's choice to the ChooseCharacterResult()
proc. The default behavior uses an ugly input() list.
*/
return ..()
DeleteCharacterMenu(list/menu)
/*
Customizing Delete menu
-----------------------
This function receives the list of menu items for deleting
a character. It can display these any way it wishes,
then send the player's choice to the DeleteCharacterResult()
proc. The default behavior uses an ugly input() list.
*/
return ..()
client/base_SaveMob()
/*
Forcing the character to be saved
---------------------------------
Characters are saved automatically when the player logs out.
If you want them saved at other times too, just call this
client function for the mob when you want it saved:
*/
return ..()
mob/BaseCamp/FirstTimePlayer
FirstTimePlayer()
/*
Handling first time players
---------------------------
If you want to do something special the first time a player ever logs
into your game, you can do so by putting code in the FirstTimePlayer
class, FirstTimePlayer() proc. This is only the first time EVER that
they login...it is not called everytime they login.
You can use this to charge the player, or get their email address,
or give them special help or whatever.
If you don't want to use this, then don't do anything. By default,
nothing will happen. This is ONLY called the very first time a
player logs in, so it's not useful for things that check everytime
the player logs in.
*/
return 1
/*
If you don't want a mob to be saved, set
mob/base_save_allowed to 0.
*/
mob/base_save_allowed = 1
/*
If you don't want the mob's location to be saved and restored,
set mob/base_save_location to 0.
*/
mob/base_save_location = 1
mob/base_InitFromSavefile()
/*
Initializing from savefile
--------------------------
Sometimes you have special checks you need to do or things you need
to add when a character is read in from the savefile. If so,
you can do them in this mob function:
By default nothing happens. This is just here in case you need it.
*/
return
Problem description:
So, I got this without errors. And when I run the game, I choose the option Create New Charachter, then it asks for my name, I put my name in. And then you normally need to choose your gender, but after the name-choosing part, there doens't popup a new window. And it just stays like that. But before it did work out o.o' and I can't find the problem.
Sincerely,
Raimo