Jump to content
  • 0

i want script npc reward


tonikh

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  25
  • Reputation:   0
  • Joined:  07/01/12
  • Last Seen:  

hi all

 

 

i want npc can get reward for all players online in the server

 

 

and i want , the GM could choose the items reward in everytime.

 

 

"Sry i bad speak english" and please help me.. thx

Link to comment
Share on other sites

8 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

Browse through Emistry's script collection  /no1

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  52
  • Reputation:   3
  • Joined:  01/05/12
  • Last Seen:  

query_sql("select name from char where online = 1",@name$)

 

explode(@name$)

 

and and and ^^^^^^

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  43
  • Reputation:   15
  • Joined:  06/24/12
  • Last Seen:  

Basically:

-	scrip	PmThisScript	-1,{
OnWhisperGlobal:
if(getgroupid != 99) end;
if(!@whispervar0$)
{
	dispbottom "Be sure to tell me the ID of the item you want to prize all the online characters.";
	dispbottom "[PM to npc:PmThisScript] : <item_id>#<item_quantity>";
	dispbottom "Example:";
	dispbottom "npc:PmThisScript | 999#10";
	dispbottom "This will give 10 "+getitemname(999)+" to all online characters.";
	end;
}
if( ! (.@give_this_id = atoi(@whispervar0$)) || ! (.@at_this_quantity = atoi(@whispervar1$) || ! getitemname(.@give_this_id) )
{
	dispbottom "The given ID couldn't be processed.";
	dispbottom "Be sure to use only numeric values and checked item IDs.";
	end;
}

.@return_to = getcharid(3);

// After-checking, let's do the dirty job!
query_sql("SELECT `account_id` FROM `login` DESC LIMIT 0,1", .@num);
for( .@i = 2000000; .@i < .@num[0]; .@i++)
{
	if( isloggedin(.@i) )
	{
	attachrid(.@i);
	getitem .@give_this_id, .@at_this_quantity;
	}
}

if( ! attachrid(.@return_to) )
{
	debugmes "The Administrator couldn't be contacted through the ACCOUNT_ID["+.@return_to+"]!";
	end;
}
dispbottom .@at_this_quantity+" "+getitemname(.@give_this_id)+" had been successfully given to all online characters!";
end;
I hadn't tested it, be sure to tell me if it doesn't work or if you want a modification on it.

@Edit:

Script fixed accordingly @@Capuche loop-warning. Thank him!

Also removed unnecessary detachrid, as the rid is automatically detached with a new instance of the attachrid command.

-- yet not tested --

Edited by Schrwaizer
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

for( .@i = 2000000; .@i < 3000000; .@i++)
{
	if( !isloggedin(.@i) ) end;
	attachrid(.@i);
	getitem .@give_this_id, .@at_this_quantity;
	detachrid;
}

Make a loop of 1 million is a very bad solution

on my computer a loop of 50 000 take 1 min and the increase isn't linear

Moreover mapserv will stop the loop if it seems infinite

 

also if( !isloggedin(.@i) ) end; == if not online, the loop end : all online player wouldn't have the reward

Edited by Capuche
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  43
  • Reputation:   15
  • Joined:  06/24/12
  • Last Seen:  

O'right, I'll edit it to loop the quantity of existent accounts ASAP. ><

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

or something like that

	.@count = query_sql( "SELECT `account_id` FROM `char` WHERE `char`.`online` = '1'", .@num );
	for( .@i = 0; .@i < .@count; .@i++ )
		getitem .@give_this_id, .@at_this_quantity, .@num[ .@i ];

*getitem <item id>,<amount>{,<account ID>};

 
 

query_sql("SELECT `account_id` FROM `login` DESC LIMIT 0,1", .@num);

you select all account id in database but array limit is 128 rows
 
 
 
EDIT:

-	script	PmThisScript	-1,{

OnWhisperGlobal:
	if( getgmlevel() < 99 ) end;
	.@give_this_id = atoi( @whispervar0$ );
	.@at_this_quantity = atoi( @whispervar1$ );
	if( .@give_this_id <= 0 || .@at_this_quantity <= 0 ) {
		dispbottom "Be sure to tell me the ID of the item you want to prize all the online characters.";
		dispbottom "[PM to npc:PmThisScript] : <item_id>#<item_quantity>";
		dispbottom "Example:";
		dispbottom "npc:PmThisScript | 999#10";
		dispbottom "This will give 10 "+ getitemname(999) +" to all online characters.";
		end;
	}
	if( getitemname( .@give_this_id ) == "" ) {
		dispbottom "The given ID couldn't be processed.";
		dispbottom "Be sure to use only numeric values and checked item IDs.";
		end;
	}

	// After-checking, let's do the dirty job!
	.@count = query_sql( "SELECT `account_id` FROM `char` WHERE `char`.`online` = '1'", .@num );
	for( .@i = 0; .@i < .@count; .@i++ )
		getitem .@give_this_id, .@at_this_quantity, .@num[ .@i ];

	dispbottom .@at_this_quantity+" "+getitemname( .@give_this_id )+" had been successfully given to all online characters!";
	end;
}

 

Edited by Capuche
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  52
  • Reputation:   3
  • Joined:  01/05/12
  • Last Seen:  

i would also use sql for it. Ive a old script from si0n but i think isnt working, but you can modifi it as well.

 

 

//by Sim0n

-	script	online_counter	-1,{

OnInit:
	//--->AFK System<---\\
	//Enable Anti AFK (Checks if the player moves or not) else the time will stop when a player stops mooving for X minutes and start when he's moving again
	set .anti_afk,1;
	//Time which is needed tiill the timer stops, if a player is AFK
	set .afk_mins,10;
	
	//--->Reward Item<---\\
	//Get an Item each 24hrs after played a certain time (1 = Yes, 0 = No)
	set .getitem,1;
	//Time after you will get an item in minutes
	set .item_time,120;
	//Item and amount you will get
	set .item,7061;
	set .item_amount,24;
	

end;

OnPCLoginEvent:
	
	if(!.anti_afk) {
		
		//Without AFK System
		
		set login_time,gettimetick(2);
						
		dispbottom callfunc("seconds_to_days", sum_time_char, 0);
		dispbottom callfunc("seconds_to_days", ##sum_time_acc, 1);
		
		if (.getitem) {
		
			if (gettimetick(2)-last_login >= 86400) { set last_login,gettimetick(2); set got_item,0; }
			
			if (!got_item) {
			
				sleep2 (.item_time)*60000; 
				
				announce "You played more then "+ .item_time +" minutes! Here's your gift!",bc_self,0xFF0000;
				
				//Reward item
				getitem 7061,20;
				
				set got_item,1;
			
			}
			
		}
			
		end;
	
	} else {
		
		//With AFK System
		
		
		//dispbottom "[OC DEBUG] AFK Mins: "+.afk_mins;
		
		while ( isloggedin( getcharid(3), getcharid(0) ) ) {
		
			getmapxy @OC_map$, @OC_x, @OC_y, 0;
			
			//dispbottom "[OC DEBUG] "+ @OC_map$ +" == "+ @OC_map_cache$ +" && "+ @OC_x_cache +" == "+ @OC_x +" && "+  @OC_y_cache +" == "+ @OC_y;
			
			//dispbottom "[OC DEBUG] IF = "+ (@OC_map$ == @OC_map_cache$ && @OC_x_cache == @OC_x && @OC_y_cache == @OC_y);
			
			if (@OC_map$ == @OC_map_cache$ && @OC_x_cache == @OC_x && @OC_y_cache == @OC_y) { 
				
				set OC_afk_run,OC_afk_run + 1;
				
				if (OC_afk_run >= .afk_mins) { 
				
					set OC_afk, 1;
				
				}
					
			} else { 
				
				set OC_afk, 0;
				if (OC_afk_run >= afk_mins) {
				
					set OC_afk_run,0;	
					
				}
				
			}
						
			sleep2  60000;
									
			set @OC_map_cache$, @OC_map$;
			set @OC_x_cache, @OC_x;
			set @OC_y_cache, @OC_y;
					
		}
		
	}

OnPCLogoutEvent:
	
	if(!.anti_afk) {
	
		//Without AFK System
	
		set logout_time,gettimetick(2);
				
		if (login_time) set sum_time_char, sum_time_char + logout_time - login_time;
					
		set ##sum_time_acc, ##sum_time_acc + logout_time - login_time;
			
	} else 
		
		set ##sum_time_acc, ##sum_time_acc + tmp_online_sec;
		
	if (##sum_time_acc < sum_time_char) set ##sum_time_acc, ##sum_time_acc + sum_time_char;
		
	
	
OnWhisperGlobal:
	
	
	//RESET Time, only GMs
	if (getgmlevel() >= 60 && @whispervar0$ == "reset") {
		
		set ##sum_time_acc,0;
		set sum_time_char,0;
		
		dispbottom "[Online Counter] Time resetted...";
				
	}
	
	end;
	
	
}

-	script	online_seconds_counter	-1,{
	
OnPCLoginEvent:	
	
	if(getvariableofnpc( .anti_afk, "online_counter" )) {
		
		while (!OC_afk) { 
			
			sleep2 1000; 
			
			set sum_time_char, sum_time_char + 1; 
			set tmp_online_sec, tmp_online_sec + 1; 
			
			if (getvariableofnpc( .getitem, "online_counter" )) {
			
				if (gettimetick(2)-last_login >= 86400) { set last_login,gettimetick(2); set got_item,0; }
				
				if (tmp_online_sec == getvariableofnpc( .item_time, "online_counter" )) {
					
					announce "You played more then "+ getvariableofnpc( .item_time, "online_counter" ) +" minutes! Here's your gift!",bc_self,0xFF0000;
					
					//Reward item
					getitem getvariableofnpc( .item_time, "online_counter" ),getvariableofnpc( .item_amount, "online_counter" );
					
					set got_item,1;
					
				}
			
			}
			
		}
		
	}
	
}

function	script	seconds_to_days	{
	
	set @days, getarg(0) / 86400;
	set @hrs, (getarg(0) - @days * 86400) / 3600;
	set @mins, (getarg(0) - (@hrs * 3600) - (@days * 86400)) / 60;
	set @sec, getarg(0) - (@hrs * 3600) - (@mins * 60) - (@days * 86400);
		
	
		set @time$,"[Online Counter] Days: "+ @days +" || Hours: "+ @hrs +" || Mins: "+ @mins +" || Seconds: "+@sec;

		
	
	return @time$;
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  43
  • Reputation:   15
  • Joined:  06/24/12
  • Last Seen:  

@@Capuche I've started scripting it just like this suggestion of yours, but I've changed it to AttachRid 'cause of the array size limit... :P

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...