Author Topic: Adding ratio to dice game script  (Read 2269 times)

So it works and everthing, but i want it to do 1 more thing. Make it so it shows the ratio you won over what you lost. Example: Lets say i won 4 times and lost 6, Iwant to type /ratio and it will say 4/6. Not asking for you to just give it to me. Just a breif explination on how to. Well anyway here is the script thus far:
Code: [Select]
function servercmdrolldice(%client)

{   
  %diceroll = getRandom(1,6);
  if(%diceroll >= 3)
{
messageclient(%Client,""," Sweet I rolled a "@%diceroll@" and won!");
}

else
{

messageclient(%Client,""," stuff I rolled a "@%diceroll@" and lost!");
}

}

So it works and everthing, but i want it to do 1 more thing. Make it so it shows the ratio you won over what you lost. Example: Lets say i won 4 times and lost 6, Iwant to type /ratio and it will say 4/6. Not asking for you to just give it to me. Just a breif explination on how to. Well anyway here is the script thus far:
Code: [Select]
function servercmdrolldice(%client)

{   
  %diceroll = getRandom(1,6);
  if(%diceroll >= 3)
{
messageclient(%Client,""," Sweet I rolled a "@%diceroll@" and won!");
        %client.Dice_game_wins+=1;//add 1 to their win count
}

else
{

messageclient(%Client,""," stuff I rolled a "@%diceroll@" and lost!");
        %client.Dice_game_loses+=1;//add 1 to their lose score
}

}

function servercmddiceratio(%client){
        if(!%client.Dice_game_wins){%client.Dice_game_wins=0;}//if they have no wins, set it to 0 so it doesnt say /3 or something
        if(!%client.Dice_game_loses){%client.Dice_game_loses=0;}//if they have no loses, set it to 0 so it doesnt say 3/ or something
        messageclient(%client,'',"Your dice game ratio is" SPC %client.Dice_game_wins @ "/" @ %client.Dice_game_loses @ ".");
}


Basically, we assigned the client a Dice_game_wins variable and a Dice_game_loses variable. When they win, we add one to the wins variable, when they lose, we add one to the loses variable.

%client.<namehere> Variables are attached to the client, and can keep track of things over time that are specific to that person. An example is %client.name, which stores the client's name.(try adding messageclient(%client,'',%client.name @ ", you suck!"); at the end of the roll dice function for an example of using %client.name)

Another example that you will probably use a lot is %client.player, which is the clients player object(their blocko minifigure). For an example of using this, try
Code: [Select]
function servercmdLocate_Me(%client){
             bottomprint(%client,%client.player.getposition(),2);//show them their position
}
That'll show the client their player's position using the function getposition( player.getposition(), outputs the playerobjects X Y Z(i.e "3.4 84 102"))

There are a lot of good player.<functionname>() functions that are fun to screw around with.
Try
player.setvelocity(X Y Z)(try "0 0 100")
player.kill() (what do you think?)
player.setshapename("name") (change the name that appears above your head, try "!!" @ %client.name @ "!!")

etc. etc.

Wow I really got off track there.

Anyways,
when they say /diceratio, we send them a message telling them their wins / losses.


Ideas for expansion:(you should try these)
+Make it also track %client.dice_game_count for how many times in total they have played, and make a /dicetotal to see that.
+Add a /cleardicerecord so they can clear their wins and loses.
+keep at it damnit

Thanks for the help I will try my hardest at this script. Its the first one im accualy serious about. :D

Hmm, well i got an error at line 1. T.T

What was the error? its kind of important, you know...

Remove the empty line between the "function" line and the "{" part. (First and third lines, remove the second)

EDIT: You may have to remove the empty line above "else" as well.

I may know the problem i fell asleep trying to fixe it last night but when i copy stuff when its already in the add-ons folder, It doesnt work after sometimes.

Edit: I redid it on my desktop them moved it in it works now. Thanks for all the help. Now just to add mabye limitation on dice rolls per minute and othere stuff.>:-)
« Last Edit: August 06, 2008, 12:36:43 PM by Burger »

I added a help cmd so i wont have to post all the cmds in the welcome message.
Here is the script thus far:
Code: [Select]
function servercmdrolldice(%client)

{   
  %diceroll = getRandom(1,6);
if(%diceroll >= 4)
{
messageclient(%Client,""," Sweet I rolled a "@%diceroll@" and won!");
        %client.Dice_game_wins+=1;//add 1 to their win count
}

else
{

messageclient(%Client,""," stuff I rolled a "@%diceroll@" and lost!");
        %client.Dice_game_loses+=1;//add 1 to their lose score
}

}

function servercmddiceratio(%client)
{
        if(!%client.Dice_game_wins){%client.Dice_game_wins=0;}//if they have no wins, set it to 0 so it doesnt say /3 or something
        if(!%client.Dice_game_loses){%client.Dice_game_loses=0;}//if they have no loses, set it to 0 so it doesnt say 3/ or something
        messageclient(%client,'',"Your dice game ratio is" SPC %client.Dice_game_wins @ "/" @ %client.Dice_game_loses @ ".");
}

