Jump to content
  • 0

Delete specific item on all players in a certain map


mrpatrick

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  28
  • Reputation:   2
  • Joined:  03/22/12
  • Last Seen:  

Hello, does anyone here knows how to make a script that deletes a specific item from all players in a certain map?

I need my players to have a specific item to be deleted in their inventory when my event is finished.

 

I know that the command for the script is delitem but I don't know how to apply it to all player in a specific map.

 

Thanks in advance!

Link to comment
Share on other sites

9 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

 

OnInit:
disablenpc "script NPC";
end;
 
OnClock0000:
announce "The event has started!",bc_all,0xFF4500;
enablenpc "warper in prontera"
sleep2 30000;
announce "Time's up! The warper will no longer accept participants!",bc_all,0xFF4500;
disablenpc "event Warper";
donpcevent "script NPC::EventStart";
end;
 
please correct me if I'm wrong. :) Thank you!
 
EDIT: or would it be fine if I make an NPC that will do this SQL command that you given every let's say 12 midnight instead of using OnPCLogout & OnPClogin?

 

 

Firstly, you don't want to do disablenpc "<script_npc>"; that would unload the npc altogether instead make the npc header like...

event_map,0,0,0	script	script_npc	139,{
	L_EventStart:
		initnpctimer;
		end;

	OnTimer600000:
		announce "The event has ended!",bc_all,0xFF4500;
		addrid(1);
		delitem <item_id>, countitem(<item_id>);
		warp "prontera",156,191;
		end;
}

Secondly, you wouldn't want to use sleep2 because no players are attached so it doesn't matter if we keep them.

OnClock0000:
	announce "The event has started!",bc_all,0xFF4500;
	enablenpc "<event_warper>";
	sleep 30000;
	announce "Time's up! The warper will no longer accept participants!",bc_all,0xFF4500;
	disablenpc "<event_warper>";
	donpcevent "script_npc::L_EventStart";
	end;

Lastly, yes and no.. For the players that are currently logged into your server you want to remove the item from inside the server because SQL doesn't update to the player until they relog.

OnClock0000:
	donpcevent "script_npc::L_Coroutine";
	addrid(0);
	if(set(.@i,countitem(<item_id>)))
		delitem <item_id>, .@i;
	end;
	
L_Coroutine:
	sleep 100;
	query_sql("DELETE FROM `inventory` WHERE `nameid` = <itemid>;");

Just remember to include the other databases that could contain items like storage and cart.

 

But overall you understood what I meant quite well.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  53
  • Topics Per Day:  0.01
  • Content Count:  411
  • Reputation:   261
  • Joined:  04/25/12
  • Last Seen:  

To attach all players on npc map, use this:

addrid(1);

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  28
  • Reputation:   2
  • Joined:  03/22/12
  • Last Seen:  

actually, I don't know where to put that. Can you help me a little bit more?

here is my script for example:
 

OnTimer600000:
    Announce "The event has ended!",0;
    mapwarp "poring_w01","prontera",156,191;
    end;
 
how should I apply it?
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  53
  • Topics Per Day:  0.01
  • Content Count:  411
  • Reputation:   261
  • Joined:  04/25/12
  • Last Seen:  

OnTimer600000:
    Announce "The event has ended!",0;
    addrid(1);
    delitem ID_ITEM,countitem(ID_ITEM);
    warp "prontera",156,191;
    end;
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

Assuming the NPC is located on the same map as all the players in the event. :o

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  28
  • Reputation:   2
  • Joined:  03/22/12
  • Last Seen:  

 

OnTimer600000:

    Announce "The event has ended!",0;

    addrid(1);

    delitem ID_ITEM,countitem(ID_ITEM);

    warp "prontera",156,191;

    end;

 

Thank you so much I didn't expect that I will just add it there. :)

 

 

Assuming the NPC is located on the same map as all the players in the event. :o

 

What if the NPC is in a different map?

Here is how my even works:

 

When the event starts, there's  a certain waiting time to gather participants and warp them to a different map. After that, the NPC will no longer accept participants. 

And when the event ends, they will be automatically warped out without the need to talk to any npc.

Another thing: I am planning to add a script to check for a specific item in their inventory everytime my players login and delete that item if it is available in their inventory.

My concern with this is that, will it slow down my server since the script automatically runs every time someone logins?

Im really sorry for the noob question. Just wanna make sure it wont hurt my server. :)

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

 

What if the NPC is in a different map?

Here is how my even works:

 

When the event starts, there's  a certain waiting time to gather participants and warp them to a different map. After that, the NPC will no longer accept participants. 

And when the event ends, they will be automatically warped out without the need to talk to any npc.

