Jump to content
  • 0

delitem deleting equipped item


powkda

Question


  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   1
  • Joined:  11/11/17
  • Last Seen:  

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

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  292
  • Reputation:   46
  • Joined:  10/30/12
  • Last Seen:  

Check this:

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  896
  • Reputation:   118
  • Joined:  05/23/12
  • Last Seen:  

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

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

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   1
  • Joined:  11/11/17
  • Last Seen:  

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

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 .@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){
				close;
				}
		}
		end;

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  896
  • Reputation:   118
  • Joined:  05/23/12
  • Last Seen:  

@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

  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   1
  • Joined:  11/11/17
  • Last Seen:  

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

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

use delitemidx(...) script command instead.

getinventorylist;
for (.@i = 0; .@i < @inventorylist_count; .@i++) {
	if (@inventorylist_id[.@i] == 31000 && !@inventorylist_equip[.@i]) {
		delitemidx @inventorylist_idx[.@i], 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...