Jump to content
  • 0

Raffle Event NPC


Lion

Question


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.02
  • Content Count:  3
  • Reputation:   1
  • Joined:  03/11/24
  • Last Seen:  

Hello Guys, firstly I would like to thank anyone for support, tips or help in resolving this issue.

I'm a newbie in this matter of scripting NPC's, i made some searchs but not found something similar. I need help to create an NPC with these conditions:

I will have a list of grand prizes and consolation prizes, the price for attempt and the odds.

like: 
Raffle          Grand Prize           Consolation Prize         Price to try                Chance to get the grand prize
  01             Item ID X1                  Item ID Y1                 V1 zeny                                     %W1

  02             Item ID X2                  Item ID Y2                 V2 zeny                                     %W2

   .                       .                                   .                              .                                             .

   .                       .                                   .                              .                                             .

   .                       .                                   .                              .                                             .

 XX             Item ID Xn                   Item ID Yn                 Vn zeny                                     %Wn

 

The NPC will randomly choose one of the options from the list (Raffle column) , and then, the raffle will be available with the respectives attributes for the players to try to win the grand prize under the following conditions: If someone wins, a new raffle will be chosen randomly, if no one wins the grand prize in the last x minutes, a new raffle will be randomly chosen, and may even be the same. 

If possible I would like to announce to the entire server when a new raffle is available, and what the grand prize and consolation prize are.

Any help or guidance is greatly appreciated!

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  132
  • Reputation:   53
  • Joined:  06/02/12
  • Last Seen:  

Hello. Your script is looking good, great start.

You can test this one, maybe you learn something, I tried doing what you requested.

//Converts ratio to return actual number with decimals.
//10000=100%  1000=10%  100=1%  10=0,1%  1=0,01%
function	script	F_ConvertRatio	{
	.@n = getarg(0);
	if (.@n%100 && .@n > 100 && .@n < 1000 && atoi(charat(""+.@n, 1)) == 0 || .@n < 10)
		.@n2$ = .@n/100 + (.@n%100?",0"+.@n%100:"");
	else if (.@n%100 && .@n > 9 && .@n < 1000 && atoi(charat(""+.@n, getstrlen(""+.@n)-1)) == 0)
		.@n2$ = .@n/100 + "," + (.@n%100)/10;
	else
		.@n2$ = .@n/100 + (.@n%100?","+.@n%100:"");
	return .@n2$;
}