Another thing: I am planning to add a script to check for a specific item in their inventory everytime my players login and delete that item if it is available in their inventory.

My concern with this is that, will it slow down my server since the script automatically runs every time someone logins?

Im really sorry for the noob question. Just wanna make sure it wont hurt my server. :)

 

 

The suggested code won't work unless the npc is located on the same map or the players are attached to the script... What I would do in this situation is create a static invisible dummy npc which resides on the map and have him keep the timer. In my experience that is the least resource intensive and the least likely to fail. So basically when your entrance npc starts the event trigger a label (donpcevent();) which starts a timer in the dummy npc that will eventually trigger the above script.

It's ok to use commands like OnPCLogout & OnPCLogin when they are used in moderation... But if you're just trying to wipe your server of that specific item the best way is though SQL.

For example:

DELETE FROM `Inventory` WHERE `nameid` = <itemid>;
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  28
  • Reputation:   2
  • Joined:  03/22/12
  • Last Seen:  

Thankyou

 

 

 

What if the NPC is in a different map?

Here is how my even works:

 

When the event starts, there's  a certain waiting time to gather participants and warp them to a different map. After that, the NPC will no longer accept participants. 

And when the event ends, they will be automatically warped out without the need to talk to any npc.


Another thing: I am planning to add a script to check for a specific item in their inventory everytime my players login and delete that item if it is available in their inventory.

My concern with this is that, will it slow down my server since the script automatically runs every time someone logins?

Im really sorry for the noob question. Just wanna make sure it wont hurt my server. :)

 

 

The suggested code won't work unless the npc is located on the same map or the players are attached to the script... What I would do in this situation is create a static invisible dummy npc which resides on the map and have him keep the timer. In my experience that is the least resource intensive and the least likely to fail. So basically when your entrance npc starts the event trigger a label (donpcevent() ;) which starts a timer in the dummy npc that will eventually trigger the above script.

It's ok to use commands like OnPCLogout & OnPCLogin when they are used in moderation... But if you're just trying to wipe your server of that specific item the best way is though SQL.

For example:

DELETE FROM `Inventory` WHERE `nameid` = <itemid>;

Thankyou so much skorm!

So the NPC in prontera will now just be a warper NPC, and when the waiting time has ended, it will no longer accept players (or it will be disabled) then it will activate the NPC which will hold the timer and the whole script?

so is this what I should do on my script?

this is just an example:
 

 

OnInit:
disablenpc "script NPC";
end;
 
OnClock0000:
announce "The event has started!",bc_all,0xFF4500;
enablenpc "warper in prontera"
sleep2 30000;
announce "Time's up! The warper will no longer accept participants!",bc_all,0xFF4500;
disablenpc "event Warper";
donpcevent "script NPC::EventStart";
end;
 
please correct me if I'm wrong. :) Thank you!
 
EDIT: or would it be fine if I make an NPC that will do this SQL command that you given every let's say 12 midnight instead of using OnPCLogout & OnPClogin?
Edited by mrpatrick
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  28
  • Reputation:   2
  • Joined:  03/22/12
  • Last Seen:  

 

 

 

 

Firstly, you don't want to do disablenpc "<script_npc>"; that would unload the npc altogether instead make the npc header like...

event_map,0,0,0	script	script_npc	139,{
	L_EventStart:
		initnpctimer;
		end;

	OnTimer600000:
		announce "The event has ended!",bc_all,0xFF4500;
		addrid(1);
		delitem <item_id>, countitem(<item_id>);
		warp "prontera",156,191;
		end;
}

Secondly, you wouldn't want to use sleep2 because no players are attached so it doesn't matter if we keep them.

OnClock0000:
	announce "The event has started!",bc_all,0xFF4500;
	enablenpc "<event_warper>";
	sleep 30000;
	announce "Time's up! The warper will no longer accept participants!",bc_all,0xFF4500;
	disablenpc "<event_warper>";
	donpcevent "script_npc::L_EventStart";
	end;

Lastly, yes and no.. For the players that are currently logged into your server you want to remove the item from inside the server because SQL doesn't update to the player until they relog.

OnClock0000:
	donpcevent "script_npc::L_Coroutine";
	addrid(0);
	if(set(.@i,countitem(<item_id>)))
		delitem <item_id>, .@i;
	end;
	
L_Coroutine:
	sleep 100;
	query_sql("DELETE FROM `inventory` WHERE `nameid` = <itemid>;");

Just remember to include the other databases that could contain items like storage and cart.

 

But overall you understood what I meant quite well.

 

 

 

Thank you so much skorm! I learned more that what I am asking. This is my first attempt to make a script. I hope it will end up good.

 

I'll return the favor someday!

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