Author Topic: mini game help  (Read 530 times)

Legacy_Lifsn

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
mini game help
« on: October 14, 2011, 06:48:34 pm »


               Hello everyone!

I'm not the greatest scripter by any means (as I'm sure you'll be able to tell from my code), but, I tried to write this script yesterday (from scratch).  I have a question or two about it and I'm hoping someone may be able to help me... 

(This script is currently on the "onUsed" event for an object.)

1) Right now, I'm just trying to get the name of this game object to change "Jackpot: 15" and if you play again / lose then it should say "Jackpot: 30".  Each time I play and lose it continuosly stays at Jackpot: 15.  I'm assuming thats because each time this is "onUsed" it re-initializes the "jackpot" variable, thus resetting it.  If I'm right about that, could someone maybe give me a hint on how to get around reinitializing it.  Maybe constructing it somewhere else? Idk.  (I know that I can put the word Jackpot on the original string name, I don't know why I didn't do it to start).

2) I dislike how "onUsed" is executed just by a single mouse click because there is a chance a character could "play" this game on accident before reading the description / rules, etc.  (How could I MAKE the player have to use the mouse menu to "play" this game).  Would "onOpen" work better for some reason?  What about, "onDisturbed"?  I'm not exactly familiar with what dictates an onDisturbed event.  None-the-less, I'm kind of stumped here.

3)


#include "nw_i0_plot"
void SetNewName(int JP)
{
    string originalName, strJackpot;
    object theGame = GetObjectByTag("gettingbootymachine");  //our machine
    SetName(theGame, "");   //clears the name
    originalName = GetName(theGame, FALSE);     //get the game name with jackpot info
    originalName += " Jackpot: ";
    strJackpot = IntToString( JP );
    SetName(theGame, originalName + " " + strJackpot);
}
void main()                                                                                                                
{                                                                                                                          
    int jackpot;
    int oPCtotalgold;
    int gameCost = 15;
    string strJPwinnings;
    object oPC = GetLastUsedBy();   //our player

    oPCtotalgold = GetGold(oPC);
    if(oPCtotalgold <= 14) //check to see if you have enough gold to play
    {
        SendMessageToPC( oPC, "You do not have enough gold to use this machine!" );
    }
    else    //lets play
    {
        TakeGold(gameCost, oPC, TRUE);
        int jackpotRoll;
        int winningNumber = 468;
        jackpotRoll = Random(1000);
        if(jackpotRoll == 468)            //WINNING NUMBER IS 468
        {
            strJPwinnings = IntToString( jackpot );
            RewardGP(jackpot, oPC, FALSE); //gives jackpot to oPC only (not party)
            SendMessageToPC(oPC, "Congratulations!  You just won the jackpot of " + " " + strJPwinnings + " Spend it wisely!");
            //SendMessageToAllDMs(  );  Notify DMs of jackpot winner / payout    TO BE DONE AT A LATER DATE
            jackpot = 0;
            SetNewName(jackpot);
        }
        else              //LOSING
        {
            SendMessageToPC(oPC, "Sorry, you lose.");
            jackpot += gameCost;  //add oPC gold to the pot
            strJPwinnings = IntToString( jackpot );
            SetNewName(jackpot);
            SendMessageToPC(oPC, "Jackpot is now " + strJPwinnings);
 
        }
    }
}



I mean, I realize I'm amateurish but I kind of have a decent idea on how its supposed to work.  If someone could maybe just help me understand some of these things a little bit better I'd much appreciate it!
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
mini game help
« Reply #1 on: October 14, 2011, 07:10:40 pm »


                <tying an extra knot...>

You might want to store the "pot" as an int variable on the jackpot booty machine.

Use the SetLocalInt function to store the amount of gold on the machine and the GetLocalInt function to retrieve the amount.

A comment, though - You might want to add the PC's gold to the pot before the game plays, right after taking it...
if th game stays as simple as it is, it won't matter (except to a *really* miserly PC, who doesn't want to lose 15gp when he *wins* the jackpot...). But if you start getting tricky, it might make things easier to troubleshoot if the "take gold" and "add gold to pot" functions where close to each other ;-)

Edit: On #2: You might make this a conversation. Then there will be no accidental gambling... ;-)

<...in his money pouch drawstrings>
               
               

               


                     Modifié par Rolo Kipp, 14 octobre 2011 - 06:25 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
mini game help
« Reply #2 on: October 14, 2011, 07:19:50 pm »


               <Cracking open...>

Lifsn wrote...
    SetName(theGame, "");   //clears the name
    originalName = GetName(theGame, FALSE);     //get the game name with jackpot info

Having just cleared the name of theGame, you now store "" in originalName...

Did you intend to GetName(theGame, TRUE); and retrieve the original name of theGame?

From the Lexicon
bOriginalNameIf set to TRUE any new name specified via SetName() is ignored and the original object's name is returned instead. (Default: FALSE)

<...the Book of Names>
               
               

               
            

