Jump to content
  • 0
Sign in to follow this  
Tsuuu

how to optimize this script

Question

Hi, I'm pretty junior in programming, but I can still do some things through if and else (jejeje), I made this custom script to rank my WoE, the script is 100% functional, I would like to know how to optimize it Because I think too many checks can weigh my script and overload my server since a WoE can be very busy, can someone more experienced tell me a way to optimize this script? An example will already serve as a template for other scripts of mine.

OnPCKillEvent:
	if(agitcheck() || agitcheck2())
	{
		getmapxy @map$,@x,@y,0;
		if(@map$ == "prtg_cas01" || @map$ == "arug_cas03")  //Edite aqui os mapas dos castelos ativos na woe
		{
			matounawoe += 1;
			woematancacons += 1;
			dispbottom "[WoE] Você Matou: "+matounawoe+".";
			dispbottom "[WoE] Você Morreu: "+morreunawoe+".";
			dispbottom "[WoE] Matança Consecutiva: "+woematancacons+".";
			
			if(woematancacons == 10)
			{
				mapannounce(strcharinfo(3), "[WoE] O jogador "+strcharinfo(0)+" matou 10 sem morrer e está em matança consecutiva.", bc_map, 0xFFCE00);
			}
			
			if(woematancacons == 20)
			{
				announce "[WoE] O jogador "+strcharinfo(0)+" matou 20 sem morrer, alguém precisa pará-lo.",bc_all, 0xFFCE00;
			}
			
			query_sql "SELECT `char_name`,`matou`,`morreu`,`matou_sem_morrer`,`mt_sem_mr_perma` FROM `woe_rank` WHERE `char_id` = "+getcharid(0)+" AND `char_name` = '"+strcharinfo(0)+"'",@nome$,@PvPPoints,@morreu,@matou_sem_m,@mt_sem_mr_perma;
			
			if(@nome$ == ""){
				query_sql "INSERT INTO `woe_rank` (`char_id`, `char_name`, `matou`, `pontos`, `matou_sem_morrer`) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',1,1,1)";
			} else { 
				if(woematancacons > @matou_sem_m)
				{
					mtsemmrperma = woematancacons;
					query_sql "UPDATE `woe_rank` SET `matou_sem_morrer` = "+woematancacons+" WHERE `char_id`="+getcharid(0)+" AND `char_name` = '"+strcharinfo(0)+"'";
				}
				if(mtsemmrperma > @mt_sem_mr_perma)
				{
					query_sql "UPDATE `woe_rank` SET `mt_sem_mr_perma` = "+mtsemmrperma+" WHERE `char_id`="+getcharid(0)+" ";
				}
				query_sql "UPDATE `woe_rank` SET `matou` = "+matounawoe+", `pontos` = "+matounawoe+"-"+morreunawoe+" WHERE `char_id`="+getcharid(0)+" AND `char_name` = '"+strcharinfo(0)+"'";
			}
		}
	}
end;

Thank you in advance...

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 1

In my opinion, best thing to do is to save all data as char_reg variables, e.g.
WoE_Kill += 1; 

And then once WoE is finished, run a SQL query to copy data from char_reg_num_db and char_reg_str_db to your custom table. E.g.

OnAgitEnd:
    query_sql("TRUNCATE TABLE `woe_rank`;"); // clear old data. this table is only used to hold temporary values for displaying elsewhere
    .@count = query_sql("SELECT `char_id`, `value` FROM `char_reg_num_db` WHERE `key` = 'WoE_Kill';", .@CID, .@WoE_Kill);
    for (.@i = 0; .@i < .@count; .@i++) {
        query_sql(sprintf("INSERT INTO `woe_rank`(`char_id`, `kills`) VALUES(%d, %d);", .@CID, .@WoE_Kill));
        sleep(50); // don't perform too many queries at once (20 per second)
    }
    end;

So then the query_sql() command is only being run under controlled circumstances, and only used once.

Edited by bWolfie

Share this post


Link to post
Share on other sites
  • 0
37 minutes ago, bWolfie said:

In my opinion.

 

Exactly what I expected.

Thank you so much for wasting a little of your time with me, you're beast, optimized cool ... :lv:

Share this post


Link to post
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.   Restore formatting

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.