prontera,113,246,5	script	Rafa da Rifa	1_F_PUBGIRL,{
	cutin "job_dancer_eir01", 0;
	mes "[" + strnpcinfo(1) + "]";
	mes "Você quer participar da minha rifa?";
	mes "Ai, que pergunta, né? É claro que quer!";
	mes "Pelo generosíssimo valor de ^0000FF" + F_InsertComma($@raffle_cost) + "z^000000, você concorre a";
	mes "" + $@raffle_prize_qty + " [<ITEM>" + getitemname($@raffle_prize_id) + "<INFO>" + $@raffle_prize_id + "</INFO></ITEM>].";			
	next;
	if (isnpccloaked()) goto S_Restarting;
	.@i = rand(20,40);
	mes "[" + strnpcinfo(1) + "]";
	mes "Você precisa tirar o número ^FF0000" + .@i + "^000000 pra ganhar ^00FF00" + getitemname($@raffle_prize_id) + "^000000.";
	mes "Mas primeiro, preciso dos ^0000FF" + F_InsertComma($@raffle_cost) + "z^000000.";
	mes "O que me diz?";
	next;
	if(select("Tá OK! Lá vamos nós...", "Não, obrigad" + (Sex?"o":"a") + ".") == 2) {
		mes "[" + strnpcinfo(1) + "]";
		mes "Não tá confiante?";
		close3;
	}
	if (Zeny < $@raffle_cost) {
		mes "[" + strnpcinfo(1) + "]";
		mes "Você não tem o zeny para participar?";
		close3;
	}
	if (checkweight(1301,1) == 0) {
		mes "[" + strnpcinfo(1) + "]";
		mes "Você tá com uma mochila bem pesada em...";
		mes "Como você vai receber o prêmio desse jeito?";
		close3;
	}
	if (isnpccloaked()) goto S_Restarting;
	Zeny -= $@raffle_cost;
	mes "[" + strnpcinfo(1) + "]";
	mes "O número do prêmio é ^FF0000" + .@i + "^000000.";

	if (rand(10000) > $@raffle_chance) {
		.@l = rand(.@i-19,.@i+19);
		showdigit .@l;
		mes "Você tirou o número ^0000FF" + .@l + "^000000.";
		mes "Não foi dessa vez. Mas e se você tentar de novo?";
		mes "Aliás, aqui está o seu prêmio de consolação!";
		getitem $@raffle_consol_id, rand($@raffle_consol_min,$@raffle_consol_max);
		close3;
	}
	showdigit .@i;
	mes "Você tirou o número ^0000FF" + .@i + "^000000.";
	mes "... Peraí, você ganhou? É isso mesmo, produção?";
	mes "Hoje é o seu dia!";
	getitem $@raffle_prize_id, $@raffle_prize_qty;
	announce "" + strnpcinfo(1) + " : Parabéns! " + strcharinfo(0) + " recebeu " + $@raffle_prize_qty + " " + itemlink($@raffle_prize_id) + " na Rifa!", bc_all;
	specialeffect2 EF_PROVIDENCE;
	donpcevent strnpcinfo(3)+"::OnStart";
	close3;

S_Restarting:
	mes "[" + strnpcinfo(1) + "]";
	mes "Nossa, essa rifa acabou bem quando estávamos conversando.";
	mes "Você vai ter que tentar a sorte na nova rifa.";
	close3;

OnInit:
	bindatcmd "rifa",strnpcinfo(3)+"::OnGM", 99, 99;
	setarray .rifas,

		//Cada linha é uma rifa diferente
		//<grand prize>,<grand prize amount>,<consolation prize>,<consolation min amount>,<consolation max amount>,<cost>,<win chance 1~10000>,
	
		970  , 30 , 7136 , 1, 20,  40000 , 100, 
		12264, 5  , 7135 , 1, 20,  100000, 100, 
		12928, 5  , 678  , 1, 10,  100000, 200, 
		7938 , 100, 7939 , 1, 50,  100000, 100, 
		6962 , 1  , 7139 , 1, 20,  150000, 125, 
		7620 , 10 , 984  , 1, 15,  150000, 125, 
		7619 , 10 , 985  , 1, 15,  200000, 200, 
		12412, 1  , 6259 , 1, 40,  300000, 40,
		23546, 1  , 1061 , 1, 400, 500000, 200, 
		6635 , 1  , 23044, 1, 10,  600000, 50;

// 1200000 = 20 minutos
OnTimer1200000:
OnStart:
	stopnpctimer;
	cloakonnpc strnpcinfo(0);
	sleep 10000;
	.@r = rand(getarraysize(.rifas)/7) *7;
	$@raffle_prize_id = .rifas[.@r];
	$@raffle_prize_qty = .rifas[.@r+1];
	$@raffle_consol_id = .rifas[.@r+2];
	$@raffle_consol_min = .rifas[.@r+3];
	$@raffle_consol_max = .rifas[.@r+4];
	$@raffle_cost = .rifas[.@r+5];
	$@raffle_chance = .rifas[.@r+6];

	announce "A Rafa gostaria de convidar a todos a participarem de sua Rifa, na biblioteca ao oeste de Prontera!", bc_all;
	cloakoffnpc strnpcinfo(0);
	initnpctimer;
	sleep 5000;
	announce "" + strnpcinfo(1) + " : O grande prêmio é " + ($@raffle_prize_qty>1?$@raffle_prize_qty+"x ":"") + itemlink($@raffle_prize_id) + "! E o prêmio de consolação é " + itemlink($@raffle_consol_id) + " " + $@raffle_consol_min + "~" + $@raffle_consol_max + "x!", bc_all;
	npctalk "Este aqui é um prêmio especial que aparece só de vez em quando, então se eu fosse você, eu participaria!";
	end;

OnGM:
	message strcharinfo(0), "Esses são comandos especiais que apenas você ADMs e GMs podem usar.";
	switch(select("Cancelar", "^0000FFVer rifa atual^000000", "^0000FFVer rifas^000000", "^0000FFIniciar nova rifa^000000")) {
		case 1:
			end;
		case 2:
			if (isnpccloaked()) {
				message strcharinfo(0), "RIFA EM PROCESSO DE REINICIAR";
				end;
			}
			mes "^0000FFPrêmio:^000000";
			mes "^0000FF[<ITEM>" + getitemname($@raffle_prize_id) + "<INFO>" + $@raffle_prize_id + "</INFO></ITEM>] " + $@raffle_prize_qty + "x^000000";
			mes "^FF0000Consolação:^000000";
			mes "^FF0000[<ITEM>" + getitemname($@raffle_consol_id) + "<INFO>" + $@raffle_consol_id + "</INFO></ITEM>] " +  $@raffle_consol_min + "~" +  $@raffle_consol_max +"x^000000";
			mes "Preço: " + F_InsertComma($@raffle_cost) + "z";
			mes "Chance do prêmio: " + F_ConvertRatio($@raffle_chance) + "%";
			mes "Iniciada faz " + (getnpctimer(0)/1000) + " segundos.";
			close;
		case 3:
			.@size = getarraysize(.rifas)/7;
			for( .@i = 0; .@i < .@size; .@i++ ) {
				.@r = .@i * 7;
				mes "^0000FFRifa " + (.@i+1) + " - Prêmio:^000000";
				mes "^0000FF[<ITEM>" + getitemname(.rifas[.@r]) + "<INFO>" + .rifas[.@r] + "</INFO></ITEM>] " + .rifas[.@r+1] + "x^000000";
				mes "^FF0000Consolação:^000000";
				mes "^FF0000[<ITEM>" + getitemname(.rifas[.@r+2]) + "<INFO>" + .rifas[.@r+2] + "</INFO></ITEM>] " + .rifas[.@r+3] + "~" + .rifas[.@r+4] +"x^000000";
				mes "Preço: " + F_InsertComma(.rifas[.@r+5]) + "z";
				mes "Chance do prêmio: " + F_ConvertRatio(.rifas[.@r+6]) + "%";
				if (.@i < .@size-1) {
					if(select("Ver outra rifa","Fechar") == 1)
						clear;
					else
						break;
				}
			}
			close;
		case 4:
			donpcevent strnpcinfo(3)+"::OnStart";
			end;
	}
}

