SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 12/03/2015, 05:24 PM   #1
SnoopDy
Little Clucker
 
SnoopDy's Avatar
 
Join Date: Jan 2015
Posts: 16
Reputation: 1
Default Orel Reshka :)

Hi guys,i worked on pawno and decided create my Mode ).
I created first system "Orel and Reshka(Russian)"
Basically, the system needs to check the player's luck and make some money)

Go.

Defines:
Code:
#define prizedollars 500//Prize $
#define costor 500//Command Cost
#define OREL_RESHKA_DL 123//Dialog
#define OREL_RESHKA_DL_1 1231//Dialog 1_1
#define OREL_RESHKA_DL_2 1232//Dialog 1_2
New:
Code:
new lucky[MAX_PLAYERS];
new choose[MAX_PLAYERS];
OnPlayerCommand:
Code:
	if(strcmp(cmd, "/lucky", true) == 0) {
		if(GetPlayerMoney(playerid) < costor){
			new str[128];
			format(str,sizeof(str),"You don`t have %d dollars!",costor);
			SendClientMessage(playerid,-1,str);
			return 1;}
		else{
			GivePlayerMoney(playerid,costor);
			ShowPlayerDialog(playerid,OREL_RESHKA_DL,DIALOG_STYLE_MSGBOX,"Orel Reshka","Choose:","Orel","Reshka");
			return 1;}
	}
OnDialogResponse:
Code:
if(dialogid == OREL_RESHKA_DL)
	{
		new str[256];
		if(response)
		{
				choose[playerid] = 1;
				new rand = random(7);
				new stringer[10];
				switch(rand)
				{
					case 0:lucky[playerid] = 1,stringer = "Orel";
					case 1:lucky[playerid] = 2,stringer = "Reshka";
					case 2:lucky[playerid] = 2,stringer = "Reshka";
					case 3:lucky[playerid] = 2,stringer = "Reshka";
					case 4:lucky[playerid] = 2,stringer = "Reshka";
					case 5:lucky[playerid] = 2,stringer = "Reshka";
					case 6:lucky[playerid] = 1,stringer = "Orel";
				}
				new str1[64];
				format(str1,sizeof(str1),"%s",stringer);
				if(lucky[playerid] == choose[playerid]){
					format(str,sizeof(str),"Answer: %s\nCongratulations, you guessed it!",str1);
					ShowPlayerDialog(playerid,OREL_RESHKA_DL_1,DIALOG_STYLE_MSGBOX,"Orel Reshka",str,"Thank","");
				}
				else if(lucky[playerid] != choose[playerid]){
					format(str,sizeof(str),"Answer: %s\nSorry you are wrong!",str1);
					ShowPlayerDialog(playerid,OREL_RESHKA_DL_2,DIALOG_STYLE_MSGBOX,"Orel Reshka",str,"Falied","");
				}
		}
		else
			{
				choose[playerid] = 2;
				new rand = random(7);
				new stringer[10];
				switch(rand)
				{
					case 0:lucky[playerid] = 1,stringer = "Orel";
					case 1:lucky[playerid] = 1,stringer = "Orel";
					case 2:lucky[playerid] = 2,stringer = "Reshka";
					case 3:lucky[playerid] = 2,stringer = "Reshka";
					case 4:lucky[playerid] = 1,stringer = "Orel";
					case 5:lucky[playerid] = 1,stringer = "Orel";
					case 6:lucky[playerid] = 1,stringer = "Orel";
				}
				new str1[64];
				format(str1,sizeof(str1),"%s",stringer);
				if(lucky[playerid] == choose[playerid]){
					format(str,sizeof(str),"Answer: %s\nCongratulations, you guessed it!",str1);
					ShowPlayerDialog(playerid,OREL_RESHKA_DL_1,DIALOG_STYLE_MSGBOX,"Orel Reshka",str,"Thank","");
				}
				else if(lucky[playerid] != choose[playerid]){
					format(str,sizeof(str),"Answer: %s\nSorry you are wrong!",str1);
					ShowPlayerDialog(playerid,OREL_RESHKA_DL_2,DIALOG_STYLE_MSGBOX,"Orel Reshka",str,"Falied","");
				}
			}
	}
	if(dialogid == OREL_RESHKA_DL_1){
		new money = prizedollars;//Prize
		GivePlayerMoney(playerid,money);
		SendClientMessage(playerid,-1,"You can also test your luck again!:)");
		return 1;
	}
	if(dialogid == OREL_RESHKA_DL_2){
		SendClientMessage(playerid,-1,"Do not worry, you can be lucky next time!:(");
		return 1;
	}
P.S I used standart command processor
Good Luck!
SnoopDy is offline   Reply With Quote
Old 13/03/2015, 12:41 AM   #2
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,526
Reputation: 554
Default Re: Orel Reshka :)

Hello OP, it's cool you shared what you've learned, I have a few issues though:
1. Please for the love of God, use indentation properly
2. You gave player money even before the flip was made, that's not a good casino rule...
3. This casino cheats as hell: if I bet I have only 29% chance of winning? HEY!
Misiur is offline   Reply With Quote
Old 13/03/2015, 12:53 AM   #3
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,139
Reputation: 445
Default Re: Orel Reshka :)

