Jump to content

[Include] Treasure Hunt


Zooky
 Share

Recommended Posts

Pentru a rula acest "include", va va trebui y_hooks si y_timers. (https://leaks.ro/index.php?/topic/84-ysi-includes-versiune-402-ultima-versiune/)
Daca vreti sa afisati si zona unde s-a spawnat, folositi include-ul: http://forum.sa-mp.c...ead.php?t=27598
 
Codul nu a fost testat, a fost doar compilat si nu a avut erori.
Daca gasiti bug-uri sau aveti probleme, lasati un comentariu si poate va ajuta un scripter care se uita peste topicul asta!
Daca nu, o sa va raspund eu. Cred..
 
Am adaugat un singur premiu in shop-ul treasure. Daca vreti voi mai multe, le adaugati voi.
Variabilele pentru bani, level si punctele treasure sunt niste variabile temporare. Voi trebuie sa le inlocuiti cu variabilele voastre de level / bani / puncte.
 
Pentru a modifica anumite chestii, puteti sa schimbati valorile sub "Configurari". Si aveti grija la dialog-ul pe care l-am definit. Posibil ca voi sa aveti deja un dialog cu id-ul 0.
Daca aveti probleme cu spawnarea obiectului la primul start de server, mutati ce e sub hook OnGamemodeInit in public OnGamemodeInit.
Oricum nu va recomand sa folositi y_hooks daca nu aveti un gamemode modular (pe mai multe fisiere), deci cel mai ok e sa includeti codul asta in proiectul vostru.

#include <YSI\y_hooks>
#include <YSI\y_timers>

#define COLOR_DARK_BLUE 0x43AACCFF
#define DIALOG_TREASURE_CHEST 0

forward SpawnQuestObject();

/* Configurari */

#define MAX_TREASURE_POINTS 70
#define MIN_TREASURE_POINTS 10

#define MAX_TREASURE_MONEY 200000
#define MIN_TREASURE_MONEY 50000

#define LOCATIONS 1 /* !! Numarul de aici trebuie sa fie EGAL cu totalul locatiilor adaugate de tine. In cazul "default", este setat pe 1 pt ca e o singura locatie. !! */

#define PICKUP_SPAWN_TIME 30 //Timpul in care se spawneaza un obiect. (In minute)
#define PICKUP_DESPAWN_TIME 60 //Timpul in care se despawneaza un obiect. (In minute)

/* ----------- */

new Float: random_pickups[LOCATIONS][3] = 
{
	{0.0000, 0.0000, 0.0000}
};

new 
	p_treasure_points[MAX_PLAYERS],
	p_level[MAX_PLAYERS],
	p_money[MAX_PLAYERS],
	pickup_id,
	pickup_spawned = false,
	Timer: pickup_timer;


hook OnGameModeInit()
{
	SpawnQuestObject(); //Spawnam obiectul pentru prima oara.
	return 1;
}

hook OnPlayerConnect(playerid)
{
	p_treasure_points[playerid] = 0;
	p_level[playerid] = 1;
	p_money[playerid] = 0;
	return 1;
}

CMD:treasureshop(playerid)
{
	new header[128]; format(header, sizeof(header), "Treasure points: {43AACC}%d", p_treasure_points[playerid]);
	ShowPlayerDialog(playerid, DIALOG_TREASURE_CHEST, DIALOG_STYLE_TABLIST_HEADERS, header, "Item\tPoints\t\nLevel up\t30 treasure points", "Buy", "Exit");
	return 1;
}

timer OnPickupSpawn[PICKUP_SPAWN_TIME * 60000]() SpawnQuestObject();

timer OnPickupDespawn[PICKUP_DESPAWN_TIME * 60000]()
{
	if(IsValidDynamicPickup(pickup_id) && pickup_spawned)
	{
		SendClientMessageToAll(COLOR_DARK_BLUE, "(Treasure Hunt) {FFFFFF} Obiectul nu a fost gasit.");
		SendClientMessageToAll(COLOR_DARK_BLUE, "(Treasure Hunt) {FFFFFF} Un obiect nou va fi spawnat in aproximativ 30 de minute.");

		DestroyDynamicPickup(pickup_id);

		pickup_id = 0;
		pickup_spawned = false;

		stop pickup_timer;

		defer OnPickupSpawn();
	}
}

public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
	if(pickupid == pickup_id)
	{
		new 
			string[256], 
			p_name[MAX_PLAYER_NAME], 
			points = random(MAX_TREASURE_POINTS - MIN_TREASURE_POINTS) + MIN_TREASURE_POINTS, 
			money = random(MAX_TREASURE_MONEY - MIN_TREASURE_MONEY) + MIN_TREASURE_MONEY;

		GetPlayerName(playerid, p_name, sizeof(p_name));

		format(string, sizeof(string), "(Treasure Hunt) {FFFFFF}Un obiect ascuns a fost gasit de catre %s. Acesta a primit un premiu special in valoare de %d treasure points.", p_name, points); //Posibil sa nu incapa pe un rand, nu am vrut sa va dau si functia cu linii mai multe cu acelasi string.
		SendClientMessageToAll(COLOR_DARK_BLUE, string);

		SendClientMessageToAll(COLOR_DARK_BLUE, "(Treasure Hunt) {FFFFFF}Un alt obiect va fi spawnat in aproximativ 30 minute.");

		format(string, sizeof(string), "(Treasure Hunt) {FFFFFF}Ai primit drept rasplata %d treasure Points + %s$.", points, FormatNumber(money));
		SendClientMessage(playerid, COLOR_DARK_BLUE, string);

		p_money[playerid] += money;
		p_treasure_points[playerid] += points;

		GivePlayerMoney(playerid, money);

		DestroyDynamicPickup(pickupid);

		pickup_id = 0;
		pickup_spawned = false;

		stop OnPickupDespawn();
		defer OnPickupSpawn();


	}
	return 1;
}

