Tiki System Help
#1

Hi everyone, I'm here with a new question. Like the title says, I want to create a tiki system, lets say I added 50 tiki pickups, and each one give something to players that picked them up. My question is, how I should do if I want players to pick them just once, and what I have to do to identify when a player picks up all of them.

Below you will find an example of what I want to make.

Код:
new tiki1,....tiki50;
new Picked[MAX_PLAYERS];

tiki1 = CreatePickup(1234, X, Y, Z, -1); etc

public OnPlayerPickUpPickup(playerid, pickupid)
{
     if(pickupid == tiki1)
    {
        if(!Picked[playerid])
        {
            SendClientMessage(playerid, COLOR_GREY, "Ai gasit o statueta tiki si ai primit 5RP!");
            PlayerInfo[playerid][pExp] += 5;
            Picked[playerid] ++;
        }
        else { }
	}
	if(pickupid == tiki2)
	{
	    if(!Picked[playerid])
	    {
	    	SendClientMessage(playerid, COLOR_GREY, "Ai gasit o statueta tiki si ai primit un level up!");
	    	SendClientMessage(playerid, COLOR_GREY, "Felicitari,ai colectat toate tiki-urile si ai mai primit un   bonus de 1.5kk!");
	    	PlayerInfo[playerid][pLevel] +=1;
		GivePlayerMoney(playerid, 1500000);
		Picked[playerid] ++;
		}
		else { }
	}
	return 1;
}
Reply
#2

Here is an example, but it would be better if you use y_iterate
Код:
new tiki[50]; // You should've make this variable as an array for easier use
new bool:Picked[MAX_PLAYERS][50];

tiki[0] = CreatePickup(1234, X, Y, Z, -1);
// ... until tiki[49] = CreatePickup(...

public OnPlayerPickUpPickup(playerid, pickupid)
{
	for(new i = 0; i < 50; i++) // Loop 50 times to check if pickupid is tiki pickup
	{
		if(pickupid != tiki[i])
			continue;

		if(Picked[playerid][i])
			return SendClientMessage(playerid, COLOR_GREY, "You picked up this tiki already!");
		else
		{
			OnPlayerPickTiki(playerid, i);
            Picked[playerid][i] = true;
            return 1;
		}
	}
	return 1;
}

forward OnPlayerPickTiki(playerid, tikiid);
public OnPlayerPickTiki(playerid, tikiid) // This callback is called on player picked up a tiki (tikid = index of tiki)
{
	switch(tikiid)
	{
		case 0: // If player picked up tiki[0]
		{
			SendClientMessage(playerid, COLOR_GREY, "Ai gasit o statueta tiki si ai primit 5RP!");
            PlayerInfo[playerid][pExp] += 5;
		}
		case 1: // If player picked up tiki[1]
		{
			SendClientMessage(playerid, COLOR_GREY, "Ai gasit o statueta tiki si ai primit un level up!");
	    	SendClientMessage(playerid, COLOR_GREY, "Felicitari,ai colectat toate tiki-urile si ai mai primit un   bonus de 1.5kk!");
	    	PlayerInfo[playerid][pLevel] +=1;
			GivePlayerMoney(playerid, 1500000);
		}
		case 2:
		{
			// ...
		}
	}
	return 1;
}

IsPlayerPickedUpAllTiki(playerid) // You can use this to check if player picked up all tikis
{
	for(new i = 0; i < 50; i++)
		if(!Picked[playerid][i])
			return false;

	return true;
}
Reply
#3

Thanks,I'll try this and let you know!
Reply
#4

It works perfectly,but if I restart the server I am able to pick them up. And other question. IsPlayerPickedUpAllTiki(playerid) gave me warning that is never used?
Reply
#5

Quote:
Originally Posted by VikThor
Посмотреть сообщение
It works perfectly,but if I restart the server I am able to pick them up. And other question. IsPlayerPickedUpAllTiki(playerid) gave me warning that is never used?
You should save the values of "Picked" variable first, and load them under onplayerconnect.
That warning appears because you don't use that function, to fix that warning you just need to use that function somewhere in your script or simply ignore it.
Reply
#6

Okay but let's say that i'm looking for tiki's and first tiki I found is actually the last one. it'll trigger the IsPlayerPickedUpAllTiki?

I mean, I want if players have founded 49 tiki's, no matter what numbers, the 50th tiki will gave the bonus that I will script?
Reply
#7

Quote:
Originally Posted by VikThor
Посмотреть сообщение
Okay but let's say that i'm looking for tiki's and first tiki I found is actually the last one. it'll trigger the IsPlayerPickedUpAllTiki?

I mean, I want if players have founded 49 tiki's, no matter what numbers, the 50th tiki will gave the bonus that I will script?
No that's not a callback, IsPlayerPickedUpAllTiki is a function to check if player has picked up all tikis.

You can add some codes under OnPlayerPickUpPickup or OnPlayerPickTiki to check if the picked tiki is the last one.
Reply
#8

Quote:
Originally Posted by VikThor
Посмотреть сообщение
Okay but let's say that i'm looking for tiki's and first tiki I found is actually the last one. it'll trigger the IsPlayerPickedUpAllTiki?

I mean, I want if players have founded 49 tiki's, no matter what numbers, the 50th tiki will gave the bonus that I will script?
If you want each player to have saved the amount of tikis they've picked up, I would recommend to save this.

Make an array/variable that can identify it's the player picking it up. A per-player variable can look like:

Код:
new PlayerPickups[MAX_PLAYERS];
This will let you save the values of each and every player online. But remember to clear them out when the player leaves, or the next player that join with the same playerid will get the amount in his statistics.

And whenever someone picks up a tiki, you may increment the value for the player.

Код:
PlayerPickups[playerid] +=1;
Please note this is just an example, and it's to guide you to make something you wanted to do.
In order to let the players have this value available on their accounts, you would need to save it to a file or a Database, so you can load it when they log in again.

EDIT: after what i can see, this should already be done in the script above. It's per-player defined and not if the last player picked the last one only as you were afraid of.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)