Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
01-31-2014, 12:37 PM
(This post was last modified: 01-31-2014, 02:01 PM by ThuGie.)
Hey,
The wiki says i need to use dowithuser, though that needs a username..
I don't even get a username, i can't obtain it from the window so.. I'm kinda stuck here.
Am i able to add something extra to the callback like the player name or perhaps the cPlayer itself ?
Also, the server seems to crash, if a plugin opens a window, the client actually triggers this in the plugin doesn't close it, and the plugin gets reloaded, when the player interacts with the window aka it doesn't exist i assume ? the server crashes.
Edit, Also when i do a SetSlot it seems to trigger SetOnSlotChanged.. as my onslot change, does a setslot it go's into a loop until it gets a LUA: 2 - C stack overflow.. How to fix this ?
Edit2,
local dropItem = cPickup(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), Window:GetSlot(Player, 0),true);
Seems to not drop, but does crash the server ? am i using it wrong ? also the wiki does not have anything about the boolean, i asume false = non player, true = player
Also the finding user problem i fixed by saving playername + windowid in array.
And items lose there damage, when you move them in your inventory ?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
OnSlotChanged() event needn't come from a user, so there's no user bound to it in the interface - for example Furnaces and Hoppers change their slots on their own. That's why you don't get one. If we wanted to give you the user, we'd also need to change all the API functions setting the slots in the various containers (cChestEntity:SetSlot()), to include the Player parameter, and you'd need to fill it each time. That's probably not what you'd want.
Windows can be shared among multiple players (such as Chest or Furnace windows), so MCServer doesn't provide a means to bind a specific window for a client. You can do that in your plugin, if you know that you'll be using the window for only one player. Don't store the cPlayer object, though, as the player may get kicked for whatever reason; store the player Name or UniqueID. You can use Lua Closures for this (functions can access variables defined outside of them):
function OnMyCommand(a_Split, a_Player)
local PlayerName = a_Player:GetName()
local PlayerWorld = a_Player:GetWorld()
local NumChanges = 0
local OnSlotChanged = function(a_Window, a_SlotNum)
PlayerWorld:DoWithPlayer(PlayerName, DoSomething) -- Note that you can access PlayerWorld and PlayerName here, even when OnMyCommand() finished executing!
NumChanges = NumChanges + 1 -- You can even change the variables
end
local OnWindowClosing = function(a_Window, a_Player, a_CanRefuse)
PlayerWorld:BroadcastChat("Player " .. PlayerName .. " closed the window after making " .. NumChanges .. " changes") -- Again, you can access PlayerWorld and PlayerName
-- Note that NumChanges is shared among these two functions, so even after OnMyCommand finishes executing, they still refer to the same variable.
end
...
end
You need to take responsibility for not creating an infinite loop by using SetSlot() in OnSlotChanged(): Set a flag in the function whether the "Set" comes from you or not, and before doing the SetSlot(), set the flag. Then you get a second trigger of OnSlotChanged(), but because you test the flag at the very beginning, you won't do the second SetSlot() anymore.
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
Yeah i kinda got this working now,
Though the cpickup still breaks the server, am i using it wrong ?
local dropItem = cPickup(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), Window:GetSlot(Player, 0),true);
And when i get a wooden axe, cut down a tree its damaged, but when i move it in my inventory to another slot it instantly heals ?
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
You can't spawn pickups using the cPickups class. You need to use:
local Items = cItems(Window:GetSlot(Player, 0)
PlayerWorld:SpawnItemPickups(Items, Player:GetPosX(), Player:GetPosY(), Player:GetPosZ())
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
OH! That makes sense, will be using this, thanks again.
Also any clue why items keep restoring them selfs when moved ?
Or is this just a problem on my side ?, i will update server today, see if it solves it.. but if its known.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
No idea. If you can describe detailed steps on how to 100% reproduce that behavior, that would be great help.
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
02-01-2014, 02:54 AM
(This post was last modified: 02-01-2014, 03:48 AM by ThuGie.)
Well i get it always, i just go into classic spawn me a shovel sword or any other item that takes damage, hit a tree, move the shovel to the next slot and its repaired.
Even if i go into survival it still repairs. But i will download the latest version now so lets see if its somehow solved.
Edit, Well i got most working, haven't updated the server yet, as i am doing some other stuff first.
But i am working on plugin-side enchanting btw. i like it more that way.
But i can send all 3 options with setproperty all fine etc,
but when i click the button to enchant i get
[18:30:29] Unknown packet type 0x11 from client "ThuGhacK" @ 127.0.0.1
[18:30:29] Unhandled packet: type 0x11, state 3, length 3
Could this packet be implanted and added to cWindow ?
After that i just have to randomize the enchant per item, and read bookcases and its done.
Project made with cmake for vc++ 2012, on windows 8.1 64bit
Edit2, I forgot i should update first before making such request as it might have been added.. but.
i get this
Error 14 error C1083: Cannot open include file: 'polarssl/rsa.h': No such file or directory \mcserver-master\src\Crypto.h 12 1 MCServer
Seems to be missing something, i also dont seem to have any rsa.h file
Posts: 1,162
Threads: 68
Joined: Mar 2013
Thanks: 245
Given 125 thank(s) in 100 post(s)
do a git clone, dont download it by http
Posts: 372
Threads: 29
Joined: Mar 2011
Thanks: 1
Given 21 thank(s) in 18 post(s)
02-01-2014, 03:55 AM
(This post was last modified: 02-01-2014, 04:03 AM by ThuGie.)
Ah, well thanks for the info will do it . but anyway why would a http download fail at including a file ?
Edit, did what you say the file is still missing so..
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
Update sub modules after a git clone:
git submodule update --init
For the bool in cPickup, true means it comes from a player and will have a collection delay, false means that it can be picked up instantly. Defaults to false. Should add this to API docs
|