Shako 97 Report post Posted October 7, 2016 Hello, can someone write a brief script on an NPC like this? Talk - Donate NPC It gives you options: Donate 1000G, Donate 10000G, Donate 1000000G And then there's another option: View Total Donated And inside there, it will tell the total donated amount. If we want to go further, we can also add another option:View Top Donators and then it will say the Player's Name and Amount. For experimental & learning purposes. Quote Sunny Go! Online pko.host Share this post Link to post Share on other sites
Totoka 152 Report post Posted October 7, 2016 (edited) A very bad way that i would not recommend is SQL, at some point you will have to manage these transactions on sql/nosql database, then you can retrieve these within lua using the SQL Extension why is bad? An IO task involves a synchronous work, this mean that if you run these queries under a character event/request, this one will be blocked until the query returns, which is bad because there is a task queue to be attended within the same luaVM, and that queue speed will be reduced dramatically. Edit: * would not give an script, it is not a `simple` stuff to do, sorry! * also this kind of stuff can be done within more files to log, store and control many things!, - but is not my way go, i think an SQL Database would be good for such kind of propose ~ dynamic data My recommendation: The good way to go, using same approach, but complex, create on C/C++ some threadpool to attend stuff like that, then hooking and calling it from lua like: push an sql reader task, with elapsed time to control intervals and avoid unnecessary sql spam -- cache it when finished, because the way you wan it can be a good option to approach the result for also other players ( same top list result ) Is this data ready? -- process it! end -- otherwise ignore it and use a cached one. Edited October 7, 2016 by Totoka 1 Quote Discord: andresc Share this post Link to post Share on other sites
Angelix 374 Report post Posted October 8, 2016 (edited) Something like this? Donation() function Donation() if Donation == nil then Donation = {} Donation.Player = {} Donation.Total = {Amount = 0, Times = 0} Donation.Top = {} Donation.Top.First = nil Donation.Top.Second = nil Donation.Top.Third = nil end end function Donate(Player, Amount) local PlayerName = GetChaDefaultName(Player) if Donation.Player[PlayerName] = nil then Donation.Player[PlayerName] = {Times = 0, Amount = 0} end Donation.Player[PlayerName].Times = Donation.Player[PlayerName].Times + 1 Donation.Player[PlayerName].Amount = Donation.Player[PlayerName].Amount + Amount Donation.Total.Times = Donation.Total.Times + 1 Donation.Total.Amount = Donation.Total.Amount + Amount end function SortDonation(Type) if Type == 1 then for Name, Var in next, Donation.Player do if Var.Amount > Donation.Player[Donation.Top.First].Amount then Donation.Top.Third = Donation.Top.Second Donation.Top.Second = Donation.Top.First Donation.Top.First = Name elseif Var.Amount > Donation.Player[Donation.Top.Second].Amount then Donation.Top.Third = Donation.Top.Second Donation.Top.Second = Name elseif Var.Amount > Donation.Player[Donation.Top.Third].Amount then Donation.Top.Third = Name end end elseif Type == 2 then for Name, Var in next, Donation.Player do if Var.Times > Donation.Player[Donation.Top.First].Times then Donation.Top.Third = Donation.Top.Second Donation.Top.Second = Donation.Top.First Donation.Top.First = Name elseif Var.Times > Donation.Player[Donation.Top.Second].Times then Donation.Top.Third = Donation.Top.Second Donation.Top.Second = Name elseif Var.Times > Donation.Player[Donation.Top.Third].Times then Donation.Top.Third = Name end end end end function DonationNPC() Text(1, "Donate", JumpPage, 2) Text(1, "Total Donated", JumpPage, 3) Text(1, "Top Donators", JumpPage, 4) Text(2, "Donate: 1,000G", Donate, 1000) Text(2, "Donate: 10,000G", Donate, 10000) Text(2, "Donate: 100,000G", Donate, 100000) Talk(3, "Total amount donated: "..Donation.Total.Amount..", total times donated: "..Donation.Total.Times) InitTrigger() TriggerAction(1, SortDonation, 1) TriggerAction(1, JumpPage, 5) Text(4, "TOP Donators: Amount", MultiTrigger, GetMultiTrigger(), 1) InitTrigger() TriggerAction(1, SortDonation, 2) TriggerAction(1, JumpPage, 6) Text(4, "TOP Donators: Times", MultiTrigger, GetMultiTrigger(), 1) Talk(5, "TOP Donators\n Place Player Amount\n #1 "..Donation.Top.First.." "..Donation.Player[Donation.Top.First].Amount.."\n #2 "..Donation.Top.Second.." "..Donation.Player[Donation.Top.Second].Amount.."\n #3 "..Donation.Top.Third.." "..Donation.Player[Donation.Top.Third].Amount.."\n") Talk(6, "TOP Donators\n Place Player Times\n #1 "..Donation.Top.First.." "..Donation.Player[Donation.Top.First].Times.."\n #2 "..Donation.Top.Second.." "..Donation.Player[Donation.Top.Second].Times.."\n #3 "..Donation.Top.Third.." "..Donation.Player[Donation.Top.Third].Times.."\n") end It probably ain't a working code, but you get the basic idea. Edited October 8, 2016 by Angelix 3 Quote Share this post Link to post Share on other sites
Vasil 71 Report post Posted October 8, 2016 22 hours ago, Shako said: Hello, can someone write a brief script on an NPC like this? Talk - Donate NPC It gives you options: Donate 1000G, Donate 10000G, Donate 1000000G And then there's another option: View Total Donated And inside there, it will tell the total donated amount. If we want to go further, we can also add another option:View Top Donators and then it will say the Player's Name and Amount. For experimental & learning purposes. I'll be in PC and i'll give you the TOP Donators script(Requires LUASQL) 1 Quote Share this post Link to post Share on other sites
Guest Report post Posted October 8, 2016 Write it using a text database. Store character id and the value inside. There are several scripts like the one you've requested. There's no need to use sql really as long as your server is not mega-super popular or sth, since you'd have to use wrexor's lib (which is actually the best way to do it then) or 3rd party app to execute queries (which isn't a great idea). Quote Share this post Link to post Share on other sites
MonkeyCode 453 Report post Posted October 8, 2016 16 hours ago, Angelix said: Something like this? Donation() function Donation() if Donation == nil then Donation = {} end end It probably ain't a working code, but you get the basic idea. I am sure though may be wrong, Donation() and Donation = {} will collide. Well not collide, but the first condition: if Donation == nil then will never execute because Donation will always exist due to the function also being called Donation Quote Share this post Link to post Share on other sites
Angelix 374 Report post Posted October 8, 2016 2 hours ago, KONG said: I am sure though may be wrong, Donation() and Donation = {} will collide. Well not collide, but the first condition: if Donation == nil then will never execute because Donation will always exist due to the function also being called Donation Well, just a typo then, sorry haha Either way, he'll need to change that a bit and add the NPC functions to their respective scripts in order to use that NPC. It's just a base if that's what he's looking for. 1 Quote Share this post Link to post Share on other sites
Shako 97 Report post Posted October 11, 2016 On 08/10/2016 at 5:10 PM, Vasil said: I'll be in PC and i'll give you the TOP Donators script(Requires LUASQL) Can you post it here? On 08/10/2016 at 6:06 PM, nephthjes said: Write it using a text database. Store character id and the value inside. There are several scripts like the one you've requested. There's no need to use sql really as long as your server is not mega-super popular or sth, since you'd have to use wrexor's lib (which is actually the best way to do it then) or 3rd party app to execute queries (which isn't a great idea). Which is wrexor's lib? LuaSQL.dll? Quote Sunny Go! Online pko.host Share this post Link to post Share on other sites
Shako 97 Report post Posted October 11, 2016 (edited) Thanks for the replies guys, Ill give them a try when I have the time. Edited October 11, 2016 by Shako Quote Sunny Go! Online pko.host Share this post Link to post Share on other sites
Vasil 71 Report post Posted October 11, 2016 12 hours ago, Shako said: Thanks for the replies guys, Ill give them a try when I have the time. Hi , i didn't have time to post it. Wait please a bit more. Thanks Quote Share this post Link to post Share on other sites