Jump to content
  • 0
GM-Murphy

how to add start and end event!! HELP!

Question

//===== Script ===============================================
//= Code Breaker [v1.1]
//===== By: ==================================================
//= Xantara
//===== Additional Comments: =================================
//= 1.0 Initial Release
//= 1.1 Took out unused [email protected] variable
//      Implemented KeyWorld's createCode optimization
//============================================================

prontera,147,172,5    script    Code Breaker    106,{
    function    gmPanel;
    function    validGuess;
    function    createCode;
    function    getCode;
    function    evaluateGuess;
    function    winGame;

    while(1)
    {
        if( getgmlevel() >= .minGMlvl )
            gmPanel();

        mes .NPC$;
        mes "Hello. Want to play Code Breaker?";
        next;
        switch(select("- Lets play!:- No thanks.:- Information")){
            case 1:
                mes .NPC$;
                mes "What level of difficulty do you want to play Code Breaker in?";
                next;
                set [email protected], select("- Easy:- Medium:- Hard");
                createCode();
                mes .NPC$;
                while( [email protected] != .CB_Guess[[email protected]] )
                {
                    mes "Guess a 3 digit number:";
                    mes "# of Tries: ^FF0000"+ [email protected] +"^000000 / ^3355FF"+ .CB_Guess[[email protected]] +"^000000";
                    next;
                    input [email protected];
                    if(validGuess([email protected])) {
                        if([email protected] == getCode())
                            winGame([email protected]);
                        else
                            evaluateGuess([email protected]);
                        set [email protected], [email protected] + 1;
                    }
                }
                next;
                mes .NPC$;
                mes "I'm sorry! You did not win the game. The number was ^FF0000"+ getCode() +"^000000 Try again.";
                close;            
            case 2:
                mes .NPC$;
                mes "See ya around!";
                close;
            case 3:
                mes .NPC$;
                mes "Objective of the game is to guess a 3 digit number where none of the digits repeat.";
                next;
                mes .NPC$;
                mes "There are 3 difficulty settings depending on the number of guesses.";
                for( set [email protected],1; [email protected] < getarraysize(.CB_Guess); set [email protected],[email protected]+1 )
                    mes "- "+ .CB_Diff$[[email protected]] +": "+ .CB_Guess[[email protected]] +" Tries";
                next;
                mes .NPC$;
                mes "I will give you a clue in regards to your previous guess. Code guide:";
                mes "- ^FF0000C^000000 stands for the number of numbers that are correct and in the right position.";
                next;
                mes .NPC$;
                mes "I will give you a clue in regards to your previous guess. Code guide:";
                mes "- ^FF0000N^000000 stands for the number of correct numbers that are in the wrong position.";
                next;
                mes .NPC$;
                mes "Prizes are as follows:";
                for( set [email protected],1; [email protected] < getarraysize(.CB_Diff$); set [email protected],[email protected]+1 )
                    mes "- "+ .CB_Diff$[[email protected]] +": ^FF0000"+ $CB_Prize[[email protected]+3] +"^000000x ^FF0000"+ getitemname($CB_Prize[[email protected]])+"^000000";
                break;
        }
        next;
    }

    function    gmPanel    {
        while(1) {
            mes .NPC$;
            mes "Hello GM. What can I do for you?";
            next;
            set [email protected], select("- Edit Easy Prize:- Edit Medium Prize:- Edit Hard Prize:- Player Mode");
            if([email protected] == 4)
                break;
            mes .NPC$;
            mes "Mode: Editing "+ .CB_Diff$[[email protected]] +" Prize";
            mes "Insert new prize ^FF0000item ID^000000";
            next;
            input [email protected];
            mes .NPC$;
            mes "Mode: Editing "+ .CB_Diff$[[email protected]] +" Prize";
            mes "Insert new prize ^FF0000amount^000000";
            next;
            input [email protected];
            next;
            mes .NPC$;
            mes "Mode: Editing "+ .CB_Diff$[[email protected]] +" Prize";
            mes "Are you sure you want to change the prize to ^FF0000"+ [email protected] +"^000000x ^FF0000"+ getitemname([email protected]) +"^000000?";
            next;
            if(select("No, it's wrong!:Yes, I'm sure.")==2){
                mes .NPC$;
                mes "Mode: Editing "+ .CB_Diff$[[email protected]] +" Prize";
                mes "Done!";
                set $CB_Prize[[email protected]], [email protected];
                set $CB_Prize[[email protected]+3], [email protected];
                next;
            }
        }
    }

    function    validGuess    {
        set [email protected], getarg(0);

        if( [email protected] < 100 || [email protected] > 999 ) {
            mes "^FF0000Invalid Guess. Must be a 3 digit number.^000000";
            mes " ";
            return 0;
        }

        set [email protected], [email protected] / 100;
        set [email protected], ([email protected] % 100) / 10;
        set [email protected], [email protected] % 10;

        if( ([email protected] == [email protected]) || ([email protected] == [email protected]) || ([email protected] == [email protected]) ) {
            mes "^FF0000Invalid Guess. Do not use a number more than once.^000000";
            mes " ";
            return 0;
        }

        return 1;
    }

    function    createCode    {
        for ( setarray [email protected],1,2,3,4,5,6,7,8,9; [email protected]<3; set [email protected],[email protected]+1 ) {
            set [email protected], rand([email protected]);
            set @CB_code[[email protected]+1], [email protected][[email protected]];
            deletearray [email protected][[email protected]], 1;
        }
    }
    
    function    getCode    {
        set [email protected], @CB_code[1];
        set [email protected], @CB_code[2];
        set [email protected], @CB_code[3];

        return ( ([email protected] * 100) + ([email protected] * 10) + [email protected] );
    }

    function    evaluateGuess    {
        set [email protected][1], getarg(0) / 100;
        set [email protected][2], (getarg(0) % 100) / 10;
        set [email protected][3], getarg(0) % 10;

        if( [email protected][1] == @CB_code[1] ) set [email protected],[email protected] + 1;
        if( [email protected][2] == @CB_code[2] ) set [email protected],[email protected] + 1;
        if( [email protected][3] == @CB_code[3] ) set [email protected],[email protected] + 1;

        if( ([email protected][1] == @CB_code[2]) || ([email protected][1] == @CB_code[3]) ) set [email protected],[email protected] + 1;
        if( ([email protected][2] == @CB_code[1]) || ([email protected][2] == @CB_code[3]) ) set [email protected],[email protected] + 1;
        if( ([email protected][3] == @CB_code[1]) || ([email protected][3] == @CB_code[2]) ) set [email protected],[email protected] + 1;
        
        mes .NPC$;
        mes "Last guess ^3355FF"+ getarg(0) +"^000000 had ^FF0000"+ [email protected] +"^000000 C and ^FF0000"+ [email protected] +"^000000 N";
        mes " ";
        return;
    }

    function    winGame    {
        set [email protected], getarg(0);

        mes .NPC$;
        mes "Congratulations, you cracked the code!";
        mes "Difficulty: ^3355FF"+ .CB_Diff$[[email protected]] +"^000000";
        next;
        mes .NPC$;
        mes "Here is your prize. Enjoy!";
        getitem $CB_Prize[[email protected]], $CB_Prize[[email protected]+3];
        close;
    }

OnInit:
// ---- CONFIG ------------------------------------------------------------------------------------
// NPC Name
    set .NPC$, "[ Code Breaker ]";
// Minimum GM Level for GM Panel. [Default: 60]
    set .minGMlvl, 60;
// Number of Guesses per Difficulty (Easy, Medium, Hard) [Default: 5, 3, 2]
    setarray .CB_Guess[1], 5, 3, 2;
// ---- END OF CONFIG -----------------------------------------------------------------------------
    setarray .CB_Diff$[1], "Easy", "Medium", "Hard";
    if(!$CB_Prize[1])
        setarray $CB_Prize[1], 909,909,909, 1,2,3;
    end;
}

 

Edited by Emistry
codebox
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.