SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 29/10/2019, 03:46 PM   #11
Proxus
Huge Clucker
 
Proxus's Avatar
 
Join Date: May 2018
Location: United Kingdom
Posts: 461
Reputation: 20
Default Re: Checking if no one's player-specific variable is equal to value

Quote:
Originally Posted by Mugala View Post
okay, it means that we have to prioritize the lotto numbers first, then if there is not a winner by that number, we should start a new lottery by the players, so, I'll write a code here to do that.
PHP Code:
        LottoNum random(59);

        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(!
IsPlayerConnected(i)) continue;
            if(
LottoNumber[i] == LottoNum)
            {
                
// Get the player's name
                
GetPlayerName(iNamesizeof(Name));
                
                
format(Msgsizeof(Msg), "{FFFF00}LOTTO: Congratulations, you have won $%i in the lottery!"LottoPrize);
                
SendClientMessage(iCOLOR_WHITEMsg);
                
                
format(Msgsizeof(Msg), "{FFFF00}LOTTO: %s has won $%i in the lottery. Congratulations!"NameLottoPrize);
                
SendClientMessageToAll(COLOR_WHITEMsg);
                
GivePlayerMoney(iLottoPrize);

                
TotalWinners++;

                
LottoNumber[i] = 0;

                
//break; NO NEED, WILL CAUSE ISSUES
            
}
            else if(
LottoNumber[i] != && LottoNumber[i] != LottoNum && TotalWinners 0)
            {
                    
SendClientMessage(iCOLOR_WHITE"{FFFF00}LOTTO: Unfortunately you haven't won the lottery. Good luck next time!");
            }
            
//else return 0; NO NEED, THIS WILL STOP WHOLE FUNCTION
            
LottoNumber[i] = 0;
        }

        
LottoNum 0;

        if(
TotalWinners == 0//So if there is not a winner, start a second lottery.
        
{
            new 
winnerID random(GetPlayerPoolSize());
            while(
IsPlayerConnected(winnerID))
            {
                
winnerID random(GetPlayerPoolSize());
            }
            
GetPlayerName(winnerIDNamesizeof(Name));
            
            
format(Msgsizeof(Msg), "{FFFF00}LOTTO: Congratulations, you have won $%i in the lottery!"LottoPrize);
            
SendClientMessage(winnerIDCOLOR_WHITEMsg);
            
            
format(Msgsizeof(Msg), "{FFFF00}LOTTO: %s has won $%i in the lottery. Congratulations!"NameLottoPrize);
            
SendClientMessageToAll(COLOR_WHITEMsg);
            
GivePlayerMoney(winnerIDLottoPrize);
        }

        
LottoPrize 0
It starts a new lottery instead of using the existing participants, and therefore requiring players to put new numbers & more money in, was this intentional?
__________________
Developer @ Trucknation
"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity"


IMPORTANT LINKS
An upcoming mix of trucking & light roleplay
Proxus is online now   Reply With Quote
Old 29/10/2019, 05:33 PM   #12
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,939
Reputation: 504
Default Re: Checking if no one's player-specific variable is equal to value

Just push the lotto numbers into an array with playerid as index .Get the random lotto number from this array and announce the corresponding playerid as the winner.
Or use y_iterate
SyS is offline   Reply With Quote
Old 29/10/2019, 05:38 PM   #13
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,177
Reputation: 73
Default Re: Checking if no one's player-specific variable is equal to value

Quote:
Originally Posted by Proxus View Post
It starts a new lottery instead of using the existing participants, and therefore requiring players to put new numbers & more money in, was this intentional?
change in "while" function then, do however you like to use it.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 30/10/2019, 03:33 PM   #14
RoboN1X
Huge Clucker
 
RoboN1X's Avatar
 
Join Date: Feb 2011
Location: Indonesia
Posts: 453
Reputation: 145
Default Re: Checking if no one's player-specific variable is equal to value

Quote:
Originally Posted by Proxus View Post
How would I pick a random one from the numbers entered by the participants? Would it be best to use an array, add all the numbers there and then choose one?
Quote:
Originally Posted by Proxus View Post
I want a winner guaranteed every time. So I did this:
Quote:
Originally Posted by Proxus View Post
I feel like it's going to be annoying for players if there's barely ever a winner.
The lottery system should still function because:
- a percentage will be drawn out of the player's input (e.g. 5000 won't be exactly 5000 in the lottery pot), will add
- there is still a chance of winning & losing

If people barely win, people will eventually get bored and stop using lottery. It's not for a roleplay server, it's for a trucking server (which isn't as deeply focussed on hardcore roleplay)
Sorry if i get you wrong. I think that hotspicytaco's and SyS's points are kinda clear? So you want a lottery that is guaranteed a winner every time? Then what is the lottery number is there for? Just pick random player id and it's always guaranteed found. Then simulate as if the player's chosen number is correct. What is the point doing a second lottery like that if player who did not participate lottery have chance to win it?
__________________
Need Help? Use Search, WIKI, and FAQ
RoboN1X is offline   Reply With Quote
Old 30/10/2019, 06:59 PM   #15
Proxus
Huge Clucker
 
Proxus's Avatar
 
Join Date: May 2018
Location: United Kingdom
Posts: 461
Reputation: 20
Default Re: Checking if no one's player-specific variable is equal to value

Quote:
Originally Posted by RoboN1X View Post
Sorry if i get you wrong. I think that hotspicytaco's and SyS's points are kinda clear? So you want a lottery that is guaranteed a winner every time? Then what is the lottery number is there for? Just pick random player id and it's always guaranteed found. Then simulate as if the player's chosen number is correct. What is the point doing a second lottery like that if player who did not participate lottery have chance to win it?
My bad, I didn't even see the replies.

Only one thing I'd criticise about your reply:
Code:
What is the point doing a second lottery like that if player who did not participate lottery have chance to win it?
That's probably where I've been misinterpreted. I didn't want it to start a new lottery, I just wanted it to loop until a number is found that has been chosen. I like the ideas suggested above, so consider this closed unless I need further help.

Thanks everyone!

For example:
Player1 chooses 52 -> Wrong -> Loops to 23 -> Wrong -> Loops to 52 -> Correct
__________________
Developer @ Trucknation
"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity"


IMPORTANT LINKS
An upcoming mix of trucking & light roleplay
Proxus is online now   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


Similar Threads
Thread Thread Starter Forum Replies Last Post
TextDraw is not getting equal to Variable maikons Scripting Help 6 30/08/2015 07:07 AM
I need some help. (Checking if the playerid is equal to the targetid) Th3UnKnOwN Scripting Help 4 09/07/2015 11:46 PM
Create a variable equal to the current value of another variable (create a constant) WellDone Scripting Help 19 19/01/2013 11:41 PM
Checking for specific player's name cosbraa Scripting Help 4 09/06/2012 10:14 AM
Checking if the player passed the specific EXP?(EDITED)!!!! still need help 0ne Help Archive 6 21/06/2010 08:31 PM


All times are GMT. The time now is 02:45 PM.


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