prontera,115,246,3	script	Rifa#raffle_board	2_BULLETIN_BOARD,{
	mes "^0000FFGrande prêmio da Rifa:^000000";
	mes "^0000FF[<ITEM>" + getitemname($@raffle_prize_id) + "<INFO>" + $@raffle_prize_id + "</INFO></ITEM>] " + $@raffle_prize_qty + "x^000000";
	mes " ";
	mes "^FF0000Prêmio de Consolação:^000000";
	mes "^FF0000[<ITEM>" + getitemname($@raffle_consol_id) + "<INFO>" + $@raffle_consol_id + "</INFO></ITEM>] " +  $@raffle_consol_min + "~" +  $@raffle_consol_max +"x^000000";
	mes " ";
	mes "Preço: " + F_InsertComma($@raffle_cost) + "z";
	close;
}

Using initnpctimer and stopnpctimer you can automate the raffle change. Example:

OnInit:
	// set the first raffle when the server starts.
	initnpctimer; //start the timer
	end;

OnTimer60000:
	//after 60 seconds this part will trigger
	//change the raffle array to new values.
	stopnpctimer; //erase the old timer
	initnpctimer; //start the timer again from 0
	end;

 

  • Like 3
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.02
  • Content Count:  3
  • Reputation:   1
  • Joined:  03/11/24
  • Last Seen:  

Good night guys, i'm working on the script since yesterday and got some good results that i would like to share with you. At the moment, i think i done some of the main part of the script, added some securities checks for Zeny, weight and inventory space. Yet i need to learn about npc events, how to set a timer and a condition to restart the npc event.

At the moment i want to give a special thanks to @GmOcean for the excellent beginners guide who helped me out and give me some directions to how start my scripting. Second  for all other users who made/answer questions that somehow helped me out with my issues of how do or declare things etc.

Below is the code i've made so far, it's not complete or optimized, but it express part of my initial request.