This isn't a tutorial! You explained nothing, and just gave us code. You cannot do that in this section - either change it to a tutorial form or request a thread move to an appropriate section(such as the filterscript / release section).

You also have some bad scripting habits going on, for example the switch.

pawn Code:
switch(rand)
                {
                    case 0:lucky[playerid] = 1,stringer = "Orel";
                    case 1:lucky[playerid] = 2,stringer = "Reshka";
                    case 2:lucky[playerid] = 2,stringer = "Reshka";
                    case 3:lucky[playerid] = 2,stringer = "Reshka";
                    case 4:lucky[playerid] = 2,stringer = "Reshka";
                    case 5:lucky[playerid] = 2,stringer = "Reshka";
                    case 6:lucky[playerid] = 1,stringer = "Orel";
                }

Now basically instead of using 2 lines you spread it over 7 - when the results are purely the same. A better code would be:

pawn Code:
switch(rand)
                {
                    case 0,6:lucky[playerid] = 1,stringer = "Orel";
                    case 1..5:lucky[playerid] = 2,stringer = "Reshka";
                                        default: return 0; // This shouldn't be called but just in case let's have it return 0.
                }
Abagail is offline   Reply With Quote
Old 13/03/2015, 01:33 PM   #4
SnoopDy
Little Clucker
 
SnoopDy's Avatar
 
Join Date: Jan 2015
Posts: 16
Reputation: 1
Default Re: Orel Reshka :)

Quote:
Originally Posted by Misiur View Post
Hello OP, it's cool you shared what you've learned, I have a few issues though:
1. Please for the love of God, use indentation properly
2. You gave player money even before the flip was made, that's not a good casino rule...
3. This casino cheats as hell: if I bet I have only 29% chance of winning? HEY!
And how should it be?
SnoopDy is offline   Reply With Quote
Old 13/03/2015, 01:35 PM   #5
SnoopDy
Little Clucker
 
SnoopDy's Avatar
 
Join Date: Jan 2015
Posts: 16
Reputation: 1
Default Re: Orel Reshka :)

Quote:
Originally Posted by Misiur View Post
Hello OP, it's cool you shared what you've learned, I have a few issues though:
1. Please for the love of God, use indentation properly
2. You gave player money even before the flip was made, that's not a good casino rule...
3. This casino cheats as hell: if I bet I have only 29% chance of winning? HEY!
Quote:
Originally Posted by Abagail View Post
This isn't a tutorial! You explained nothing, and just gave us code. You cannot do that in this section - either change it to a tutorial form or request a thread move to an appropriate section(such as the filterscript / release section).

You also have some bad scripting habits going on, for example the switch.

pawn Code:
switch(rand)
                {
                    case 0:lucky[playerid] = 1,stringer = "Orel";
                    case 1:lucky[playerid] = 2,stringer = "Reshka";
                    case 2:lucky[playerid] = 2,stringer = "Reshka";
                    case 3:lucky[playerid] = 2,stringer = "Reshka";
                    case 4:lucky[playerid] = 2,stringer = "Reshka";
                    case 5:lucky[playerid] = 2,stringer = "Reshka";
                    case 6:lucky[playerid] = 1,stringer = "Orel";
                }

Now basically instead of using 2 lines you spread it over 7 - when the results are purely the same. A better code would be:

pawn Code:
switch(rand)
                {
                    case 0,6:lucky[playerid] = 1,stringer = "Orel";
                    case 1..5:lucky[playerid] = 2,stringer = "Reshka";
                                        default: return 0; // This shouldn't be called but just in case let's have it return 0.
                }
It`s my first system.
Of course there will be mistakes, not everything is perfect)
SnoopDy is offline   Reply With Quote
Old 13/03/2015, 01:39 PM   #6
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default Re: Orel Reshka :)

First off, this is not a tutorial in any way, you haven't explained anything at all.
A tutorial means to explain what to do, why to do it, and how it works.

Second, why do you have the [Tool/Web/Other]-tag in the tutorial section?
__________________
[Tutorial] Custom Playerdamage system
Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
CalvinC is offline   Reply With Quote
Old 13/03/2015, 02:04 PM   #7
newbienoob
High-roller
 
newbienoob's Avatar
 
Join Date: Jan 2012
Location: Follow the moaning coming from your parents' bedroom
Posts: 1,532
Reputation: 269
Default Re: Orel Reshka :)

Quote:
Originally Posted by SnoopDy View Post
It`s my first system.
Of course there will be mistakes, not everything is perfect)
but when it comes to coding, everything SHOULD and MUST be perfect
__________________
Help me, please /a chat
newbienoob is offline   Reply With Quote
Old 13/03/2015, 02:39 PM   #8
SnoopDy
Little Clucker
 
SnoopDy's Avatar
 
Join Date: Jan 2015
Posts: 16
Reputation: 1
Default Re: Orel Reshka :)

This ready-made solution )

As I can and I bring the script to perfection, this version I have overthrown yesterday, today I did timers, animation and added on the public, and not in dialog.Progress)
SnoopDy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.