Buying help
#1

Hey,

So I am a bit confused about this thing.

Let's say you go in a shop and type /buy. You choose a laptop and do /buy laptop.
I have this in my script so far.

The only way I see how to use this right now is the PlayerToPoint, but it would be boring if you could use laptop at only one place.
So I really want to know how to script that if someone doesn't buy a laptop but uses the commands for it, that he would get a message like
''You dont have a laptop"

I believe I'd have to put somewhere new laptop; and then even more but this is really so confusing for me right now.
If anyone is able to help, please
Reply
#2

Ok, so basically in order to make a item like your laptop, you have to define a variable and use that variable as if it was the laptop.

I'm not sure if you save player stats, because saving the variable will differ, depending on the way you save your stats.

But basically, you define a variable for each player, or if you have stat saving, you define one variable per stat set.

Without Stat Saving:
Код:
new HasLaptop[MAX_PLAYERS];
With Stat Saving:
If your stat system uses an enum, you have to add the HasLaptop variable to that enum. Along with that, you also need to add it to the save/load functions.

When you have the variable created, whenever the player uses the laptop command, so lets say /laptop, you check if the variable is 1, if it is, then the command will succeed.

Without Stat Saving:
Код:
if(HasLaptop[playerid] == 1)
Also, when the player buys the laptop, you should set the variable to 1.

I hope this helps. It is mainly concept, since you didn't mention how you save stats, etc. But it should give you an idea.
Reply
#3

I have stats saving. It saves money, score and all that stuff.

Thanks for the quick reply
But you ment for the second code WITH STAT SAVING and not Without Stat saving ? Cause if you didn't, then I'm a bit confused hehe.

Tho this is how I understand it from your reply.

If the player will buy the laptop, this is how the command looks like then:
Код:
	if(!strcmp(cmdtext,"/buy laptop", true))
	{
	 if(PlayerToPoint(20, playerid, -27.5028,-51.9626,1003.5469))
		{
		SendClientMessage(playerid,COLOR_GREEN,"You have bought a laptop for 450$");
		GivePlayerMoney(playerid, -450);
        // I must put something here to it will know he bougt the laptop ?
    }
    else
    {
		SendClientMessage(playerid,COLOR_RED,"You're not in a shop");
    }
   return 1;
	}
And I put this at the other 'new'

new HasLaptop[MAX_PLAYERS];
I know you said this is for without saving but doesn't there have to be a 'new HasLaptopt blabla' somewhere ?

And if he will do /laptop on
Код:
	if(!strcmp(cmdtext,"/laptop on", true))
	{
         if(HasLaptop[playerid] == 1)
	 	SendClientMessage(playerid,COLOR_GREEN,"You turned on the laptop");
        
    }
    else
    {
         if(HasLaptop[playerid] == 0)
		SendClientMessage(playerid,COLOR_RED,"You don't have a Laptop");
    }
   return 1;
	}
Thanks again for the reply, and sorry I'm learning
Reply
#4

Quote:

// I must put something here to it will know he bougt the laptop ?

Yes, but I would re-arrange the command to make it a little better!

Basically like this:
Код:
  if(!strcmp(cmdtext,"/buy laptop", true))
  {
    if(PlayerToPoint(20, playerid, -27.5028,-51.9626,1003.5469))
    {
      if(GetPlayerMoney(playerid) >= 450) // Check if the player has enough money
      {
        if(HasLaptop[playerid] == 0) // Check if the player does NOT have a laptop
        {
          SendClientMessage(playerid,COLOR_GREEN,"You have bought a laptop for 450$");
          GivePlayerMoney(playerid, -450);
          HasLaptop[playerid] = 1; // Set the laptop variable to 1
        }
        else // Player already has a laptop
        {
          SendClientMessage(playerid,COLOR_GREEN,"You already have a laptop!");
        }
      } 
      else
      {
        SendClientMessage(playerid,COLOR_GREEN,"You need 450$ to buy a laptop!");
        return 1;
      }
    }
    else
    {
      SendClientMessage(playerid,COLOR_RED,"You're not in a shop");
    }
    return 1;
  }
Again, this is without stat saving. If you want, you can contact me via msn, so that you don't have to post your code. (stephengp(a)hotmail.com) replace the (a) with @, lol

Also, don't say sorry... we all start from somewhere.


Hope this helps.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)