prontera,128,200,6	script	Testinho	94,{
	.@npc_name$ = "[^FF0000 Testinho ^000000]";
	mes .@npc_name$;
	mes "Olá, seja bem vindo ao senhor das rifas";
	.@index = rand(getarraysize(.raffle));
	next;
	mes "Gostaria de participar da rifa de hoje?";
	mes "O prêmio principal será:";
	mes "x"+.Grand_Prize_Amount[.@index]+" ^228B22"+ .Grand_Prize_T$[.@index];
	mes "";
	mes "O prêmio de ^FF0000 Consolação ^000000 será:";
	mes "x"+.Consolation_Prize_Amount[.@index]+" "+ .Consolation_Prize_T$[.@index];
	mes "O valor da rifa é de ^FF0000"+ .zeny_required[.@index] +"^000000 Zenys";
	next;
	switch( select("Tentar a sorte", "Hoje não Juvenal") ) {
		case 1:
			if (Zeny <= .zeny_required[.@index]) {
				mes "Você nao tem ^FF0000"+ .zeny_required[.@index] +"^000000 Zenys para participar da Rifa!";
				close;
			}
			.@weight = 100 * Weight / MaxWeight;
			getinventorylist;
			if (.@weight > 50) || ((100 - @inventorylist_count ) < 6) {
				mes "Verifique se voce esta sobrecarregado ou com o inventário próximo do limite!";
				close;				
			}
			.@p1 = (rand(1000)+1);
			mes "Sua chance de ganhar e de "+ (.odds[.@index]/10) +"%";
			next;
			mes "Sua sorte hoje é o número - ^FF9900"+ .@p1 +".";
			if (.@p1 <= .odds[.@index]) {
				mes "Parabéns voce ganhou o grande premio:";
				mes "x"+ .Grand_Prize_Amount[.@index] +" ^228B22"+ .Grand_Prize_T$[.@index];
				Zeny -= .zeny_required[.@index];
				getitem .Grand_Prize$[.@index], .Grand_Prize_Amount[.@index];
				close;
			}
			else{
				mes "Infelizmente nao foi dessa vez, seu premio de consolacao e:";
				mes "x"+ .Consolation_Prize_Amount[.@index] +" ^0000FF"+ .Consolation_Prize_T$;
				Zeny -= .zeny_required[.@index];
				getitem .Consolation_Prize$[.@index], .Consolation_Prize_Amount[.@index];
			close;
			}
	
	}
	close;

OnInit:
	setarray .raffle[0], 0, 1, 2, 3, 4;
	setarray .Grand_Prize$[0], "Red_Potion", "White_Potion", "Blue_Potion", "Tha_Maero_Card", "Poring_Card";
	setarray .Grand_Prize_T$[0], "Poções Vermelhas", "Poções Brancas", "Poções Azuis", "Carta Memória de Thanatos", "Carta Poring";
	setarray .Grand_Prize_Amount[0], 20, 30, 5, 50, 25;
	setarray .Consolation_Prize$[0], "Red_Potion", "White_Potion", "Blue_Potion", "Jellopy", "Stone_Fragments";
	setarray .Consolation_Prize_T$[0], "Poções Vermelhas", "Poções Brancas", "Poções Azuis", "Jellopy", "Fragmentos de Pedra";
	setarray .Consolation_Prize_Amount[0], 1, 1, 1, 50, 5;
	setarray .zeny_required[0], 500, 1500, 10000, 2500000, 999;
	setarray .odds[0], 150, 350, 450, 30, 500;
end;
}

I'll keep updating this thread until the script is finished the way i envisioned.

Please point out any gross errors you find in the code, as it is the first version, there is certainly a lot to be added and improved. There are also some parts of the code written in my native language, since the server i intend to develop will be in it, I need to adapt the texts to my language.

For anyone who needs learn some basics/intermediate knowledge of scripting, i recommend take a look in the GM Ocean Tutorial for Beginners:

https://rathena.org/board/topic/98856-scripting-techniques-tutorialsguides/

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.02
  • Content Count:  3
  • Reputation:   1
  • Joined:  03/11/24
  • Last Seen:  

Posted (edited)

Hello Racaae, thx for your help! i'm testing your script now, and he looks really clean and with more features than i expected! I noticed that some time when even if the player gets the right number of the raffle (win codition) he not get the grand prize istead the npc gives to the player the consolation prize.

Spoiler

image.png.6871c6dc380c82777bcaea1e86e2cbd2.png

I've made some changes on my original code yesterday before read your post and here is what my actual  raffle script is:

