Jump to content

RAINBOW

Member
  • Posts

    103
  • Joined

  • Last visited

Recent Profile Visitors

977 profile views
  1. RAINBOW

    Lua - File I/O

    This function is in my include file. It's a way to do a "Check if File Exists()". If it returns nil, well... You know the routine by now --prints an error message if file not exist in dir. function checkFileExist(_sFile) local string sFile = _sFile; local file = getFileReader(sFile, false); -- dir: C:\Users\User\Zomboid\Lua if file == nil then --does anything exist there? print("RAENBOW : Could not find file : ".. sFile .. " in C:\Users\User\Zomboid\Lua"); else -do nothing. File exists. end endSo if you wanted to check a file existed in your code, the format of the function would be: checkFileExist("Item_ m4a1.png");The file extension doesn't matter in this very basic function. Note the path I have commented actually, you'll see what RoboMat was saying- We aren't able to do what are known as i.o write/read from our wee lua files to anywhere except this directory. So any custom files we want people to be using have to be in
  2. Holy smokes. You are quite right, I do apologise. There's an event in there: Events.OnWorldMessage.Add(ISChat.addLineInChat); I use this website HERE to look up my events. Is there a more (regularly) updated one I can check out, out there?
  3. Turbo, there's no Event for: "OnWorldMessage" I, likewise, wanted to create some server specific commands relating to the chat. I discovered only lua relating to drawing UI although there was some methods in the "media/lua/Chat/" folder that would fire a "Command" like the method you mentioned, the sendWorldMessage stuff. Good link for the java class tho
  4. Dude. Totally fucking works. Hard to believe someone who created a "Pillow Case silencer" could stumble upon this beauty! Also, that is the most horrendously commented tutorial I've ever read!
  5. Solved it! Whoever it is that made the "Pillow Silencer" mod, (He doesn't leave his name!) has written this: http://pz-mods.net/guide/get-what-data-getmoddata/ It's how to save a table of values to ANY item we want in the game. Kickass.
  6. Is that a no Aricane? I'll have to put a value into a lua file too? Gonna try it first, might be just THIS simple after all?
  7. Anyway, lol! THANKS! 12.5 , thanks! Lol! Realised I seemed a bit ungrateful there, haha soz!
  8. Someone didn't study "Limits" in maths! The problem is not that my function is firing "EveryTenMinutes", but rather it is/will be doing so over an extended period of time. The idea behind a player being able to call my(custom) function and access the stored variable means I don't want it to be off by hours(real time) which if I am a second 'off' will be amplified by two, by two by two etc... Don't you see the merit in a player being able to simply type a command to see how long the server has been up? It shows how long it has been since the last reset for example! As I said before tho, using Ticks is overkill for this too, I don't need it THAT accurate, but a modicum of accuracy is called for. I doubt our server will stay up for longer than a week ever at a time, without a soft reset. Ours is a persistent world however. So, needs must.
  9. I wasn't too sure about this script business. I read This and I'm beginning to wonder. "Is creating my own custom variable and attaching it to an item, as simple as adding a line of code in here?" For example: item EnergyDrink{HungerChange = 10,Weight = 1.0,Type = Food,UnhappyChange = 10,ThirstChange = -5,DisplayName = Energy drink,ReplaceOnUse = PopBottleEmpty,Icon = Pop4,CustomContextMenu = Drink,}Can I just 'add' in a line here? such as item EnergyDrink{HungerChange = 10," " " " " "CharacterTokenFaction = Bandit," " " " " "CustomContextMenu = Drink,} Surely it can't be that simple?
  10. Came up with some code that checks for a custom item I've modded in called "Ctoken". Have a look if you like, I have gotten to the point where I access the server specific item, then realised I don't have a clue if I can just 'add' in values to it. The idea behind storing it on an item is for our persistent server, each character will get the item when they join (If they don't already possess one that is!). The event OnGameStart is serving fine for this purpose, anyway, boolean (true or false) values such as "Trusted Player" and custom player factions such as "Trader" are going to be set on this wonderific "do it all" item. Here's my code: --+ Raenbow +----+ 9th May 2014 +-- --+ CHARACTER TOKEN HANDLER. +---- function loadToken(_player)local player = _player;local token = player:getInventory():FindAndReturn("Raenbow.Ctoken");--local string sDebug = token:getName(); --returns "Character Token" --How can I add in 'another' value to the object token? end function raenbow_ctoken() local player = getPlayer(); --Check if a ctoken exists in inventory or not here:if player:getInventory():contains("Item_Ctoken") == false then--No Ctoken exists, create one and move on:print("Raenbow: No CTOKEN FOUND. CREATING ONE:");getPlayer():getInventory():AddItem("Raenbow.Ctoken");elseprint("Raenbow: CTOKEN FOUND!");end --to do here, Check there is not more than one ctoken here: --Execute next part here:loadToken(player);end Events.OnGameStart.Add(raenbow_ctoken); I'm entirely unsure if I can just 'add' in a value somehow, like with a simple "SetValue()" command or whatever, all I managed to trawl up from the javadocs and gleaming the forums was these: setScriptItem(token);ScriptManager():getItem(); But from what I see on the forums, the scripting stuff is getting binned or whatever anyway. Surely there must be a simple way to attach a bunch of string/int/bools to an inventory item object? Thanks in advance! This one has me stumped
  11. You're certain every 24 hours (1 day) game time is equal to 30 minutes in real time? I couldn't find anywhere on the forums that clarified that. I can't be off, not even by 1 millisecond. If you're certain you read that somewhere I'll believe you, and thanks Aricane
  12. Viceroy: The one you are looking to hook into is the perform() function in a TimedAction. Overwrite the "perform" function to do your check, for example, for my "Vegetarian" custom trait, I wanted to be able to check the ISEAT.lua which would then fire a timed action in the perform in it's 'require' at the top, I always think a wee bit of code speaks volumes anyway, here's my code: require 'TimedActions/ISEatFoodAction' --Hooked into here for "Vegetarian Trait" when they eat ham. function ISEatFoodAction:perform() -- CUSTOMISED FOR SANCTUARY local player = self.character;local item = self.item;local string whatIam = item:getName(); print("1: is working"); player:Say("AAAAAA"); --If the player eats some ham has the veg trait:if whatIam == "Ham" and player:HasTrait("vegetarian") then print("I ate some " .. whatIam .. " but I'm a bloody vegetarian! eek");else--call the original "Perform" code here: self.item:getContainer():setDrawDirty(true);self.item:setJobDelta(0.0);self.character:Eat(self.item);self.character:getBodyDamage():JustAteFood(self.item);self.item:UseItem(); -- needed to remove from queue / start next.ISBaseTimedAction.perform(self);end-- END CUSTOM HOOK end Events.OnFillInventoryObjectContextMenu.Add(ISEatFoodAction:perform());The code fires every time an item is eaten. And checks if it is ham. It fires a print statement. Pretty self explanatory eh? Oh! You might need to alter the require statement at the top if you are using build 26+ because the directory structure is changing now that PZ has gone multiplayer. The event "Onfillinventory" blah blah blah, is what fires when a player right clicks inventory. The function name ISEatFoodAction:perform is pinched from the Timed Action which links into that. Anyway, private message me if you need more help.
  13. MOODLEFACTORY() Moodles as it stands require a tremendous amount of work for us to alter. The function "MoodleFactory()" needs to be put in. Sure, we can alter moodles with item use (such as cigarettes), but firing a moodle change from a player object is much harder. One of the classes not inherited to the player object(but inherited by item obj's) is moodleChange(), for example "boredomChange()" or "panicChange()". That's one other possible solution to this prob.
×
×
  • Create New...