Dowdoon Posted September 23, 2022 Share Posted September 23, 2022 (edited) For the past month or so I've been working on further developing the DrHyde's Vaccine mod to suit the needs of PZ roleplaying servers. There is one feature I'd really like to implement but am unable to. Vaccinating OTHER PLAYERS -- how can I code a function that will change the other player's bodyDamage()? So far I've successfully added a UI-button to the HealthPanelUI that opens up when medically checking right-clicked player, but I just can't manage to add function that will change right-clicked player's stats. The code I'm using is simple: adds UI-button and a 'confirmPress' function that runs when that button is pressed. But how do I change the local function confirmPress(button, args) to apply changes to the other player's stats and not the one that initiates the button press (me)? Any help is appreciated-- please help me solve something that I couldn't figure out in a month worth of time.. -- Functions for button of UIs local function confirmPress(button, args) local player = getPlayer(); if player:getInventory():getItemFromType('CmpSyringeWithVirus') then if player:getInventory():getItemFromType('AlcoholedCottonBalls') then player:getBodyDamage():setInfected(true); player:getInventory():Remove("CmpSyringeWithVirus"); player:getInventory():Remove("AlcoholedCottonBalls"); else player:Say("Cotton balls?"); end--if else player:Say("Nothing to inject with.."); end--if end--function -- Add HealthPanelUI Syringe Button local ISHealthPanel_createChildren = ISHealthPanel.createChildren function ISHealthPanel:createChildren() ISHealthPanel_createChildren(self); self.fitness:setWidth(self.fitness:getWidth()/1.5); self.TOCButton = ISButton:new(self.fitness:getRight(), self.healthPanel.y, 20, 20, "", self, confirmPress); self.TOCButton:setImage(getTexture("media/ui/iconForMenu.png")); self.TOCButton.anchorTop = false self.TOCButton.anchorBottom = true self.TOCButton:initialise(); self.TOCButton:instantiate(); self:addChild(self.TOCButton); if getCore():getGameMode() == "Tutorial" then self.TOCButton:setVisible(false); end end local ISHealthPanel_render = ISHealthPanel.render function ISHealthPanel:render() ISHealthPanel_render(self); self.TOCButton:setY(self.fitness:getY()); end Edited September 23, 2022 by Dowdoon Link to comment Share on other sites More sharing options...
Tchernobill Posted September 24, 2022 Share Posted September 24, 2022 (edited) On Dr Client side: (lua/client) sendClientCommand("DrHide", "vaccinePlayer", _data); -- _data should include the onlineID of the target player. This allows you to identify him on server side On Server side: (lua/server) DrHideServer = {} DrHideServer.OnClientCommand = function(_module, _command, _player, _packet)--not that _player is the source player. i.e. the Dr. if _module ~= "DrHide" then return; end;--the message is not for you. it's ok if (_command ~= "vaccinePlayer") or (not _packet) then return end; --bug maybe log this too --TODO interpret _packet -- it should include the onlineID of the target player. This allows you to identify him on server side --in your case there are two possibilities: -- 1/ modify the target player mod data (getModData().DrHideMD) and update them (with ModData.transmit("DrHideMD")) -- 2/ sendServerCommand to the target player end Events.OnClientCommand.Add(DrHideServer.OnClientCommand); On Vaccine target Client side: (lua/client) --if you used moddata update from server: local function OnReceiveGlobalModData(_module, _packet) if _module ~= "DrHideMD" then return; end; ModData.add(_module, _packet); --now you can use the updated moddata end; end Events.OnReceiveGlobalModData.Add(OnReceiveGlobalModData) This is how Donkaike made it in Prisonner mod. I guess you could use OnServerCommand in case 2 (using sendServerCommand on server side). Edited September 24, 2022 by Tchernobill Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now