public SpawnQuestObject()
{
	new rand = random(sizeof(random_pickups));

	pickup_id = CreateDynamicPickup(1247, 1, random_pickups[rand][0], random_pickups[rand][1], random_pickups[rand][2]);
	pickup_spawned = true;

	SendClientMessageToAll(COLOR_DARK_BLUE, "(Treasure Hunt) {FFFFFF} Un obiect a fost spawnat!");
	SendClientMessageToAll(COLOR_DARK_BLUE, "(Treasure Hunt) {FFFFFF} Daca acest obiect nu va fi gasit intr-un interval de 60 minute, serverul va spawna alt obiect.");

	// Daca folosesi zones.inc (formateaza tu textul cum trebuie)
	// SendClientMessageToAll(COLOR_DARK_BLUE, "(Treasure Hunt) {FFFFFF} Hint: Obiectul se afla in zona X");

	pickup_timer = defer OnPickupDespawn();
	return 1;
}

hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		case DIALOG_TREASURE_CHEST:
		{
			if(response)
			{
				switch(listitem)
				{
					case 0: //Level up (30 puncte)
					{
						if(p_treasure_points[playerid] < 30) return SendClientMessage(playerid, COLOR_DARK_BLUE, "(Treasure Shop) {FFFFFF} You don't have 30 treasuer points.");

						p_treasure_points[playerid] -= 30;
						p_level[playerid]++;

						SetPlayerScore(playerid, p_level[playerid]);

						SendClientMessage(playerid, COLOR_DARK_BLUE, "(Treasure Shop) {FFFFFF} You have leveled up!");
					}
				}
			}
		}
	}
	return 1;
}

// Nu mai stiu a facut stock-ul asta, dar creditele sunt ale lui.
stock FormatNumber(number)
{
	new numOfPeriods = 0, tmp = number;
	new str[32];
	while(tmp > 1000) {
		tmp = floatround(tmp / 1000, floatround_floor), ++numOfPeriods;
	}
	valstr(str, number);
	new slen = strlen(str);
	for(new i = 1; i != numOfPeriods + 1; ++i) {
		strins(str, ",", slen - 3*i);
	}
	return str;
} 

Credite: Ksenon.

 
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...