Jump to content
  • 0

how to make these scripts reset itself


Rizta

Question


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.01
  • Content Count:  109
  • Reputation:   5
  • Joined:  08/12/17
  • Last Seen:  

As in the title i would like to know how can i make these 2 scripts reset itself every a hour. I tried things like OnMinute/OnHour with commands (@reloadnpc or @unload and @load) but i got 0 positive results AND a map server crash ?

Script 1:

Spoiler

//===== rAthena Script =======================================
//= Sample: Dynamic Shop
//===== By: ==================================================
//= Lance
//===== Last Updated: ========================================
//= 20140208
//===== Description: ========================================= 
//= Contains commands needed for a dynamic shop.
//============================================================
// Dummy shop to insert items into:


-	shop	dyn_shop3	-1,501:50.

1@gef_in,30,135,3	script	Vendedor de Poção	749,{

dispbottom "==========================================================";
dispbottom "No momento possuímos "+ $@rpotsleft +"x "+ getitemname(501) +" em estoque!";
dispbottom "No momento possuímos "+ $@opotsleft +"x "+ getitemname(502) +" em estoque!";
dispbottom "No momento possuímos "+ $@ypotsleft +"x "+ getitemname(503) +" em estoque!";
dispbottom "==========================================================";
	
callshop "dyn_shop3",0;
	npcshopattach "dyn_shop3";
	end;

OnSellItem:
	for (.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {
		if (countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {
			mes "omgh4x!";
			close;
		} else if (@sold_nameid[.@i] == 501){
			delitem 501, @sold_quantity[.@i];
			set $@rpotsleft, $@rpotsleft + @sold_quantity[.@i];
			set Zeny, Zeny + @sold_quantity[.@i]*25;
		} else if (@sold_nameid[.@i] == 503){ // novo item aqui	503	
			delitem 503, @sold_quantity[.@i];
			set $@ypotsleft, $@ypotsleft + @sold_quantity[.@i];
			set Zeny, Zeny + @sold_quantity[.@i]*275;
		} else if (@sold_nameid[.@i] == 502){
			delitem 502, @sold_quantity[.@i];
			$@opotsleft += @sold_quantity[.@i];
			set Zeny, Zeny + @sold_quantity[.@i]*100;
		} else {
			mes "________________________________";
			mes "Olá ^0000CD"+strcharinfo(0)+"^000000";
			mes "Eu,só compro os itens que estão na lista!";
			mes "________________________________";
			close;
		}
	}
	deletearray @sold_quantity, getarraysize(@sold_quantity);
	deletearray @sold_nameid, getarraysize(@sold_nameid);
	mes "Negócio fechado.";
	close;

OnBuyItem:
	for (.@i = 0; .@i < getarraysize(@bought_nameid); .@i++){
		if (@bought_quantity[.@i] <= 0){
			mes "omgh4x!";
			close;
		} else if (@bought_nameid[.@i] == 501){
			if (@bought_quantity[.@i] > $@rpotsleft){
				if ($@rpotsleft > 0){
					@bought_quantity[.@i] = $@rpotsleft;
				} else {
					mes "Estamos sem Red Potions!";
					close;
				}
			}
			if (Zeny >= 50*@bought_quantity[.@i]){
				set Zeny, Zeny - 50*@bought_quantity[.@i];
				getitem 501, @bought_quantity[.@i];
				$@rpotsleft -= @bought_quantity[.@i];
			} else {
				mes "Você não tem dinheiro suficiente.";
				close;
			}
		} else if (@bought_nameid[.@i] == 503){
			if (@bought_quantity[.@i] > $@ypotsleft){
				if ($@ypotsleft > 0){
					@bought_quantity[.@i] = $@ypotsleft;
				} else {
					mes "Estamos sem Yellow Potions!";
					close;
				}
			}
			if (Zeny >= 550*@bought_quantity[.@i]){
				set Zeny, Zeny - 550*@bought_quantity[.@i];
				getitem 503, @bought_quantity[.@i];
				$@ypotsleft -= @bought_quantity[.@i];
			} else {
				mes "Você não tem dinheiro suficiente.";
				close;
			}					
		} else /*if (@bought_nameid[.@i] == 502)*/ {
			if (@bought_quantity[.@i] > $@opotsleft){
				if ($@opotsleft > 0){
					@bought_quantity[.@i] = $@opotsleft;
				} else {
					mes "Estamos sem Orange Potions!";
					close;
				}
			}
			if (Zeny >= 200*@bought_quantity[.@i]){
				set Zeny, Zeny - 200*@bought_quantity[.@i];
				getitem 502, @bought_quantity[.@i];
				$@opotsleft -= @bought_quantity[.@i];
			} else {
				mes "Você não tem dinheiro suficiente.";
				close;
			}
		}
	}

	deletearray @bought_quantity, getarraysize(@bought_quantity);
	deletearray @bought_nameid, getarraysize(@bought_nameid);
	mes "Troca encerrada.";
	close;

OnInit:
	npcshopitem "dyn_shop3", 501,50,502,200,503,550;
	$@rpotsleft =1+(getusers(1))*100-1; // Red Potion
	$@opotsleft =1+(getusers(1))*50-1; // Orange Potion
	$@ypotsleft =1+(getusers(1))*25-1; // Yellow Potion
	end;
}

 

Script 2:

Spoiler

//	Author: Ehwaz
//	Version: 2018/06/01

// Dummy shop to insert items into:
-	shop	Equips	-1,501:50.

celestiaj,59,82,3	script	Vendedor de Equipamentos	666,{
	dispbottom DisplayCurrency(.currency);
	callshop .shop_name$,1;
	npcshopattach .shop_name$;
	end;
OnBuyItem:
	BuyProcess(.priceList, .currency);
OnInit:
	.shop_name$ = "Equips";
	.npcName$ 	= strnpcinfo(1);	//Visiable name
	.currency 	= 6242;				// 0: Zeny, else Item

	setarray .items,13040,rand(1,5),  // Dagger
					13415,rand(1,5),  // 1HSword
					1118,rand(5,20), // 2HSword
					1381,rand(5,20), // 2HAxe
					1545,rand(1,5),  // Mace
					1742,rand(1,5),  // Bow
					1639,rand(1,5),  // Staff
					1403,rand(5,20), // 1HSpear
					1453,rand(10,30),// 2HSpear
					2401,rand(20,50),// Sandals
					2501,rand(20,50),// Hood
					2101,rand(20,50),// Guard
					2211,rand(20,50),// Bandana
					1801,rand(50,100),// Knuckles
					1901,rand(50,100),// Violin
					1950,rand(50,100),// Whip
					1264,rand(50,100);// Katar					
					
	InitItemShop(.items,.shop_name$,.npcName$);
	end;
}

 

Script 2 use the following function to work:

Spoiler

//	Author: Ehwaz
//	Version: 2018/06/03

function	script	GetCurrencyText	{
	.@currency = getarg(0,0);
	return .@currency ? getitemname(.@currency): "Zeny";
}

function	script	DisplayCurrency	{
		.@currency		= getarg(0,0);
		.@textCurrency$ = GetCurrencyText(.@currency);
		if(.@textCurrency$ != "Zeny"){
			.@numCurr$ = "("+countitem(.@currency)+")";
			return "Bem-vind"+(Sex?"o":"a")+" ao Shop de "+ .@textCurrency$ + " " + .@numCurr$;
		}
}

//////////////////////////////////

function	script	InitItemShop	{

	copyarray(.@items[0],getarg(0),getarraysize(getarg(0)));
	
	.@shop_name$ 	= getarg(1);
	.@npcName$ 		= getarg(2);
	.@total_items 	= getarraysize(.@items);

	for(.@i = 0; .@i < .@total_items; .@i+=2){
		
		.@itemid = .@items[.@i];
		.@price  = .@items[.@i+1];
		
		set getvariableofnpc(.priceList[.@itemid],.@npcName$),.@price;
		npcshopadditem .@shop_name$, .@itemid , .@price;
	}

	npcshopdelitem .@shop_name$,501;
}

//////////////////////////////////

function	script	BuyProcess	{

	.@bought_nameid_size = getarraysize(@bought_nameid);
	copyarray(.@price_arr[0],getarg(0),getarraysize(getarg(0)));
	
	.@itemCurrencyId	= getarg(1,0);
	.@isZeny 			= .@itemCurrencyId ? 0 : 1;
	.@textCurrency$		= GetCurrencyText(.@itemCurrencyId);
	.@paid 				= 0;
	
	for (.@i = 0; .@i < .@bought_nameid_size; .@i++){
	
		.@boughtId 	= @bought_nameid[.@i];
		.@quanty 	= @bought_quantity[.@i];
		.@totalPrice = .@price_arr[.@boughtId] * .@quanty;
		.@canPay	= 1;
		
		//Check weight
		if( !checkweight(.@boughtId,.@quanty) )
		{
			message strcharinfo(0),sprintf("Precisa de mais peso para obter %d %s",.@quanty, getitemname(.@boughtId));
			break;
		}
		
		if(.@isZeny)
		{
			if(Zeny >= .@totalPrice){
				Zeny -= .@totalPrice;
				getitem .@boughtId,.@quanty;
				.@paid += .@totalPrice;
			}
			else .@canPay = 0;
		}
		else 
		{
			if(countitem(.@itemCurrencyId) >= .@totalPrice){
				delitem .@itemCurrencyId,.@totalPrice;
				getitem .@boughtId,.@quanty;
				.@paid += .@totalPrice;
			}
			else .@canPay = 0;
		}
		
		if(!.@canPay)
		{
			message strcharinfo(0),sprintf("Não há %s suficiente para pagar %d %s",.@textCurrency$,.@quanty, getitemname(.@boughtId));
			break;
		}	
	}
	
	if(.@paid)
		dispbottom "Pago: "+F_InsertComma(.@paid)+" "+.@textCurrency$+"";
	
	deletearray @bought_quantity, getarraysize(@bought_quantity);
	deletearray @bought_nameid, .@bought_nameid_arr_size;
	end;
}

 

Thx everyone.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  6
  • Topics Per Day:  0.00
  • Content Count:  91
  • Reputation:   22
  • Joined:  10/24/14
  • Last Seen:  

Hey, you can use OnHour event with donpcevent "npcname::OnInit";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...