[Albetros source]Any one can explain me how to make random drop item event?

06/06/2014 21:23 mejo33#1
Hello EPVP member, any one can explain for me how i can make randomize position on map dropped item? like:

/dropdb <-- when i used player got msg

[SYSTEM]Suprise! Free DB on random pos in Twin City!

and server dropped 1 dbs on random title in city.

Thanks for explain i no have idea for it.. I have only build command and i am now on this step:
Quote:
private static bool Command_SantaEvent(Player user, string[] data)
{
if (user.Permission < PlayerPermission.GM) return false;
Kernel.SendToServer(new TalkPacket("SYSTEM", "ALLUSERS", "Suprise! Free DB on random pos in Twin City!", "", 0xffffff, ChatType.Center));
return true;
}
06/06/2014 22:50 abdoumatrix#2
that command is just talkpacket?

u should look for grounditem packet 1101

search for it and check all the refences it would be helpful for u
06/07/2014 00:58 mejo33#3
So i looking for this packet and write code like that:
Quote:
private static bool Command_SantaEvent(Player user, string[] data)
{
if (user.Permission < PlayerPermission.GM) return false;
Kernel.SendToServer(new TalkPacket("SYSTEM", "ALLUSERS", "AlcoholistChuck lost GiftBag, search it on random pos in Twin City for your reward!", "", 0xffffff, ChatType.Center));

Entity killer;
GroundItem bag = new GroundItem(new Structures.ItemInfo(1088000), (ushort)400, (ushort)400, Kernel.Maps[user.Map.ID], user is Player ? user.UID : 0);
user.SendToScreen(Packet.GroundItem.Create(bag, 1), false);
return true;
}
And this is now work.. Can u ask me more Abdo? I dont get any error in console and debugger, but i dont see item on the ground in pos 400, 400, 1002

and i have other one questios.. i make script for BlackTulip, all works armor changed color etc.. but i dont know how can i save the color to database -> items -> color column.. can u help me too? there codes for black tulip.
Quote:
#region BlackTulip
case 723584:
var itm = user.Equipment.GetItemBySlot(ItemLocation.Armor);
itm.ChangeItemtype(item.Color = 2);
var id = item.StaticID;
var UID = item.UniqueID;
var Color = itm.Color;
itm.Color = 2;
user.Send(Packet.ItemInfoPacket.Create(itm, item.Color = 2));
user.Equipment.SetSlot(itm, (ItemLocation)itm.Location);
user.Send(Packet.ItemInfoPacket.Create(itm, 3));
user.Recalculate();
Database.ModifyItem(Color, "2", itm.UniqueID);
break;
#endregion
06/07/2014 01:17 abdoumatrix#4
Quote:
user.SendToScreen(Packet.GroundItem.Create(bag, 1), true);
as

Quote:
public override void SendToScreen(byte[] data, bool self)
---------------------

PHP Code:
 Database.ModifyItem(mainItem.Color"Color"mainItem.UniqueID); 
as

/// value , coloum name, itemuid
06/07/2014 01:44 mejo33#5
Thanks for helps, all fully working but i need using randomize tiles can u help me too with what? i now using like that:
Quote:
private static bool Command_SantaEvent(Player user, string[] data)
{
if (user.Permission < PlayerPermission.GM) return false;
Kernel.SendToServer(new TalkPacket("SYSTEM", "ALLUSERS", "AlcoholistChuck lost GiftBag, search it on random pos in Twin City for your reward!", "", 0xffffff, ChatType.Center));


uint[] randposx = new uint[] { 400, 376, 391, 360, 382, 358, 409, 468, 462, 473, 510, 463, 394, 401, 472 };
uint[] randposy = new uint[] { 400, 404, 366, 347, 341, 317, 328, 341, 367, 399, 355, 291, 274, 242, 235 };
GroundItem gi = new GroundItem(new Structures.ItemInfo(729912), (ushort)randposx[Kernel.RandomNext(randposx.Length - 1)], (ushort)randposy[Kernel.RandomNext(randposy.Length - 1)], Kernel.Maps[user.Map.ID], 0);
user.SendToScreen(Packet.GroundItem.Create(gi, 1), true);
return true;
}
So.. its randomize x and y what ever.. I need build a tablice like
xpos = 400, 450, 500
ypos = 400, 450, 500
i dont know how to make it...

