Jump to content
  • 0
Sehrentos

Extract char_id from crafted items card position 3 & 4

Question

Hello,

Is it possible to calculate and extract the crafted items char_id from card position 3 and 4 ?
I have this test script, where i'm trying to extract as many data from the crafted items as possible and show results.

In docs char_id is calculated: @card3 = @charid & 65535; @card4 = @charid >> 16; when crafting them.

-	script	#atcmd_test	-1,{
OnInit:
	bindatcmd "test", strnpcinfo(3)+"::OnAtCommand";
	end;

OnAtCommand:
	if (getgmlevel() < 60) end;
	[email protected]_id = getcharid(0);
	getinventorylist( [email protected]_id );
	for( [email protected] = 0; [email protected]<@inventorylist_count; [email protected]++ ) {
		if(@inventorylist_card1[[email protected]] == CARD0_PET) {
			message strcharinfo(0), ([email protected]+1) +". [Pet] "+ getitemname(@inventorylist_id[[email protected]]) +
			" ("+ @inventorylist_amount[[email protected]] +")";
		}
		else if(@inventorylist_card1[[email protected]] == CARD0_FORGE) {
			message strcharinfo(0), ([email protected]+1) +". [Forge]" +
			(@inventorylist_refine[[email protected]] ? " +"+ @inventorylist_refine[[email protected]] : "") +
			" "+ callsub(S_ForgeProperty, @inventorylist_card2[[email protected]]) +
			" "+ getitemname(@inventorylist_id[[email protected]]) + 
			" ("+ @inventorylist_amount[[email protected]] +")" +
			(@inventorylist_equip[[email protected]] > 0 ? " Equiped: "+ callsub(S_EquipPosition,@inventorylist_equip[[email protected]]) : "") +
			(@inventorylist_attribute[[email protected]] ? " broken" : "");
			// for debugs:
			//(@inventorylist_card2[[email protected]] ? " card-2:" + @inventorylist_card2[[email protected]] : "") +
			//(@inventorylist_card3[[email protected]] ? " card-3:" + @inventorylist_card3[[email protected]] : "") +
			//(@inventorylist_card4[[email protected]] ? " card-4:" + @inventorylist_card4[[email protected]] : "");
		}
		else if(@inventorylist_card1[[email protected]] == CARD0_CREATE) {
			message strcharinfo(0), ([email protected]+1) +". [Create]" +
			(@inventorylist_refine[[email protected]] ? " +"+ @inventorylist_refine[[email protected]] : "") +
			" "+ getitemname(@inventorylist_id[[email protected]]) + 
			" ("+ @inventorylist_amount[[email protected]] +")" +
			(@inventorylist_equip[[email protected]] > 0 ? " Equiped: "+ callsub(S_EquipPosition,@inventorylist_equip[[email protected]]) : "");
			// for debugs:
			//(@inventorylist_card2[[email protected]] ? " card-2:" + @inventorylist_card2[[email protected]] : "") +
			//(@inventorylist_card3[[email protected]] ? " card-3:" + @inventorylist_card3[[email protected]] : "") +
			//(@inventorylist_card4[[email protected]] ? " card-4:" + @inventorylist_card4[[email protected]] : "");
		}
		else if (@inventorylist_equip[[email protected]] > 0) {
			// Equiped items
			message strcharinfo(0), ([email protected]+1) +"." +
			(@inventorylist_refine[[email protected]] ? " +"+ @inventorylist_refine[[email protected]] : "") +
			" "+ getitemname(@inventorylist_id[[email protected]]) + 
			" ("+ @inventorylist_amount[[email protected]] +")" +
			" Equiped: "+ callsub(S_EquipPosition,@inventorylist_equip[[email protected]]) +
			(@inventorylist_identify[[email protected]] ? "" : " unidentified") +
			(@inventorylist_attribute[[email protected]] ? " broken" : "") +
			(@inventorylist_card1[[email protected]] ? " card-1:" + @inventorylist_card1[[email protected]] : "") + //@inventorylist_card1[[email protected]] == 256 is Egg
			(@inventorylist_card2[[email protected]] ? " card-2:" + @inventorylist_card2[[email protected]] : "") +
			(@inventorylist_card3[[email protected]] ? " card-3:" + @inventorylist_card3[[email protected]] : "") +
			(@inventorylist_card4[[email protected]] ? " card-4:" + @inventorylist_card4[[email protected]] : "");
		}
		else {
			// Other inventory items
			message strcharinfo(0), ([email protected]+1) +"." +
			(@inventorylist_refine[[email protected]] ? " +"+ @inventorylist_refine[[email protected]] : "") +
			" "+ getitemname(@inventorylist_id[[email protected]]) +
			" ("+ @inventorylist_amount[[email protected]] +")" +
			(@inventorylist_identify[[email protected]] ? "" : " unidentified") +
			(@inventorylist_attribute[[email protected]] ? " broken" : "") +
			(@inventorylist_card1[[email protected]] ? " card-1:" + @inventorylist_card1[[email protected]] : "") +
			(@inventorylist_card2[[email protected]] ? " card-2:" + @inventorylist_card2[[email protected]] : "") +
			(@inventorylist_card3[[email protected]] ? " card-3:" + @inventorylist_card3[[email protected]] : "") +
			(@inventorylist_card4[[email protected]] ? " card-4:" + @inventorylist_card4[[email protected]] : "");
		}
		//debugmes "Equip: "+ getitemname(@inventorylist_id[[email protected]]) + ": "[email protected]_equip[[email protected]];
	}
	end;

