Reaction Help -
Kostas' - 07.11.2011
I typed the randoms letters, but I didn't win anything. Also, it didn't appear message that I won.
What is wrong with this code?
pawn Код:
#include <a_samp>
#define CONTEST_PRIZE 5000
#define MAX_CONTESTWORD_LENGTH 6 //Set to whatever you want
new ContestAnswer[MAX_CONTESTWORD_LENGTH],bool:StartTest;
forward NewContest();
stock randomletters(string[], maxlen = sizeof(string))
{
new i;
while(i < maxlen)
{
if(random(2))
string[i] = random(26) + 65; //upper
else
string[i] = random(26) + 97; //lower
i++;
}
return 1;
}
public OnFilterScriptInit()
{
SetTimer("NewContest",180000,true);
return 1;
}
public OnPlayerText(playerid, text[])
{
if(StartTest)
{
if(!strcmp(text,ContestAnswer))
{
OnPlayerWinContest(playerid);
return 0;
}
}
return 1;
}
public NewContest()
{
new string[128];
randomletters(ContestAnswer);
format(string,sizeof string,"A new contest has started. Whoever types %s first, wins $%d.",ContestAnswer,CONTEST_PRIZE);
SendClientMessageToAll(0x00FFFFFF,string);
StartTest=true;
return 1;
}
stock OnPlayerWinContest(playerid)
{
StartTest=false;
new pName[MAX_PLAYER_NAME],string[128];
GetPlayerName(playerid,pName,sizeof pName);
format(string,sizeof string,"Player %s has won the contest and has won %d!",pName,CONTEST_PRIZE);
SendClientMessageToAll(0x00FFFFFF,string);
GivePlayerMoney(playerid,CONTEST_PRIZE);
ContestAnswer="";
return 1;
}
Something is wrong with OnPlayerText.
Moreover, how can I change the stock except for random letters to have random letters+ numbers.
For example to appears like "f4Sue2Ro"
Re: Reaction Help -
RyDeR` - 07.11.2011
Make sure you use capital letters correct since you haven't disable case check in strcmp.
Re: Reaction Help -
Kostas' - 07.11.2011
I used them correctly when I test it. I mean with the correct capitals letters.
At strcmp when it's false, they're not the same, right?
How can I disable the case
Re: Reaction Help -
RyDeR` - 07.11.2011
Yes, it returns false when they're equal.
Set the
bool:ignorecase parameter to true.
Re: Reaction Help -
Kostas' - 07.11.2011
How do you mean like this
pawn Код:
stock randomletters(string[], bool:ignorecase = true, maxlen = sizeof(string))
{
new i;
while(i < maxlen)
{
if(random(2))
string[i] = random(26) + 65; //upper
else
string[i] = random(26) + 97; //lower
i++;
}
return 1;
}
pawn Код:
public OnPlayerText(playerid, text[])
{
if(StartTest)
{
if(!strcmp(text,ContestAnswer,true))
{
OnPlayerWinContest(playerid);
return 0;
}
}
return 1;
}
I got a warning at line 7
pawn Код:
stock randomletters(string[], bool:ignorecase = true, maxlen = sizeof(string))
pawn Код:
warning 203: symbol is never used: "ignorecase"
Re: Reaction Help -
Jefff - 07.11.2011
maxlen = sizeof(string) must be -1 You dont have EOS and its fail
Re: Reaction Help -
Kostas' - 08.11.2011
I confused.
I made one, but I haven't learn about the stock, so I don't know how it works.
pawn Код:
stock randomletters(string[], maxlen = sizeof(string))
{
new i;
while(i < maxlen)
{
if(random(2))
string[i] = random(26) + 65; //upper
else
string[i] = random(26) + 97; //lower
i++;
}
string[i] = EOS;
return string;
}
This is compiles fine, but it will not correct I guess, because as you mentioned before
maxlen = sizeof(string) must be -1 . Is the EOS is correct?
Also,
pawn Код:
stock randomletters(string[], maxlen = sizeof(string))
{
new i;
while(i < maxlen = sizeof(string) -1)
{
if(random(2))
string[i] = random(26) + 65; //upper
else
string[i] = random(26) + 97; //lower
i++;
}
string[i] = EOS;
return string;
}
I made the
i < maxlen = sizeof(string) -1, but I got 3 errors and 3 warnings at line
pawn Код:
while(i < maxlen = sizeof(string) -1)
Warnings:
warning 211: possibly unintended assignment
warning 224: indeterminate array size in "sizeof" expression (symbol "")
warning 215: expression has no effect
Errors:
error 022: must be lvalue (non-constant)
error 001: expected token: ")", but found "sizeof"
error 001: expected token: ";", but found ")"
But as I saw, it must be
while(i < maxlen)