[help]driving school
#1

hello, I cant get this code to work.

1) it spams the chat with messages
2)something is wrong with the getplayermoney checks because even if I have the money its says I dondt (tested with $999, $1, $1000 and $1001)

Link to code (click me)
Reply
#2

Instead of...
pawn Code:
if(GetPlayerMoney(playerid) < 1001)
{
Use...
pawn Code:
if (GetPlayerMoney(playerid) >= 1000)
{
Reply
#3

thx, I will test it
Reply
#4

Quote:
Originally Posted by klavins
thx, I will test it
Working?
Reply
#5

Alright.

I had a slight look at your code and I was highly supprised on how you coded it and I am not at all supprised that it spams you with messages.

So, lets have a look at your loop here:

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{// start of the loop
  if(IsPlayerConnected(i))
  {
    if(PlayerInfo[i][pLeader] == 11 || PlayerInfo[i][pMember] == 11)
    {
      SendClientMessage(playerid, COLOR_WHITE, "Tu vari nopirkt licensi tikai tad ja instruktori nava online.");
    }
  }
  else
  {
    if(PlayerInfo[playerid][pCarLic] == 1)
    {
      SendClientMessage(playerid, COLOR_WHITE, "Tev jau ir brauksanas license.");
      return 1;
    }
  }
}// end of the loop
// this is just a example, not the exact loop
Thats already enough, don't need more. I've already marked where the loop starts and where it ends. So, let me explain you what you are doing.

At first you are declaring a loop with a variable called i. You are saying that I should increase until it reaches 200(MAX_PLAYERS in 0.2x as this isn't 0.3 scripting). Alright, now you repeat the code between the loop 201 times(due to ID 0). Each time, when you are looking through this loop, you look with a "if" if the variable "i" indicating the ID, is a faction member of the DMW and if he is a license instructor, trying to tell him that there is someone in need of a license. Each time the person isn't a instructor or a DMW member, you will automatically execute the "else". In the else, you tell the script to look if he has a license or not and you will then, regarding if he does or not send him a message. Lets say you have 200 players. None of these players are a license instructor. You will repeat the else exactly 201 times.

The only fault you did here, hence the messages spam, was repeat a code you don't have to repeat. You weren't thinking enough when doing this loop. Move the "else" code out of the loop and check it AFTER the loop and you will be fine with your first problem.

Also, to your second problem:
(PS: I know it was already solved)

pawn Code:
if(GetPlayerMoney(playerid) < 1001)
Is what you did.

So, lets have a look at that. GetPlayerMoney(playerid) will return a integer, which will hold the amount of how much the person has in cash. Now, in the if, you look if the amount of money is "<" BELOW 1001, hence the problem that it tells you you do not have enough money. Now, the solution Abernethy posted was:

pawn Code:
if(GetPlayerMoney(playerid) >= 1000)
So, lets have a closer look at that too. GetPlayerMoney(playerid) as above, getting the players money. Then we look if ">" the money is above 1000 or "=" is 1000.

All your problems should be solved.

EDIT: typo.
Reply
#6

thx but I think is should of said at first what that code needed to do (ops) when typing /dmv driving it gives a license and takes 1000$ from player, but if instructor is online it says that license cant be purchased.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)