function servercmddicehelp(%client)
{
messageclient(%client,"","1. Type /rolldice to play");
messageclient(%client,"","2. Type /diceratio to see you wins/loses ratio");
}

Ive ran into 1 more problem trying to get the total..
Here is the script. Do you see any problems:
Code: [Select]
function servercmdrolldice(%client)

{   
  %diceroll = getRandom(1,6);
if(%diceroll >= 4)
{
messageclient(%Client,""," Sweet I rolled a "@%diceroll@" and won!");
        %client.Dice_game_wins+=1;//add 1 to their win count
%client.Dice_game_count+=1;//Adds 1 to their Total amount
}

else
{

messageclient(%Client,""," Man I rolled a "@%diceroll@" and lost!");
        %client.Dice_game_loses+=1;//add 1 to their lose score
%client.dice_game_count+=1;//Adds 1 to their total amount
}

}

function servercmddiceratio(%client)
{
        if(!%client.Dice_game_wins){%client.Dice_game_wins=0;}//if they have no wins, set it to 0 so it doesnt say /3 or something
        if(!%client.Dice_game_loses){%client.Dice_game_loses=0;}//if they have no loses, set it to 0 so it doesnt say 3/ or something
        messageclient(%client,'',"Your dice game ratio is" SPC %client.Dice_game_wins @ "/" @ %client.Dice_game_loses @ ".");
}

function servercmddicetotal
{
If(!%client.dice_game_count){%client.Dice_game_wins=0;}
messageclient(%client,'',"You have played the dice game" spc %Client.Dice_game_count @ "" @" Times.");

function servercmddicehelp(%client)
{
messageclient(%client,"","1. Type /rolldice to play");
messageclient(%client,"","2. Type /diceratio to see you wins/loses ratio");
messageclient(%client,"","3. Type /dicetotal to see the total amount of times you played");
}

You forgot to end the servercmddicetotal with a } and you forgot to add the args for the function, such as (%client)

Quote
function serverCmdDiceTotal(%client)
{
//code here
}

The bolded+underlined is the parts you missed.

Thanks so i did it right but forgot some parts.(which in turn is not doing it right, thus making me confused)

stuff, it still doesnt work.
code thus far again.......:
Code: [Select]
function servercmdrolldice(%client)

{   
  %diceroll = getRandom(1,6);
if(%diceroll >= 4)
{
messageclient(%Client,""," Sweet I rolled a "@%diceroll@" and won!");
        %client.Dice_game_wins+=1;//add 1 to their win count
%client.Dice_game_count+=1;//Adds 1 to their Total amount
}

else
{

messageclient(%Client,""," Man I rolled a "@%diceroll@" and lost!");
        %client.Dice_game_loses+=1;//add 1 to their lose score
%client.dice_game_count+=1;//Adds 1 to their total amount
}

}

function servercmddiceratio(%client)
{
        if(!%client.Dice_game_wins){%client.Dice_game_wins=0;}//if they have no wins, set it to 0 so it doesnt say /3 or something
        if(!%client.Dice_game_loses){%client.Dice_game_loses=0;}//if they have no loses, set it to 0 so it doesnt say 3/ or something
        messageclient(%client,'',"Your dice game ratio is" SPC %client.Dice_game_wins @ "/" @ %client.Dice_game_loses @ ".");
}

function servercmddicetotal(%client)
{
If(!%client.dice_game_count){%client.Dice_game_count=0;}
messageclient(%client,"","You have played the dice game" spc %Client.Dice_game_count @ "" @" Times.");
}

function servercmddicehelp(%client)
{
messageclient(%client,"","1. Type /rolldice to play");
messageclient(%client,"","2. Type /diceratio to see you wins/loses ratio");
messageclient(%client,"","3. Type /dicetotal to see the total amount of times you played");
}

It's way easier then that give me a minute and I'll make some code and post it.

Edit:: Here you go sorry about the crappy formatting.

Code: [Select]
//DiceRoll
function servercmdRollDice(%client)
 {
 %amount = getRandom(1,6);
  if(%amount > 3)
 {
     %client.win+=1;
     %client.play+=1;
     messageclient(%Client,"","\c6Sweet I rolled a \c2"@ %amount @" and won!");
}
  if(%amount < 3)
 {
     %client.lose+=1;
     %client.play+=1;
     messageclient(%Client,"","\c6Aww I rolled a \c2"@ %amount @" and lost!");
}
}

function serverCmdDiceratio(%client)
    {
       messageClient(%client,"","\c6Your dice ratio is \c2"@ %client.win @" wins /" @ %client.lose @ " loss and you have played " @ %client.play @ " times! ");
}

function servercmddicehelp(%client)
{
messageclient(%client,"","1. Type /rolldice to play!");
messageclient(%client,"","2. Type /diceratio to see you wins/loses ratio and total played times!");
}
« Last Edit: August 06, 2008, 10:42:37 PM by Kunit_Yo »

Wow, that is more orginized. Thanks, now from what i see there i think it will be alot easier to add on to it. :D

I have looked at this topic since it was made but was too lazy to create some code and actually post it after what Rky went and described.

P.S. I will be releasing a Casino mod sometime today.