prontera,161,188,4	script	Ana da Rifa	4_F_PINKWOMAN,{
	.@npc_name$ = "[^FF09FF Ana ^000000]";
	mes .@npc_name$;
	if ((gettimetick(2) - .last_participation_time) <= 3) {
	mes "Você já comprou uma rifa recentemente, aguarde um instante...";
	close;
	}
	mes "Olá, seja bem-vindo(a) ao nosso sistema de rifas!";
	mes "Temos vários prêmios interessantes que podem te ajudar em sua jornada!";
	next;
	mes "Gostaria de participar da rifa do momento?";
	mes "O prêmio ^FFAF22 PRINCIPAL ^000000 será: ";
	mes "x"+.Grand_Prize_Amount[.index]+" ^477FEE"+ .Grand_Prize_T$[.index];
	mes "-------------------------------------------";
	mes "O prêmio de ^FF0000 consolação ^000000 será: ";
	mes "x"+.Consolation_Prize_Amount[.index]+" ^895818"+ .Consolation_Prize_T$[.index];
	mes "O valor da rifa é de ^FF0000"+ .zeny_required[.index] +"^000000 Zenys";
	next;
	switch( select("Tentar a sorte!", "Hoje não.") ) {
		case 1:
			if (Zeny <= .zeny_required[.index]) {
				mes "Você não tem ^FF0000"+ .zeny_required[.index] +"^000000 Zenys para participar da Rifa!";
				close;
			}
			.@weight = 100 * Weight / MaxWeight;
			getinventorylist;
			if (.@weight > 50) || ((100 - @inventorylist_count ) < 6) {
				mes "Verifique se você esta sobrecarregado ou com o inventário próximo do limite!";
				close;				
			}
			.@p1 = (rand(1000)+1);
			mes "Sua chance de ganhar é de "+ (.odds[.index]/10) +"%";
			next;
			mes "Sua sorte hoje é o número - ^FF9900"+ .@p1 +".";
			if (.@p1 <= .odds[.index]) {
				mes "Parabéns voce ganhou o grande prêmio:";
				mes "x"+ .Grand_Prize_Amount[.index] +" ^477FEE"+ .Grand_Prize_T$[.index];
				Zeny -= .zeny_required[.index];
				getitem .Grand_Prize$[.index], .Grand_Prize_Amount[.index];
				mapannounce .map$, "O jogador "+ strcharinfo(0) +" foi o vencedor da atual rifa!", 0, 0xFCE516;
				close2;
				goto OnInit;
			}
			else{
				.last_participation_time = gettimetick(2);
				mes "Infelizmente não foi desta vez, seu prêmio de consolação é: ";
				mes "x"+ .Consolation_Prize_Amount[.index] +" ^895818"+ .Consolation_Prize_T$[.index];
				Zeny -= .zeny_required[.index];
				getitem .Consolation_Prize$[.index], .Consolation_Prize_Amount[.index];
			close;
			}
	
	}
	close;

OnInit: OnTimer600000: initnpctimer;
	.map$ = "prontera";
	hideonnpc "Ana da Rifa";
	sleep 12000;
	hideoffnpc "Ana da Rifa";
	setarray .raffle[0], 0, 1, 2, 3, 4;
	setarray .Grand_Prize$[0], "Red_Potion", "White_Potion", "Blue_Potion", "Tha_Maero_Card", "Poring_Card";
	setarray .Grand_Prize_T$[0], "Poções Vermelhas", "Poções Brancas", "Poções Azuis", "Carta Memória de Thanatos", "Carta Poring";
	setarray .Grand_Prize_Amount[0], 20, 30, 5, 50, 25;
	setarray .Consolation_Prize$[0], "Red_Potion", "White_Potion", "Blue_Potion", "Jellopy", "Stone_Fragments";
	setarray .Consolation_Prize_T$[0], "Poção Vermelha", "Poção Branca", "Poção Azul", "Jellopys", "Fragmentos de Pedra";
	setarray .Consolation_Prize_Amount[0], 1, 1, 1, 50, 5;
	setarray .zeny_required[0], 500, 1500, 10000, 2500000, 999;
	setarray .odds[0], 500, 350, 450, 30, 500;
	.index = rand(getarraysize(.raffle));
	announce "Olá, uma nova rifa está disponível! O prêmio no momento para o ganhador é x"+ .Grand_Prize_Amount[.index]+ " " + .Grand_Prize_T$[.index] +", e para quem não conseguir, o prêmio de consolação será x"+ .Consolation_Prize_Amount[.index]+ " " + .Consolation_Prize_T$[.index] + ", a chance de ganhar o prêmio é de "+ (.odds[.index]/10) +"%." , 0, 0x7AF6EE;
end;
}

Some of the changes:

Spoiler

added a CD timer to try the raffle, to slow the players who have macro programs for that purpose.

added a CD timer when someones wins the raflle.

added a restart condition to the npc for when someone wins or 10 minutes passed without a winner.

others minor changes like announces, string changes, colors etc.

Yet i need to fix a problem when one player wins and the others are  chatting with the NPC they also get one last chance to win, but i see in your code the solution (check if the npcs is cloaked before the prize results, if true, go to restarting label!)

Thank you very much Racaae for coding my request and for the insights it gives me, I will try to understand the complete code to improve my scripting skills!🙂

I will make some changes based on Raccae's code and in a few days i will share it here.

Edited by Lion
added some new information.
  • Like 1
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...