Jump to content
  • 0
powkda

delitem deleting equipped item

Question

Good night, I'm having a big problem with the delitem, it is removing the item that is equipped, how do I make it only count and delete the item that is in the inventory?

	case 1:
	if(countitem(31000)<1)goto noanel;
	delitem 31000,1;
	getitem 30001,5;
	next;
	mes "^FF0000["+strnpcinfo(1)+"]^000000";
	mes "Aqui está a sua recompensa.";
	close;
	end;

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

@powkda

Some small suggestions

if u only want to know if player don't have one of an item u better change from:

if(countitem(31000)<1)

 

To:

if(!countitem(31000))

 

If u just need the label noanel once. U should better put the code directly to the if statement. It will be better than goto a label u only need once.

U don't need to close; and end; the script. Close end the dialog (mes etc). End stops the script. It's as example used if no dialog is open. If u want to close the dialog but u want to do something like getitem, delitem or else where u need to keep player attached u can use close2. It will close the dialog normally but the script do stuff in background. Than u need to end the script afterwards.

On switch case u can use break; to jump directly to the code after the switch. It will ignores the other cases.

 

This should works for u:

case 1:
    if(!countitem(31000))goto noanel;
    getinventorylist;
    for(set [email protected],0; [email protected]<@inventorylist_count; [email protected]++){
        if(@inventorylist_id[[email protected]] == 31000 && [email protected]_equip[[email protected]]){
            delitem @inventorylist_id[[email protected]],1;
            getitem 30001,5;
            next;
            mes "^FF0000["+strnpcinfo(1)+"]^000000";
            mes "Aqui está a sua recompensa.";
            close;
        } else if([email protected]==inventorylist_count){
            //they only have the equipped item
            close;
        } else continue;
    }
    end;

Feel free to PM me if u need help. I'm already willing to help.

 

Rynbef~

Edited by Rynbef
  • Like 1
Link to comment
Share on other sites

  • 0
On 1/30/2022 at 7:47 PM, Rynbef said:

@powkda

Some small suggestions

if u only want to know if player don't have one of an item u better change from:

if(countitem(31000)<1)

 

To:

if(!countitem(31000))

 

If u just need the label noanel once. U should better put the code directly to the if statement. It will be better than goto a label u only need once.

U don't need to close; and end; the script. Close end the dialog (mes etc). End stops the script. It's as example used if no dialog is open. If u want to close the dialog but u want to do something like getitem, delitem or else where u need to keep player attached u can use close2. It will close the dialog normally but the script do stuff in background. Than u need to end the script afterwards.

On switch case u can use break; to jump directly to the code after the switch. It will ignores the other cases.

 

This should works for u:

case 1:
    if(!countitem(31000))goto noanel;
    getinventorylist;
    for(set [email protected],0; [email protected]<@inventorylist_count; [email protected]++){
        if(@inventorylist_id[[email protected]] == 31000 && [email protected]_equip[[email protected]]){
            delitem @inventorylist_id[[email protected]],1;
            getitem 30001,5;
            next;
            mes "^FF0000["+strnpcinfo(1)+"]^000000";
            mes "Aqui está a sua recompensa.";
            close;
        } else if([email protected]==inventorylist_count){
            //they only have the equipped item
            close;
        } else continue;
    }
    end;

Feel free to PM me if u need help. I'm already willing to help.

 

Rynbef~

 

I did this but it didn't work, did I make a mistake somewhere?

case 1:
	if(!countitem(31000))goto noanel;
	getinventorylist;
	for(set [email protected],0; [email protected]<@inventorylist_count; [email protected]++){
		if(@inventorylist_id[[email protected]] == 31000 && [email protected]_equip[[email protected]]){
			delitem @inventorylist_id[[email protected]],1;
			getitem 30001,5;
			next;
			mes "^FF0000["+strnpcinfo(1)+"]^000000";
			mes "Aqui está a sua recompensa.";
			close;
			}
			else if([email protected]==inventorylist_count){
				close;
				}
		}
		end;

 

Link to comment
Share on other sites

  • 0

@powkdaI've posted a modified version above. Just replace ur case and check if it works. I can only recommend u to study about close; close2; and end; I've already explained it. Not only on this thread. U should read the rA/doc/script_commands.txt Manual! U do again used close; and end; wrong.

 

Maybe attach ur full script. So I can understand why ur case needs a next; Is their a dialog before?

 

Rynbef~

Edited by Rynbef
  • Like 1
Link to comment
Share on other sites

  • 0
6 hours ago, Rynbef said:

@powkdaI've posted a modified version above. Just replace ur case and check if it works. I can only recommend u to study about close; close2; and end; I've already explained it. Not only on this thread. U should read the rA/doc/script_commands.txt Manual! U do again used close; and end; wrong.

 

Maybe attach ur full script. So I can understand why ur case needs a next; Is their a dialog before?

 

Rynbef~

 

I did as you said, there was no error, but it is not getting the items from the inventory

here is the full npc

 

mes "^FF0000["+strnpcinfo(1)+"]^000000";
mes "Você pode recuperar os seus itens";
mes "Deseja Continuar?";
switch(select("[^daa520•^000000] Sim:[^ff0000•^000000] Não")){

case 1:
    if(!countitem(31000))goto noanel;
    getinventorylist;
    for(set .@i,0; .@i<@inventorylist_count; .@i++){
        if(@inventorylist_id[.@i] == 31000 && !@inventorylist_equip[.@i]){
            delitem @inventorylist_id[.@i],1;
            getitem 30001,5;
            next;
            mes "^FF0000["+strnpcinfo(1)+"]^000000";
            mes "Aqui está a sua recompensa.";
            close;
        } else if(.@i==inventorylist_count){
            //they only have the equipped item
            close;
        } else continue;
    }
    end;


	case 2:
	next;
	mes "^FF0000["+strnpcinfo(1)+"]^000000";
	mes "Volte quando quizer!";
	close;
	end;
}

 

Link to comment
Share on other sites

  • 0

use delitemidx(...) script command instead.

getinventorylist;
for ([email protected] = 0; [email protected] < @inventorylist_count; [email protected]++) {
	if (@inventorylist_id[[email protected]] == 31000 && [email protected]_equip[[email protected]]) {
		delitemidx @inventorylist_idx[[email protected]], 1;
		getitem 30001,5;
	}
}

 

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.