BTW released here fully working BlackTulip code:
Quote:
#region BlackTulip
case 723584:
var itm = user.Equipment.GetItemBySlot(ItemLocation.Armor);
itm.ChangeItemtype(item.Color = 2);
var id = item.StaticID;
var UID = item.UniqueID;
var Color = itm.Color;
itm.Color = 2;
user.Send(Packet.ItemInfoPacket.Create(itm, item.Color = 2));
user.Equipment.SetSlot(itm, (ItemLocation)itm.Location);
user.Send(Packet.ItemInfoPacket.Create(itm, 3));
user.Recalculate();
Database.ModifyItem(itm.Color, "Color", itm.UniqueID);
break;
#endregion
Thanks for Abdumatrix for help saving the colors to databases.
06/07/2014 13:52 abdoumatrix#6
u could use something like that one used in generateing monster
PHP Code:
   var spawnPoint = new Point(Kernel.RND.Next(spreadspread), Kernel.RND.Next(spreadspread));
                   for (var 
tries 0tries 10 && !Kernel.DmapHandler.Maps[(int)monster.Map.ID].Check(spawnPoint.XspawnPoint.Y); tries++)
                   {
                       
spawnPoint = new Point(Kernel.RND.Next(spreadspread), Kernel.RND.Next(spreadspread));
                   } 
as it check points vaild. etc


or just use this

Quote:
ushort[] randposx = new ushort[] { 400, 376, 391, 360, 382, 358, 409, 468, 462, 473, 510, 463, 394, 401, 472 };
ushort[] randposy = new ushort[] { 400, 404, 366, 347, 341, 317, 328, 341, 367, 399, 355, 291, 274, 242, 235 };

var rnd = Kernel.RandomNext(randposx.Length);
GroundItem gi = new GroundItem(new Structures.ItemInfo(729912), randposx[rnd], randposy[rnd], Kernel.Maps[user.Map.ID], 0);
06/07/2014 15:40 mejo33#7
Ok its work but i got one new problem... The item drops only when player stay in this cords.. But when i am on center map twin city and use this command and go to cords i dont see item, when i stay in ex. 400, 400 the item will be dropped and see it. Where problem? user.SendToScreen? how to update map for world.
06/07/2014 17:07 abdoumatrix#8
Quote:
Originally Posted by mejo33 View Post
Ok its work but i got one new problem... The item drops only when player stay in this cords.. But when i am on center map twin city and use this command and go to cords i dont see item, when i stay in ex. 400, 400 the item will be dropped and see it. Where problem? user.SendToScreen? how to update map for world.
:D so u drop item too far away from u so u arrive the point it disappeared

isn't there a time for item to disappear? (15-20 sec.)
06/07/2014 17:49 mejo33#9
You play in lastCo? there is a santabag drop event, i need make it same. No drop item from reach player, item need to drop by random cords in map for all player.
06/07/2014 18:02 TwitchTime#10
Take a peek at monster drops to see how a item is generated and added to the ground.


Combine with dmap validity checks (examples in same item drop section) and a System.Random roll to find a random location on the twin city map.

NOTE: There is not currently a way to make the DB last longer than most ground items IIRC.... You could just add an overload to the ground item constructor to let you have it last longer on the ground if needed.

Very basic pseudo code

ushort _x = random.Next(selectedMap.Width);
ushort _y = random.Next(selectedMap.Height);

while(!ValidItemLocation(selectedMap, _x, _y))
{
_x = random.Next(selectedMap.Width);
_y = random.Next(selectedMap.Height);
}

DropItemOnGround(selectedMap, _x, _y);