Legacy_Lifsn

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
mini game help
« Reply #3 on: October 14, 2011, 07:31:55 pm »


               With that I was trying to clear the name, and reset it to show the new jackpot total.

I was using SetName to bring back the original name (without the jackpot: int), and then rebuild it with the new string (including the new sum of the jackpot) but I see what you mean now. I suppose it is pretty redundant and messy.

Thanks for pointing that out. (brain fart hehe).
               
               

               
            

Legacy_Lifsn

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
mini game help
« Reply #4 on: October 14, 2011, 07:33:14 pm »


               oh, and also, thanks for the heads up on the SetLocalInt, etc.  not exactly familiar with it but I'm gonna read up on it and do some rewriting
               
               

               
            

Legacy_Lifsn

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
mini game help
« Reply #5 on: October 14, 2011, 09:35:17 pm »


               Yeahh. I can't figure out how to use SetLocalInt without having to reinitialize the value integer (which brings it back to 0 everytime).
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
mini game help
« Reply #6 on: October 15, 2011, 07:08:36 pm »


                <scribbling something...>

What happens when you use this?

// Note: The integer iJackPot should be set on the object when created with a value of initial jackpot

#include "nw_i0_plot"
void SetNewName(int JP)
{
    string originalName, strJackpot;
    object theGame = GetObjectByTag("gettingbootymachine");  //our machine
    originalName = GetName(theGame, TRUE);     //get the original name
    originalName += " Jackpot: ";
    strJackpot = IntToString( JP );
    SetName(theGame, originalName + strJackpot); //set the name + jackpot
}
void main()                                                                                                                
{
                                                                                                                       
  object oMachine = GetObjectByTag("gettingbootymachine")
  int jackpot = GetLocalInt(oMachine,"iJackPot");
  int oPCtotalgold = GetGold(oPC);
  int gameCost = 15;
  string strJPwinnings;
  object oPC = GetLastUsedBy();   //our player

  if(oPCtotalgold <= 14) //check to see if you have enough gold to play
  {
    SendMessageToPC( oPC, "You do not have enough gold to use this machine!" );
  }
  else    //lets play
  {
    TakeGold(gameCost, oPC, TRUE);
    jackpot += gameCost;     //add oPC gold to the pot
    int jackpotRoll = Random(1000);
    if(jackpotRoll == 468)            //WINNING NUMBER IS 468
    {
      strJPwinnings = IntToString( jackpot );
      RewardGP(jackpot, oPC, FALSE); //gives jackpot to oPC only (not party)
      SendMessageToPC(oPC, "Congratulations!  You just won the jackpot of " + " " + strJPwinnings + " Spend it wisely!");
      //SendMessageToAllDMs(  );  Notify DMs of jackpot winner / payout    TO BE DONE AT A LATER DATE
      jackpot = 0; // if jackpot is 0gp... what is players motivation for playing? :-P
    }
    else              //LOSING
    {
      SendMessageToPC(oPC, "Sorry, you lose.");
      strJPwinnings = IntToString( jackpot );
      SendMessageToPC(oPC, "Jackpot is now " + strJPwinnings);
    }
    SetLocalInt(oMachine, "iJackPot", jackpot);
    SetNewName(jackpot);
  }
}


<...on a scrap>
               
               

               


                     Modifié par Rolo Kipp, 16 octobre 2011 - 01:13 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
mini game help
« Reply #7 on: October 16, 2011, 05:15:15 am »


               

Rolo Kipp wrote...

// if jackpot is 0gp... what is players motivation for playing? :-P


You are having 100% of proceeds go to the jackpot.  What you could do is have 99.5% of proceeds go to the jackpot and when there is a win, simply set the new jackpot at 5/1000 the old.  With a 0.1% chance of winning, this will allow the jackpot to slowly increase over time.  Then at the beginning of each server week, (or whatever timespan) reset the jackpot to 10,000 or whatever you want as the initial.



EDIT fixed 5/995 to 5/1000 this preserves new jackpot to be a portion not the entirety of what was set aside.
               
               

               


                     Modifié par WhiZard, 16 octobre 2011 - 05:23 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
mini game help
« Reply #8 on: October 16, 2011, 05:22:34 pm »


               <chuckling as he...>

WhiZard wrote...
You are having 100% of proceeds go to the jackpot.  What you could do is have 99.5% of proceeds go to the jackpot and when there is a win, simply set the new jackpot at 5/1000 the old.  With a 0.1% chance of winning, this will allow the jackpot to slowly increase over time.  Then at the beginning of each server week, (or whatever timespan) reset the jackpot to 10,000 or whatever you want as the initial.

Even better, .5% go to seeding the next jackpot and .5% go to *ME* =) Er, I mean, the guy that runs the crooked, er, fascinating little machine.  Cost of oil and polish, you know :-)

Good Idea :-)

<...gets even richer>
               
               

               
            

Legacy_Lifsn

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
mini game help
« Reply #9 on: October 17, 2011, 12:29:09 am »


               Awesome.  Thanks for the help and the advice guys.