Jump to content
  • 0
Sign in to follow this  
utofaery

H>Pet egg renewal fixing

Question

I have a broken pet egg exchanging old egg to new egg script which need help in fixing.

-	script	F_PetTrader	FAKE_NPC,{
		disable_items;
		getinventorylist;
		for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
			.@item_type = getiteminfo( @inventorylist_id[.@i], ITEMINFO_TYPE );
			if ( .@item_type == IT_PETEGG ) {
				if ( .petid[ @inventorylist_id[.@i] ] && !.@compare[ @inventorylist_id[.@i] ] ) {
					.@found[.@c++] = @inventorylist_id[.@i];
					.@compare[ @inventorylist_id[.@i] ] = false;
				}
			}
		}
		.@menu$ = "+&Sort&Count&Item&Name+&^FF0000Quit^000000:";
		for ( .@i = 0; .@i < getarraysize(.@found); ++.@i ) {
			mes getitemname( .@found[.@i] );
			.@menu$ += .@i + " " + countitem(.@found[.@i] ) + " " + getitemname(.@found[.@i]) + " :";
			dispbottom ( " .@i :: " + .@i + "  Count item :: " + countitem(.@found[.@i] ) + "  ItemName :: " + getitemname(.@found[.@i]) ) ;
		}
		.@i = select(.@menu$)-1;
		if ( .@i > getarraysize(.@found) ) {
			dispbottom ( " Dont mess with bug or I bug you! " ) ;
			close2;
			end;
		} else {
			mes (" .@i " + .@i ); 
			.@EggItemId = .@found[.@i];
			.@EggCount = countitem(.@found[.@i] );
			if ( .@EggItemId ) {
				delitem ( .@EggItemId, .@EggCount ) ;
				makepet ( .@EggItemId );
				mes ( " Exchanged :: " + .@EggCount + " of " + .@EggItemId ) ;
			} else {
				dispbottom ( " .@EggItemId :: " + .@EggItemId + "  .@EggCount :: " + .@EggCount ) ;
			}
		}
		close;
OnInit:
	.@nb = query_sql( "select id from item_db where type & "+( 7 ), .@id );
	freeloop true;
	for ( .@i = 0; .@i < .@nb; ++.@i )
		.petid[ .@id[.@i] ] = true;
	end;
}

It is suppose to list what egg in player inventory but always returning poring egg..

sometimes nothing is listed..or 0

somewhere is broken and I failed to find out where

and the .@menu$ part is confusing for me since it's not something I always messing with.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

pet eggs are not simple as that, there is also a `pet` table you have to worry about
you can't just *delitem ... have to list the pet owner, intimacy, ... etc fetch the pet information then use *delitem2 to delete the correct pet ID

also your script is a total mess, I have totally no idea what you are doing

// counting_sort_index <input array>, <output index>{, <total index>};
function	script	counting_sort_index	{
	.@total = .@size = getarg( 2, getarraysize( getarg(0) ) );
	copyarray .@arr, getarg(0), .@size;
	for ( .@i = 0; .@i < .@size; ++.@i )
		setd ".@index_"+ .@arr[.@i] +"["+( .@tmp[.@arr[.@i]]++ )+"]", .@i;
	for ( ; .@size; --.@size ) {
		.@index = getarraysize(.@tmp) -1;
		.@out[.@size-1] = getd( ".@index_"+ .@index +"["+( --.@tmp[.@index] )+"]" );
	}
	copyarray getarg(1), .@out, .@total;
	return;
}

