Jump to content
  • 0

how to add start and end event!! HELP!


GM-Murphy

Question


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  5
  • Reputation:   0
  • Joined:  08/31/21
  • Last Seen:  

//===== Script ===============================================
//= Code Breaker [v1.1]
//===== By: ==================================================
//= Xantara
//===== Additional Comments: =================================
//= 1.0 Initial Release
//= 1.1 Took out unused .@skip 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 .@l, select("- Easy:- Medium:- Hard");
                createCode();
                mes .NPC$;
                while( .@guesses != .CB_Guess[.@l] )
                {
                    mes "Guess a 3 digit number:";
                    mes "# of Tries: ^FF0000"+ .@guesses +"^000000 / ^3355FF"+ .CB_Guess[.@l] +"^000000";
                    next;
                    input .@num;
                    if(validGuess(.@num)) {
                        if(.@num == getCode())
                            winGame(.@l);
                        else
                            evaluateGuess(.@num);
                        set .@guesses, .@guesses + 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 .@i,1; .@i < getarraysize(.CB_Guess); set .@i,.@i+1 )
                    mes "- "+ .CB_Diff$[.@i] +": "+ .CB_Guess[.@i] +" 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 .@i,1; .@i < getarraysize(.CB_Diff$); set .@i,.@i+1 )
                    mes "- "+ .CB_Diff$[.@i] +": ^FF0000"+ $CB_Prize[.@i+3] +"^000000x ^FF0000"+ getitemname($CB_Prize[.@i])+"^000000";
                break;
        }
        next;
    }

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

    function    validGuess    {
        set .@guess, getarg(0);

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

        set .@n1, .@guess / 100;
        set .@n2, (.@guess % 100) / 10;
        set .@n3, .@guess % 10;

        if( (.@n1 == .@n2) || (.@n1 == .@n3) || (.@n2 == .@n3) ) {
            mes "^FF0000Invalid Guess. Do not use a number more than once.^000000";
            mes " ";
            return 0;
        }

        return 1;
    }

    function    createCode    {
        for ( setarray .@list,1,2,3,4,5,6,7,8,9; .@i<3; set .@i,.@i+1 ) {
            set .@j, rand(9-.@i);
            set @CB_code[.@i+1], .@list[.@j];
            deletearray .@list[.@j], 1;
        }
    }
    
    function    getCode    {
        set .@n1, @CB_code[1];
        set .@n2, @CB_code[2];
        set .@n3, @CB_code[3];

        return ( (.@n1 * 100) + (.@n2 * 10) + .@n3 );
    }

    function    evaluateGuess    {
        set .@g[1], getarg(0) / 100;
        set .@g[2], (getarg(0) % 100) / 10;
        set .@g[3], getarg(0) % 10;

        if( .@g[1] == @CB_code[1] ) set .@C,.@C + 1;
        if( .@g[2] == @CB_code[2] ) set .@C,.@C + 1;
        if( .@g[3] == @CB_code[3] ) set .@C,.@C + 1;

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

    function    winGame    {
        set .@d, getarg(0);

        mes .NPC$;
        mes "Congratulations, you cracked the code!";
        mes "Difficulty: ^3355FF"+ .CB_Diff$[.@d] +"^000000";
        next;
        mes .NPC$;
        mes "Here is your prize. Enjoy!";
        getitem $CB_Prize[.@d], $CB_Prize[.@d+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...