ID:139837
 
Code:
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

Re-Download the library. Read the guide. You probably accidentally edited a portion of his code in a way which no errors were compiled.
In response to Darkjohn66
I redownloaded the library. Copy-pasted to be sure and it's still the same thing.
In response to Raimo
You are not meant to copy-paste or edit libraries in any way. To include a library, check the box next to it under the Lib folder in Dream Maker. To USE a library, read the documentation that comes with it.
I did everything you wanted. Still the same problem.
In response to Raimo
-bump-
In response to Garthor
Well, it worked before so I don't know what is wrong. Can someone help me please?
its because your switching mobs here :
src.client.mob = new_mob


and since its a mob proc then the mob you switch to is not the one the proc applies to now is it? I suggest you make it a client proc instead. if you cant do that then i suggest you read this and look through this when you don't understand certain things.
In response to Masschaos100
I know you want me to read the guides. But I already did Zilal's without any errors. Can you give me a bit more information on this? Since I'm still learning.
Thanks in advance.

Sincerely,
Raimo.
In response to Raimo
well this is what i meant:

mob
creating_character
Login()
..()
client.CreateCharacter()

client//this time instead of the proc using the current mob its going directly to the client
//so even if you switch mobs it will continue
proc
CreateCharacter()
var
prompt_title="New Character"//most things are going to remain the same
help_text="What will people call u by"
default_value = key
char_name = input(src, help_text, prompt_title, default_value)
var/rank = "Trainer"

if(!char_name)
//some things will have to be changed, since the client doesn't have a client var
//we remove the (client.) that was before the base_ChooseCharacter.
base_ChooseCharacter()
return
var/ckey_name=ckey(char_name)
var/list/characters=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="Male"
var/char_class = input(src, help_text, prompt_title, default_value) in classes

var/mob/new_mob
switch(char_class)
if ("Female")
new_mob = new /mob/female1()
if ("Male")
new_mob = new /mob/male1()
new_mob.name=char_name
new_mob.rank = rank
//once again we remove client, and since this is not a mob we also remove the src
var/mob/old_mob=mob//since were switching mobs and we want to delete ones that
//aren't being used
mob = new_mob
var/turf/first_location=locate(171,52,1)
mob.Move(first_location)
del(old_mob)
In response to Masschaos100
Thank you, I'm getting a bit farther then last time.
I'm getting my staff tab now, which I didn't get before. And I can see the start point of the map now, and I can walk there. But the 'gender-choosing' still doesn't popup.
In response to Garthor
No but copy and pasting a library is a good idea if you're going to be fiddling around with it. Personally I do the same because I never use libraries the way they come. every time I loo at a library I see a way to improve it and, as such I do. The thing is, it seems he's done this and has forgotten the modifications that were made, as a result it's caused this issue. Either that or he has another bit of code somewhere fumbling this whole process up, if that's the case we pretty much can't help.
In response to Bravo1
Well, what are the options of codes that can mess this up?
In response to Raimo
Problem solved. Thanks everyone for the effort it took to help me out. I appreciate it.

Sincerely,
Raimo
In response to Bravo1
Bravo1 wrote:
No but copy and pasting a library is a good idea if you're going to be fiddling around with it.

No. If you need to modify a library, then that library does not suit your purposes and therefore should not be used.
In response to Garthor
If you need to modify a library then do so. It's a good idea if it's going to save you a lot of time and effort but you still site the sources.

I don't know about you, but if I get a mustang and amp it up with a different engine, it's more useful than trying to build a car yourself. So long as you don't try to say "I made this car without any help." So long as you give credit where credit is due, taking a library and modifying it to your needs is a lot better than trying to find "the perfect library" and/or building it all from scratch.