Jump to content

Konijima

Member
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Konijima's Achievements

  1. It would be great if we could have access to some ChatServer functions in our server-side lua script to send messages to client chats - sendServerAlertMessageToServerChat - sendMessageToServerChat - sendMessageToAdminChat
  2. Suggestion to make it a bit easier for server mods to handle some of the situation. Most of it is doable in a hacky way but having those in the core engine would just make it cleaner and more efficient for us. EVENTS: OnServerPlayerConnected (playerObj, isNewPlayer) When the player officially connected to the server, passing a parameter to inform if it's a brand new player. Use cases: Show a message, an existing player has connected. Show a message, a new player has connected. Do something every time a player join. Do something one-time only when a new player joined for the first time. ___________________________________________ OnServerPlayerDisconnected (playerObj, reason) When the player has left the server, passing a parameter to inform the reason of leaving. (Logged Out, Kicked, Banned, Unknown/Crash) Use cases: Show a message, a player has left and why. Do something special when a player disconnect based on the reason. ___________________________________________ OnServerPlayerSpawned (playerObj, isNewCharacter) Similar to OnServerPlayerConnected but also trigger after re-spawning a new character (after death). Use cases: Do something every time a player spawn. Do something when a player spawn with a new character. ___________________________________________ OnServerPlayerDied (playerObj, reason) Trigger when a player has died, potentially add the cause of the death. Use cases: Show a message, when a player died and why. Do something every time a player died.
  3. So now that I think about it. If adding a OnServerSave method, could probably get a param that specify if the shutdown signal has been given. Would probably be good to trigger that event before the saving of the GlobalModData so that we can still change stuff in it. local function onServerSave(isShuttingDown) if isShuttingDown then -- do something before saving only if shutting down end -- save stuff end Events.OnServerSave.Add(onServerSave);
  4. OnSave seem to be only a client sided event after looking at the source. Added this into a server script file. Called `save` and `quit` and no print.
  5. You know what, I will test that thanks. I'll confirm here if it does it.
  6. Hey hey hey I know it's me again with yet an other safehouse suggestion. Suggestion Allow owner to assign member roles. - Co-owner, similar to owner but cannot kick owner and cannot promote member to co-owner. - Member, give access to the safehouse as a member, allow respawn. - Visitor, default role allow the player to sleep, drink from tap water and use doors, disallow respawn and looting.
  7. Hello it's me yet again, Some mods require to save files or data into files that are kept into memory. The ability to save that data when ever the server is going to shutdown would be a blessing. Suggestion Adding a server event named 'OnServerShuttingDown' that allow server mods to do a finalization work when the server is shutting down. Result Saving files and data when the server is shutting down.
  8. Hello there again, So custom safehouse set by admin are a great feature that we appreciate alot but when player accidentally un-claim the safehouse the job needs to be done again. Suggestion Added a special variable to an admin defined safehouse so that when it is un-claimed it is not deleted but marked as not claimed and self-claimable again. Result People who abandon or accidentally un-claim a custom safehouse area, will be able to re-claim again as if this was a normal safehouse.
  9. Hello there, The way safehouse works is that it select a whole building and set the area 2 square out each side and doesn't check for the Z axis at all. Suggestion Add a Z axis to the safehouse, by default self-claimed safehouse would still be from zero to the maximum stories. But admin custom safehouse would have the possibility to set the starting Z and ending Z axis when defining the zone. Result Gives the possibility to divide apartments into multiple different safehouses, manually by an admin.
  10. Would be great to have an option in the `mod.info` to prevent my mod of loading if an other mod ID is found to be enabled. This way we can have multiple mods into a single workshop project that offer different flavor without overwriting each other when people auto-enable them all. Example: disableIf=OtherModID name=FlavourRed id=FlavourRed disableIf=FlavourBlue disableIf=FalvourYellow
  11. I share my Utilities class here, it add a variety of useful function to help make mods implementation works both in SP as in MP. It contains client only functions, server only functions and shared functions that can be used by both the client and server. The networking functions give the modders a way to make networking code work also in Single Player without needing extra code to handle that. It also give functions to check if a player is admin and moderator that both works in single player and multiplayer. For the admin function to be true in single player the game must run with debug mode enabled. This post will be updated if I update my version of the Utilities class with future game updates. Post suggestions, errors, fixes, refactor ideas of this class in this post to help improve this class. Current Game Version: 41.66 Location to place the file in your mods: media\lua\shared\Utilities.lua How to use: local Utilities = require("Utilities"); The Class: ---@class Utilities local Utilities = {}; --- [SHARED] --- Return a IsoPlayer from its username if found function Utilities.GetPlayerFromUsername(username) if isServer() then local players = getOnlinePlayers(); for i = 0, players:size() - 1 do local player = players:get(i); if player:getUsername() == username then return player; end end elseif isClient() then return getPlayerFromUsername(username); end end --- [SHARED] --- Return true if game is single player ---@return boolean function Utilities.IsSinglePlayer() return not isClient() and not isServer(); end --- [SHARED] --- Return true if game is single player with debug enabled ---@return boolean function Utilities.IsSinglePlayerDebug() return Utilities.IsSinglePlayer() and isDebugEnabled(); end --- [CLIENT] --- Return true if the game is client or single player function Utilities.IsClientOrSinglePlayer() return isClient() or Utilities.IsSinglePlayer(); end --- [SERVER] --- Return true if the game is server or single player function Utilities.IsServerOrSinglePlayer() return isServer() or Utilities.IsSinglePlayer(); end --- [CLIENT] --- Return true if client is admin or single player + debug mode ---@return boolean function Utilities.IsClientAdmin() return (isClient() and isAdmin()) or Utilities.IsSinglePlayerDebug(); end --- [CLIENT] --- Return true if the client is admin or moderator ---@return boolean function Utilities.IsClientStaff() local playerObj = getPlayer(); return Utilities.IsClientAdmin() or (instanceof(playerObj, "IsoPlayer") and playerObj:getAccessLevel() == "Moderator"); end --- [SERVER] --- Return true if the IsoPlayer is admin or single player + debug mode ---@param playerObjOrUsername IsoPlayer|string ---@return boolean function Utilities.IsPlayerAdmin(playerObjOrUsername) if type(playerObjOrUsername) == "string" then playerObjOrUsername = Utilities.GetPlayerFromUsername(playerObjOrUsername); end return (instanceof(playerObjOrUsername, "IsoPlayer") and playerObjOrUsername:getAccessLevel() == "Admin") or Utilities.IsSinglePlayerDebug(); end --- [SERVER] --- Return true if the IsoPlayer is admin or moderator ---@param playerObjOrUsername IsoPlayer|string ---@return boolean function Utilities.IsPlayerStaff(playerObjOrUsername) if type(playerObjOrUsername) == "string" then playerObjOrUsername = Utilities.GetPlayerFromUsername(playerObjOrUsername); end return (instanceof(playerObjOrUsername, "IsoPlayer") and (playerObjOrUsername:getAccessLevel() == "Admin" or playerObjOrUsername:getAccessLevel() == "Moderator")) or Utilities.IsSinglePlayerDebug(); end --- [CLIENT] --- Send a command from the client to the server ---@param _module string ---@param _command string ---@param _data table function Utilities.SendClientCommand(_module, _command, _data) if Utilities.IsClientOrSinglePlayer() then sendClientCommand(_module, _command, _data); end end --- [SERVER] --- Send a command from the server to a specific client ---@param _targetPlayerObj IsoPlayer ---@param _module string ---@param _command string ---@param _data table function Utilities.SendServerCommandTo(_targetPlayerObj, _module, _command, _data) if Utilities.IsServerOrSinglePlayer() then if Utilities.IsSinglePlayer() then triggerEvent("OnServerCommand", _module, _command, _data); else sendServerCommand(_targetPlayerObj, _module, _command, _data); end end end --- [SERVER] --- Send a command from the server to all clients ---@param _module string ---@param _command string ---@param _data table function Utilities.SendServerCommandToAll(_module, _command, _data) if Utilities.IsServerOrSinglePlayer() then if Utilities.IsSinglePlayer() then triggerEvent("OnServerCommand", _module, _command, _data); else sendServerCommand(_module, _command, _data); end end end --- [SERVER] --- Send a command from the server to all clients in range ---@param _x number ---@param _y number ---@param _z number ---@param _distanceMin number ---@param _distanceMax number ---@param _module string ---@param _command string ---@param _data table function Utilities.SendServerCommandToAllInRange(_x, _y, _z, _distanceMin, _distanceMax, _module, _command, _data) if Utilities.IsServerOrSinglePlayer() then if Utilities.IsSinglePlayer() then if Utilities.IsPlayerInRange(getPlayer(), _x, _y, _z, _distanceMin, _distanceMax) then triggerEvent("OnServerCommand", _module, _command, _data); end else local players = getOnlinePlayers(); if players then for i = 0, players:size() - 1 do local targetPlayer = players:get(i); if Utilities.IsPlayerInRange(targetPlayer, _x, _y, _z, _distanceMin, _distanceMax) then sendServerCommand(targetPlayer, _module, _command, _data); end end end end end end --- [SHARED] --- Return true if the IsoPlayer is in range ---@param _x number ---@param _y number ---@param _z number ---@param _distanceMin number ---@param _distanceMax number ---@return boolean function Utilities.IsPlayerInRange(_playerObj, _x, _y, _z, _distanceMin, _distanceMax) if not _playerObj then return false; end local x2, y2, z2 = _playerObj:getX(), _playerObj:getY(), _playerObj:getZ(); local currentDistance = IsoUtils.DistanceTo(_x, _y, _z, x2, y2, z2); return (currentDistance >= _distanceMin and currentDistance <= _distanceMax); end --- Check if a square is powerred function Utilities.SquareHasElectricity(square) return (SandboxVars.AllowExteriorGenerator and square and square:haveElectricity()) or (SandboxVars.ElecShutModifier > -1 and GameTime:getInstance():getNightsSurvived() < SandboxVars.ElecShutModifier); end --- Get the server name or the save file name in single player function Utilities.GetServerName() if Utilities.IsSinglePlayer() then local world = getWorld():getWorld(); if type(world) == "string" and world ~= "" then local saveInfo = getSaveInfo(world) if saveInfo and saveInfo.gameMode then return saveInfo.saveName; end end return "SinglePlayerGame"; else return getServerOptions():getOptionByName("PublicName"):getValue(); end return "Unknown"; end function Utilities.SplitString(str, delimiter) local result = {} for match in (str..delimiter):gmatch("(.-)%"..delimiter) do table.insert(result, match) end return result end function Utilities.SquareToString(square) if square then return square:getX() .. "|" .. square:getY() .. "|" .. square:getZ(); end end function Utilities.StringToSquare(string) local split = Utilities.SplitString(string, "|"); if #split >= 3 then local x, y, z = tonumber(split[1]), tonumber(split[2]), tonumber(split[3]); local square = getCell():getGridSquare(x, y, z); if square then return square; end end end function Utilities.FindAllItemInInventoryByTag(inventory, tag) local foundItems = ArrayList.new() local validItems = getScriptManager():getItemsTag(tag) if validItems then for i=0, validItems:size()-1 do foundItems:addAll(inventory:getItemsFromFullType(validItems:get(i):getFullName())) end end return foundItems end function Utilities.GetMoveableDisplayName(obj) if not obj then return nil end if not obj:getSprite() then return nil end local props = obj:getSprite():getProperties(); if props:Is("CustomName") then local name = props:Val("CustomName"); if props:Is("GroupName") then name = props:Val("GroupName") .. " " .. name; end return Translator.getMoveableDisplayName(name); end return nil; end return Utilities;
  12. This post is for requesting two new global functions followed with a description and pro/con. __________________________________________________________________ The functions: Json Encode A function to serialize data into a json string. Json Decode A function to deserialize a json string back into data. __________________________________________________________________ We currently have access to an external LUA json library that works pretty well. But using an Java version of it would save a lot of LUA calls and run much faster especially for serializing large amount of data. The function de/serialize a Kalhua Table as a Json Array or a Json Object. __________________________________________________________________ Pro: - To use an exposed java json serializer would greatly improve the performance compared to using a LUA json script. Con: - Require TIS dev team to implement it and make it exposed and bug less.
  13. So I have a custom spawn point system which let the player choose a location to teleport to. It seem that player (non-admin only) get kicked when running this command: playerObj:setPosition(x, y, z); It's seem that the anti-cheat detect teleportation from a distance as a cheat. It is probably the wanted behavior for the anti-teleport purpose but I wonder as a modder, what would be the proper way of teleporting a client. Trying to set the player position from the server side didn't do anything on the client so maybe an example snippet as to how to do it would be helpful. Any mod setting the player position probably will kick with Type 2. Admin account don't seem to get kicked from using the setPosition, or even setX, setLx, etc...
×
×
  • Create New...