S_ForgeProperty:
	[email protected] = getarg(0);
	// 1 - Ice, 2 - Earth 3 - Fire 4 - Wind.
	// Calc formula: ElementNumber + ((StarCrubNumber * 5) << 8)
	switch([email protected]) {
		case 3840: [email protected]$ = "Very Very Very Strong Neutral"; break;
		case 3841: [email protected]$ = "Very Very Very Strong Ice"; break;
		case 3842: [email protected]$ = "Very Very Very Strong Earth"; break;
		case 3843: [email protected]$ = "Very Very Very Strong Fire"; break;
		case 3844: [email protected]$ = "Very Very Very Strong Wind"; break;
		case 2560: [email protected]$ = "Very Very Strong Neutral"; break;
		case 2561: [email protected]$ = "Very Very Strong Ice"; break;
		case 2562: [email protected]$ = "Very Very Strong Earth"; break;
		case 2563: [email protected]$ = "Very Very Strong Fire"; break;
		case 2564: [email protected]$ = "Very Very Strong Wind"; break;
		case 1280: [email protected]$ = "Very Strong Neutral"; break;
		case 1281: [email protected]$ = "Very Strong Ice"; break;
		case 1282: [email protected]$ = "Very Strong Earth"; break;
		case 1283: [email protected]$ = "Very Strong Fire"; break;
		case 1284: [email protected]$ = "Very Strong Wind"; break;
		case 0: [email protected]$ = "Neutral"; break;
		case 1: [email protected]$ = "Ice"; break;
		case 2: [email protected]$ = "Earth"; break;
		case 3: [email protected]$ = "Fire"; break;
		case 4: [email protected]$ = "Wind"; break;
		default: [email protected]$ = ""; break;
	}
	//debugmes "Calc value: "+ [email protected];
	//debugmes "Calc result: "+ [email protected]$;
	return [email protected]$;

S_EquipPosition:
	[email protected] = getarg(0);
	if([email protected] == EQP_ACC_L) {
		[email protected]$ = "Accessory Left";
	} else if([email protected] == EQP_ACC_R) {
		[email protected]$ = "Accessory Right";
	} else if([email protected] == EQP_SHOES) {
		[email protected]$ = "Shoes";
	} else if([email protected] == EQP_GARMENT) {
		[email protected]$ = "Garment";
	} else if([email protected] == EQP_HEAD_LOW) {
		[email protected]$ = "Head lower";
	} else if([email protected] == EQP_HEAD_MID) {
		[email protected]$ = "Head middle";
	} else if([email protected] == EQP_HEAD_TOP) {
		[email protected]$ = "Head top";
	} else if([email protected] == EQP_ARMOR) {
		[email protected]$ = "Armor";
	} else if([email protected] == EQP_HAND_L) {
		[email protected]$ = "Hand Left";
	} else if([email protected] == EQP_HAND_R) {
		[email protected]$ = "Hand Right";
	} else if([email protected] == EQP_HAND_L + EQP_HAND_R) {
		[email protected]$ = "Hands Left & Right";
	} else if([email protected] == EQP_COSTUME_HEAD_TOP) {
		[email protected]$ = "C-Head top";
	} else if([email protected] == EQP_COSTUME_HEAD_MID) {
		[email protected]$ = "C-Head middle";
	} else if([email protected] == EQP_COSTUME_HEAD_LOW) {
		[email protected]$ = "C-Head lower";
	} else if([email protected] == EQP_COSTUME_GARMENT) {
		[email protected]$ = "C-Garment";
	} else if([email protected] == EQP_AMMO) {
		[email protected]$ = "Ammonition";
	} else if([email protected] == EQP_SHADOW_ARMOR) {
		[email protected]$ = "S-Armor";
	} else if([email protected] == EQP_SHADOW_WEAPON) {
		[email protected]$ = "S-Weapon";
	} else if([email protected] == EQP_SHADOW_SHIELD) {
		[email protected]$ = "S-Shield";
	} else if([email protected] == EQP_SHADOW_SHOES) {
		[email protected]$ = "S-Shoes";
	} else if([email protected] == EQP_SHADOW_ACC_R) {
		[email protected]$ = "S-Accessory Right";
	} else if([email protected] == EQP_SHADOW_ACC_L) {
		[email protected]$ = "S-Accessory Left";
	} else if([email protected] == EQP_ACC_RL) {
		[email protected]$ = "Accessory Both";
	} else if([email protected] == EQP_SHADOW_ACC_RL) {
		[email protected]$ = "S-Accessory Both";
	} else {
		[email protected]$ = "";
	}
	return [email protected]$;
}