prontera,155,185,5	script	F_PetTrader	1_F_MARIA,{
	disable_items;
	if ( getpetinfo(1) ) {
		mes "please return your pet into egg state to continue";
		close;
	}
	getinventorylist;
	for ( .@i = 0; .@i < @inventorylist_count; ++.@i ) {
		if ( @inventorylist_card1[.@i] == -256 ) {
			.@egg_id[.@c] = @inventorylist_id[.@i];
			.@pet_id[.@c] = @inventorylist_card2[.@i] + @inventorylist_card3[.@i] * ( 1 << 16 );
			++.@c;
		}
	}
	if ( !.@c ) {
		mes "your inventory doesn't have any pet egg";
		close;
	}
	counting_sort_index .@petid, .@s, .@c; // never thought a time need a sorting algorithm
	for ( .@i = 0; .@i < .@c; ++.@i ) {
		.@petid[.@i] = .@pet_id[.@s[.@i]];
		.@eggid[.@i] = .@egg_id[.@s[.@i]];
	}
	.@pet_field$ = .@petid[0];
	for ( .@i = 1; .@i < .@c; ++.@i )
		.@pet_field$ += ","+ .@petid[.@i];
	.@nb = query_sql( "select intimate, class, equip, name from pet where pet_id in ("+ .@pet_field$ +") order by pet_id", .@intimate, .@class, .@equipped, .@name$ );
	if ( .@nb != .@c ) {
		mes "Error ... ";
		close;
	}
	mesf "There are %d pet egg inside your inventory", .@c;
	for ( .@i = 0; .@i < .@nb; ++.@i ) {
		mesf "\rPet ID : %d", .@petid[.@i];
		mesf "Pet Name : %s", .@name$[.@i];
		mesf "Pet Class : %d", .@class[.@i];
		mesf "Egg ID : %d", .@eggid[.@i];
		mesf "Intimacy : %d", .@intimate[.@i];
	}
	next;
	for ( .@i = 0; .@i < .@nb; ++.@i )
		.@menu$ += sprintf( ("[%d] %s:"), .@petid[.@i], replacestr( .@name$[.@i], ":", ";" ) );
	.@s = select(.@menu$) -1;
	mesf "Selected #%d %s", .@petid[.@s], .@name$;
	// then decide what you want to do here
	mes "delete it ?";
	next;
	if ( select( "Yes", "No" ) == 2 ) close;
	delitem2 .@eggid[.@s], 1,1,0,0, -256, .@petid[.@s] % ( 1 << 16 ), .@petid[.@s] / ( 1 << 16 ), 0;
	close;
}

 

Edited by AnnieRuru

Share this post


Link to post
Share on other sites
  • 0

Yes my script is total mess.

Which is why am posting for help.

Only those don't want to be helped will refuse to ask for it or worst reject it.

But something else comes in my mind.

Curiously...

Why is there got bhatch;

And there hasn't got any breturntoegg; ?

Or could you create something like that too?

 

 

Side stuff:

At this time I am using phone to browsing here 

But out of curiosity why there is so many guess which outnumbered members which logged in.

Edited by utofaery
Added side stuff

Share this post


Link to post
Share on other sites
  • 0
On 2/14/2019 at 8:31 PM, utofaery said:

Why is there got bhatch;
And there hasn't got any breturntoegg; ?

its *bpet actually

*bpet()

This command opens up a pet hatching window on the client connected to the
invoking character. It is used in item script for the pet incubators and
will let the player hatch an owned egg. If the character has no eggs, it
will just open up an empty incubator window.
This is still usable outside item scripts.

 

 

On 2/14/2019 at 8:31 PM, utofaery said:

Or could you create something like that too?

there is already pet_return_egg function, so just use it

#include "common/hercules.h"
#include "map/pc.h"
#include "map/pet.h"
#include "map/script.h"
#include "common/HPMDataCheck.h"

HPExport struct hplugin_info pinfo = {
	"pet_return_egg",
	SERVER_TYPE_MAP,
	"0.1",
	HPM_VERSION,
};

BUILDIN(pet_return_egg) {
	struct map_session_data *sd;
	if ( script_hasdata(st,2) ) {
		if ( script_isstringtype(st,2) )
			sd = script->nick2sd( st, script_getstr(st,2) );
		else
			sd = script->id2sd( st, script_getnum(st,2) );
	}
	else
		sd = script->rid2sd(st);
	if ( !sd )
		return true;
	if ( !sd->pd ) {
		ShowWarning( "buildin_pet_return_egg: Pet not found !\n" );
		return false;
	}
	pet->return_egg(sd, sd->pd);
	return true;
}

HPExport void plugin_init(void) {
	addScriptCommand( "pet_return_egg", "?", pet_return_egg );
}
prontera,155,185,5	script	kjhdfksjf	1_F_MARIA,{
	if ( getpetinfo(1) )
		pet_return_egg;
	close;
}

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.