PDA

View Full Version : [Essentials script] Password Gift


FlipelyFlip
March 4th, 2012, 06:39 AM
PasswordGift v1.0
by FlipelyFlip


heyey,
I know there are some scripts out there doing the same like mine, but with mine you have a lot more power! You can set Items and Pokemons as gifts. It's easy used and you don't need a lot of scripting knowledge to use this snippet.

What does this Snippet do?
this little snippet allows you to create a Password Gift part.
You enter a password and if the password is correct, you will
gain a pre-defined item.

How to use it?
To call the script you have only use the call-script event code
and enter this:

Scene_PasswordGift.new(minlength, maxlength)

minlength = minimum of letters or symbols to enter (by default it's 1)
maxlength = maximum of letters or symbols to enter (by default it's 8)

How to setup?
To setup a password, it's important that you know, that you have to
put a PBItems:: before the item name or a PBSpecies:: before a pokemon name!
All items and Pokemons you will find in your PBS folder.

How to setup a Item-Password:

"password" => [PBItems::Item_Name, Switch_ID, pokemon=false]

"password" = "Password" which you have to choose. Don't forget this friends: ""
PBItems::Item_Name = Sets the Item
Switch_ID = Switch ID if you want. to set this password to nil for endless use.
pokemon=false = Items are no pokemons, so this is set to false. It's very important that this is set to false for items (Causes Errors)

How to setup a Pokemon-Password:

"password" => [PBSpecies::Pokemon_Name, Switch_ID, pokemon=true, Level]
"password" = "Password" which you have to choose. Don't forget this friends: ""
PBSpecies::Pokemon_Name = Sets the Pokemon
Switch_ID = Switch ID if you want. to set this password to nil for endless use.
pokemon=true = defines if it's a pokemon or not. So you're setting up a pokemon, this has to be true!
Level = Level of the pokemon when gained!

The Script itself
=begin
PasswordGift v1.0
by FlipelyFlip

heyey,
this little snippet allows you to create a Password Gift part.
You enter a password and if the password is correct, you will
gain a pre-defined item.

To call the script you have only use the call-script event code
and enter this:

Scene_Gift.new(minlength, maxlength)

minlength = minimum of letters or symbols to enter (default 1)
maxlength = maximum of letters or symbols to enter (default 8)

To setup a password, it's important that you know, that you have to
put a PBItems:: before the item name or a PBSpecies:: before a pokemon name!
All items and Pokemons you will find in your PBS folder.

that's all you have to know in this snippet (:
=end

#=============================================================================
# Password Module
#-----------------------------------------------------------------------------
# Here you can define the Items you will gain for the different passwords
#=============================================================================
module Password
# this is the hash to define
Gifts = { # <-- do not remove!!
# "password" => [PBItems::Item_Name, Switch_ID, pokemon=false]
# "password" => [PBSpecies::Pokemon_Name, Switch_ID, pokemon=true, Level]
"PASSWORD" => [PBItems::POTION, 198, false],
# important!! if you add more passwords don't
# forget the Komma until you reacht the last line
"FUEL" => [PBItems::ETHER, 199, false, nil],
"CLONE" => [PBSpecies::MEW, 200, true, 5]
} # <-- do not remove!!
end
#============================================================================#
# !!EDIT ONLY IF YOU KNOW WHAT YOU DO!! #
#============================================================================#

#=============================================================================
# Scene_PasswordGift
#-----------------------------------------------------------------------------
# The core of the whole script
# minlength = minimum of letters or symbols to enter
# maxlength = maximum of letters or symbols to enter
#=============================================================================
class Scene_PasswordGift
#---------------------------------------------------------------------------
# initialize
#---------------------------------------------------------------------------
def initialize(minlength = 1, maxlength = 8)
enterPassword(minlength, maxlength)
end

#---------------------------------------------------------------------------
# getPassword
#---------------------------------------------------------------------------
def enterPassword(minlength, maxlength)
password = pbEnterText(_INTL("Enter the password"),minlength,maxlength)
if password.scan(/\r/) == ["\r"]
slicing = password.size - 1
password.slice!(slicing)
end
if Password::Gifts.include?(password)
if $game_switches[Password::Gifts[password][1]] == true
Kernel.pbMessage(_INTL("Password already used"))
else
Kernel.pbMessage(_INTL("Correct password!"))
if Password::Gifts[password][2] == true
Kernel.pbAddPokemon(Password::Gifts[password][0], Password::Gifts[password][3])
else
Kernel.pbReceiveItem(Password::Gifts[password][0])
end
if Password::Gifts[password][1] != nil
$game_switches[Password::Gifts[password][1]] = true
end
end
else
Kernel.pbMessage(_INTL("Incorrect password."))
end
end
end


Planed Features:


amount of use. Means: You can use the password for the potion 3 times but the password for a Mew only once.
if you have some ideas just say (:

that's all you have to know in this snippet (:
I hope you like it^^"

~Flip

Ho-oh 112
March 4th, 2012, 07:30 AM
Well, this is great as a starter but, for some better scripts you should atleast let people "compile" items/pokemon/eggs without needing pre-defined passwords(a password generator)

Pharetra
March 4th, 2012, 07:44 AM
Seems like a great script to me, I have yet to test it but this definitely looks promising. Really like the idea of passwords by the way. I do have a suggestion, how about adding Online support? I'd like to be able to add gifts after my game has been released.

seeker
March 4th, 2012, 07:55 AM
This is pretty awesome to be frank. I would like to see online support a bit later, this would be really useful for events and so on. Good work!

help-14
March 4th, 2012, 08:23 AM
Well, this is great as a starter but, for some better scripts you should atleast let people "compile" items/pokemon/eggs without needing pre-defined passwords(a password generator)

That's a really good idea and i think it is possible. First you need a key so no one will able to fake it:

$SecretKey = "some crazy text"

Encrypt method will be something like this:

def Encrypt(pokemon,switch)
return Zlib::Inflate.inflate(Zlib::Inflate.inflate(pokemon+"|"+switch)+$SecretKey)
end

And Decrypt mothod

def Decrypt(pass)
arg = (Zlib::Deflate.deflate(Zlib::Deflate.deflate(pass).gsub($SecretKey, ""))).split("|")
@pokemon = arg[0]
@switch = arg[1]
#Do something
end

Ho-oh 112
March 4th, 2012, 08:25 AM
That's a really good idea and i think it is possible. First you need a key so no one will able to fake it:

$SecretKey = "some crazy text"

Encrypt method will be something like this:

def Encrypt(pokemon,switch)
return Zlib::Inflate.inflate(Zlib::Inflate.inflate(pokemon+"|"+switch)+$SecretKey)
end

And Decrypt mothod

def Decrypt(pass)
arg = (Zlib::Deflate.deflate(Zlib::Deflate.deflate(pass).gsub($SecretKey, ""))).split("|")
@pokemon = arg[0]
@switch = arg[1]
#Do something
end


yeah I knew that, but I was giving him a challenge of finding a method to do so....
(another method is the .pack/.unpack function)

help-14
March 4th, 2012, 08:33 AM
yeah I knew that, but I was giving him a challenge of finding a method to do so....
(another method is the .pack/.unpack function)

Oh i don't know that method, silly me :embarrass:

Awkward Squirtle
March 4th, 2012, 09:04 AM
FlipelyFlip: Nice script. Tip: you can use the chomp method to remove possible whitespace from the end of a string (instead of your current slice shenanigans). I like the way you've set up the switches - you could make a set of mutually exclusive passwords by giving them the same switch ID (such as a choice between Bulbasaur, Charmander and Squirtle)!

help-14: Deflate isn't an encryption algorithm, it's a data compression algorithm. Adding a 'secret key' on the end won't make it secure. You're not even checking the secret key after decompression - I can just make a message with an empty 'secret key' and your code will decrypt it as normal (try it). And even if you do check the secret key, I can find the game's actual secret key by decompressing the code and taking the bit off the end - then, I can fake a message and append the key before compressing, and the game will be none the wiser. Pack/unpack similarly doesn't do any encryption - it just converts an array into a string and vice-versa using a predefined format.

As an easier alternative, try the Marshal module - it provides data serialisation, meaning you can pack an actual Pokémon's data into a string with a single line of code. The default implementation is pretty inefficient, but I think there's a method you can override if you want to pack the data into a shorter string.

Pokémon Raptor uses deflate and a conversion to base-64 in its system - it's not encrypted in any way whatsoever. It's easy to fake a Mystery Gift/team code. But the Mystery Gift code there is loaded from a URL defined in the scripts, so you'd have to modify and redistribute the scripts file to change the loaded gift (as I did). And team codes don't really do anything in-game, so faking them doesn't really matter.

You should still have some sort of validation to prevent game crashes from malformed codes - for example, this guy's code (http://www.pokecommunity.com/showpost.php?p=7062808&postcount=4976) is invalid, but the game handles it gracefully (when constructing the team's Pokémon, an invalid species exception is thrown; the script catches it, and displays a message to the screen saying so). FlipelyFlip's code doesn't really need this (as long as the game creator doesn't mess up); however, any code which constructs Pokémon from a user-supplied string should have this sort of error handling. You could also include a checksum, to spot any errors that could have been made when copying the code (rather than immediately trying to load an invalid code).

Ho-oh 112
March 4th, 2012, 09:15 AM
Oh i don't know that method, silly me :embarrass:

It's simple:
For compiler:

packcode = "*^%VVVC0283204cccCCv" # something random like that
pokemon = 493
level = 100
switch = [5, true]
ary=[pokemon,level,switch]
ary.pack(packcode)


for decompiler


packcode = "*^%VVVC0283204cccCCv" # something random like that
ary=code.unpack(packcode)
pbAddPokemon(ary[0], ary[1])
$game_switches[ary[2]] = ary[3]

rescue
Kernel.pbMessage(_INTL("Your gift file is corrupted..."))



now you just need the input code method for it...

FlipelyFlip
March 4th, 2012, 01:28 PM
@Awkward Squirrle:
The switch-thingy is still in ;)
I'm just checking if the defined switch is true or not. If a password sets the switch to true, it'll be for all other passwords which uses this switch to true (:
And about the chomp, I've only worked with the included standard stuff from rgss. I haven't seen all new methods and functions for arrays and hashes. So I fought it would be better for me at first to work with standard than with the included stuff. But don't worry, I'm still testing and working to get all new stuff (:

@Ho-oh 112:
you mean to setup it in an event without a pre-defined password? I can put it in, it's not really a problem.

@all other who requested an online-function:
I have to say it would go over my actual scripting knowledge. I will add it, but it will take time until I know how the online function works ._.

~flipy

(btw: please call me flip or flipy, easier to write and it's a shorter form)

EDIT:

For a password not defined in the hash, you can also use this one:

#=============================================================================
# Module Password
#-----------------------------------------------------------------------------
# password = "password"
# minlength = minimum of letters or symbols to enter
# maxlength = maximum of letters or symbols to enter
#=============================================================================
module Password
def self.enter(password, minlength, maxlength)
pass = pbEnterText(_INTL("Enter the password"),minlength,maxlength)
if pass.scan(/\r/) == ["\r"]
slicing = pass.size - 1
pass.slice!(slicing)
end
if pass == password
Kernel.pbMessage(_INTL("Correct password!"))
return true
else
Kernel.pbMessage(_INTL("Incorrect password."))
return false
end
end
end

to use it, just use the conditional branch script and type in: Password.enter("password", minlength, maxlength).
"password" = password used
minlength = minimum amount of characters
maxlength = maximum amount of characters

and thats it (:

~flipy

Ho-oh 112
March 5th, 2012, 07:01 AM
@Ho-oh 112:
you mean to setup it in an event without a pre-defined password? I can put it in, it's not really a problem.



No I meant like my mystery gift system you can generate your gifts instead of adding them in pre-game and using them before hand.

FlipelyFlip
March 5th, 2012, 08:30 AM
okay I'll see what I can do (:
but I think it's not very difficult (:

Ho-oh 112
March 5th, 2012, 08:36 AM
okay I'll see what I can do (:
but I think it's not very difficult (:


No it's not difficult, if you have any trouble I can help.