Thanks in advance.

Edited by Sehrentos
Notes
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 1

When you're referring to docs i guess you meant these lines:

    // Now we split the character ID number into two portions with a binary
    // shift operation. If you don't understand what this does, just copy it.
    @card3 = @charid & 65535;
    @card4 = @charid >> 16;

If that is the case then i think it would be possible to retrieve it (assuming we're operating on a 32bit system):

@card3 is storing the LAST 16 bits of the character's ID
@card4 is storing the FIRST 16 bits of the character's ID

So you'll just need to perform a left shift by 16 bits and perform a bitwise OR

@crafter_char_id = (@inventorylist_card4[.@i] << 16) | @inventorylist_card3[.@i];

Let me know if that works

  • Like 1
Link to comment
Share on other sites

  • 0

Thank you @Rene

That worked for me /no1

This is the final result if any one is interested:

// callsub(S_ForgeProperty, @inventorylist_card2[[email protected]], @inventorylist_card3[[email protected]], @inventorylist_card4[[email protected]])
S_ForgeProperty:
	[email protected] = getarg(0);
	[email protected] = getarg(1);
	[email protected] = getarg(2);
	// 1 - Ice, 2 - Earth 3 - Fire 4 - Wind.
	// Calc formula: ElementNumber + ((StarCrubNumber * 5) << 8)
	[email protected]_id = ([email protected] << 16) | [email protected];
	// Character ID's start from 150000
	if ([email protected]_id >= 150000) {
		// Using strcharinfo(0,[email protected]_id) will throw Error if player is offline...
		// So we use good old SQL query:
		query_sql("SELECT name FROM `char` WHERE `char_id`="[email protected]_id, [email protected]_name$);
	} else {
		setarray [email protected]_name$[0], "Unknown";
	}
	switch([email protected]) {
		case 3840: [email protected]$ = "Very Very Very Strong "+ [email protected]_name$[0] +"'s Neutral"; break;
		case 3841: [email protected]$ = "Very Very Very Strong "+ [email protected]_name$[0] +"'s Ice"; break;
		case 3842: [email protected]$ = "Very Very Very Strong "+ [email protected]_name$[0] +"'s Earth"; break;
		case 3843: [email protected]$ = "Very Very Very Strong "+ [email protected]_name$[0] +"'s Fire"; break;
		case 3844: [email protected]$ = "Very Very Very Strong "+ [email protected]_name$[0] +"'s Wind"; break;
		case 2560: [email protected]$ = "Very Very Strong "+ [email protected]_name$[0] +"'s Neutral"; break;
		case 2561: [email protected]$ = "Very Very Strong "+ [email protected]_name$[0] +"'s Ice"; break;
		case 2562: [email protected]$ = "Very Very Strong "+ [email protected]_name$[0] +"'s Earth"; break;
		case 2563: [email protected]$ = "Very Very Strong "+ [email protected]_name$[0] +"'s Fire"; break;
		case 2564: [email protected]$ = "Very Very Strong "+ [email protected]_name$[0] +"'s Wind"; break;
		case 1280: [email protected]$ = "Very Strong "+ [email protected]_name$[0] +"'s Neutral"; break;
		case 1281: [email protected]$ = "Very Strong "+ [email protected]_name$[0] +"'s Ice"; break;
		case 1282: [email protected]$ = "Very Strong "+ [email protected]_name$[0] +"'s Earth"; break;
		case 1283: [email protected]$ = "Very Strong "+ [email protected]_name$[0] +"'s Fire"; break;
		case 1284: [email protected]$ = "Very Strong "+ [email protected]_name$[0] +"'s Wind"; break;
		case 0: [email protected]$ = [email protected]_name$[0] +"'s Neutral"; break;
		case 1: [email protected]$ = [email protected]_name$[0] +"'s Ice"; break;
		case 2: [email protected]$ = [email protected]_name$[0] +"'s Earth"; break;
		case 3: [email protected]$ = [email protected]_name$[0] +"'s Fire"; break;
		case 4: [email protected]$ = [email protected]_name$[0] +"'s Wind"; break;
		default: [email protected]$ = ""; break;
	}
	return [email protected]$;

 

Edited by Sehrentos
Notes
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...

Important Information

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