-
Posts
6,062 -
Joined
-
Last visited
-
Days Won
208
Everything posted by IIYAMA
-
Is it possible to load 2 different types of mods on the same model?
IIYAMA replied to FlyingSpoon's topic in Scripting
Most likely. Unless that person is really good with shaders and can do it without. But I have never created a shader in my life, so I do not know their limits as well. (Which is of course also limited to the hardware, but textures and objects will work on 99%of the video cards unless they run out of vram.) -
Is it possible to load 2 different types of mods on the same model?
IIYAMA replied to FlyingSpoon's topic in Scripting
One of the two points I noted before and most likely a combination of both. (You can attach objects as well to peds with bone attach resource) -
@majqq Oke let me explain you the difference between Lua tables and objects / arrays in JavaScript. (JSON = JavaScript Object Notation) Here we have a table with array structure in Lua: local thisArray = {1, 2, 3, 4} Here we have a table with object structure in Lua: local thisObject = {a = 1, b = 2, c = 3, d = 4} Here we have a table with an mixed structure in Lua: local thisMix = {a = 1, b = 2, 3, 4} As you can see those are tables. There is no such thing as arrays or objects in Lua. But if we were to transform them to JavaScript: Array const thisArray = [1, 2, 3, 4]; Object const thisObject = {a: 1, b: 2, c: 3, d: 4}; There is NO mixed in JavaScript! If you insert a mixed Lua table in JSON (JavaScript Object Notation), the structure will be an OBJECT ? Afaik this is what is happening to you, except it doesn't look like you are doing the same thing... local thisMix = {a = 1, b = 2, 3, 4} To JSON .................... From JSON local thisMix = {a = 1, b = 2, ["1"] = 3, ["2"] = 4} -- or local thisMix = {["a"] = 1, ["b"] = 2, ["1"] = 3, ["2"] = 4} So how about try it without defining any keys. Because I really have no other idea why else it would change it to an object. playerData = {playerItems = {false, false, false, false, false, false, false, false, false, false}}
-
Is it possible to load 2 different types of mods on the same model?
IIYAMA replied to FlyingSpoon's topic in Scripting
Technical it is not possible. The rule is: 1 model, per 1 model ID. There is only one thing that can overrule the visualization in game without changing models and that is: `shaders`. Unless you find somebody who is a professional with shaders + willing to help you, it will remain an impossible. Another approach I have seen before to create custom cars, is by attaching custom objects to the vehicle which look like vehicle components. That will require a good modeller. -
As I mentioned before, do not mix arrays and objects in same table in Lua. For some unknown reason that has happend here. The json I am looking at contains an object instead of an array. Object: { } Array: [ ] Try to not assign the items to specific indexes, but keep it untouched. In your current code the items can be accessed using a string "1", "2" etc. Use: iprint to figure out more info.
-
Might be possible, as long as it is detected by MTA. Not all animations are for some unknown reason detected. Just test it!
-
It is less efficient because: - Tables are a very different format than XML. That means that you have to write and convert the data with a lot more extra code. - It isn't compact, the filesize will be a lot bigger incompare to JSON.
-
I noticed that I haven't gave you an useful examples. @majqq Well here you have an example of: B In OOP. Not MTA OOP, which I do not like, but pure Lua OOP. And see how the magic does it's job. local newTable = enchantedTable:create() newTable:add({type = "yes", 1, 2, 3, 4}, {type = "no", 5, 6, 7, 8}, {type = "no", 5, 6, 7, 8}) -- add three items local collection = newTable:get() -- get the whole collection print(collection[1]) -- get the first print(collection[2]) -- get the second print(collection[3]) -- get the third -- Getting the result of the item records. print("all: ", newTable:count()) -- count all: 3 print("`yes`: ", newTable:count("yes")) -- count only type `yes`: 1 print("`no`: ", newTable:count("no")) -- count only type `no`: 2 newTable:remove(2) -- remove item 2. print("`no`: ", newTable:count("no")) -- count only type `no`: 1 When using this code you can easy extend functionality a long the way. Just adding methods to the methods-table and new functionality opens up to you. But remember, do not modify the collection (of the items) without using these functions, or the registration will not be able to get track of the item count.
-
XML has most of the cons. It is also much older, so it is to be expected. There are a few XML haters on the community, so I will keep it short. So a few pro's: - Readability is very high, especially in case of inheritance. In JSON that can also be good, but you will need a proper reader for that. - Maintenance. In case of breaking it, it is very easy to fix it. (That being said, it breaks easier if you do not know the rules.) - Saving JSON inside the notes and keeping a secondary XML layer of properties that do not have to be saved in your main data. There are not many user cases where you want that on clientside. Unless you have a shared settings file for all resources. In that case you only have to parse JSON of a specific resource node. - (not related to player settings) Can be use for multiple files that are already integrated in mta. XML, map, (acl*) So JSON? Yes, if you keep your lua table it's structure: arrays and object separated.
-
Tables that are 'saved' inside of other tables do not become a different tables. So no, there are no better solutions, except if we optimise it for the code around it that is going to use it. This matters: - The frequently + when which operation of the table is used. If we ignore the types of methods to accomplish our goal, and only look at which options there are: A: Check every items and find out the information we need. B: Keep a record of which types of items we are adding and removing. Which one is better? That depends on the frequency which part of the code is used. There are two parts: 1. Modifications of the table. 2. Reading the table.(item count) (More table modification, than reading the table, pick option: A) (More reading the table, than table modification, pick option: B)
-
I recommend to copy the editor dumb file in that case. It should contain the most possible recent map content of the map that doesn't want to be saved. Bring the content of that file to the forum to debug the xml structure. (I have fixed map files before)
-
With a loop, as you are already doing. Or use a meta table on top of your table, which can be used as `firewall` + to keep track of inserted item counts. If you need an example for that, feel free to ask. Meta tables can be a bit confusing and I most of the time try not to use them as they can executing a lot of functions for just simple operations.
-
Shouldn't "onClientPreRender" + setCameraMatrix fix the job? The wasted camera effect is a delayed effect. It occurs not imidiatly, but after a few frames. Also I do not know if the effect is just one frame or multiple. Another possible way could be attaching the camera to another element. But no guarantees.
-
Not sure if this works: https://wiki.multitheftauto.com/wiki/OnClientMouseMove Attach it to the gridlist. + -- doing some cursor position recalculation ... -- ... -- some more till you get the inner bounding box of the gridlist + https://wiki.multitheftauto.com/wiki/GuiGridListGetRowCount math.ceil(cursorInBoxPositionY / boxHeight * columns)
-
How would you reproduce that? Based to a quick look to your code that should be fine. Unless something is not working etc. See also this function: https://wiki.multitheftauto.com/wiki/GetKeyState
-
I have heard of this issue, but never ever had encounter it while killing a ped. How to reproduce this issue? And are you sure this isn't caused by a resource or your version of GTA?
-
function teleprotect (>>> thePlayer <<<) local vehicle = getPedOccupiedVehicle(playerSource) if vehicle then setElementVelocity(vehicle,0,0,0) setElementPosition (vehicle, 4131.3872070313, -1759.1988525391, 3) else setElementPosition (playerSource, 4131.3872070313, -1759.1988525391, 3) end outputChatBox ("You Have Been Teleported To The Highway!!", playerSource, 0, 255, 0) end local accName = getAccountName(getPlayerAccount(thePlayer)) if isObjectInACLGroup("user."..accName, aclGetGroup("Admin")) then outputChatBox ( "Server: You are not an owner!", thePlayer, 0, 255, 0 ) setElementPosition (thePlayer, 4131.3872070313, -1759.1988525391, 3) else outputChatBox (getPlayerName(thePlayer) .. ' #BEBEBEASf ! ', source, 255,255,255,true) end addCommandHandler ("highway", teleprotect) You can't just imagine variable names. Consistency matters. function healPlayer(>>> player <<<, cmd, name, price) if not name or not price then outputChatBox("/heal [Player_Name] [Price]", player, 255, 255, 255, true) else end end local gang = getPlayerAccount(thePlayer) if (gang) then if getAccountData(gang, "keks.fraktion") == 3 then outputChatBox("hp <name> <price>", thePlayer) else outputChatBox("You are not a member of Paramedic!", thePlayer, 255, 0, 0) end end local target = getPlayerFromName(name) if target then if getPlayerMoney(target)>=tonumber(price) then takePlayerMoney(target, tonumber(price)) givePlayerMoney(player, tonumber(price)) setElementHealth(target, 100) outputChatBox(getPlayerName(player) .. " healed you!", player, 255, 255, 255, true) outputChatBox("You healed " .. getPlayerName(target), player, 255, 255, 255, true) else outputChatBox("Can't pay the healing", player, 255, 255, 255, true) end else outputChatBox("I can't find the target!", player, 255, 255, 255, true) end addCommandHandler("heal", healPlayer)
-
Best practice to synchronize server/client caches
IIYAMA replied to Sorata_Kanda's topic in Scripting
You can also keep track of people that are allowed to edit the data. And only open a UI for 1 person at the time, per house. + only let that person push updates on serverside. -
Best practice to synchronize server/client caches
IIYAMA replied to Sorata_Kanda's topic in Scripting
@Sorata_Kanda while (blocked_exec["lockHouse"]) do end This will kill your server. ? The code will not stop at the current server/client frame, but freeze all frames that come after it and keep doing endlessly looping as fast as it can. Luckily Lua is smart enough to abort it after a few milliseconds. If we translate this to a possible working version. (I AM NOT saying that it is a good method, AS IT IS NOT, uses a lot of CPU as you are literally rendering on serverside) local function waitWithLocking (pickupElement) if blocked_exec["lockHouse"] then callNextFrame(waitWithLocking, pickupElement) else blocked_exec["lockHouse"] = true -- Block execution until finished (possible concurrency problem/race condition?) local houseObject = houses[pickupElement] houseObject:setLocked(not houseObject:isLocked()) blocked_exec["lockHouse"] = false end end addEventHandler('lockHouse', resourceRoot, function(pickupElement) callNextFrame(waitWithLocking, pickupElement) -- In case this event is currently handled by someone else, keep in loop until finished end) callNextFrame The thing you better can do, is sending a message back to clientside and reset the change. + WARNING. Or a just as risky, keep a table ready with all updates. When the user releases it's edit, update all changes at once. The release of the edit should also be triggered or when the player leaves. And it might also be handy to release it when the resource is going to stop. And the most enchanted method, update all clients that are editing as well instead of blocking! -
According this topic: http://www.computercraft.info/forums2/index.php?/topic/11043-invalid-key-to-next/ It says that the table has been changed while the process has been yield. Not sure is that is true or not. If we would reproduce that: We have for example this table: local thisTable = {[element] = ped, [element] = ped, [element] = ped, [element] = ped, [element] = ped,[element] = ped } We start looping: local thisTable = { [element] = ped, [element] = ped, [element] = ped, -- yield [element] = ped, [element] = ped, [element] = ped } Now a different part of the code removes: local thisTable = { [element] = ped, [element] = ped, [element] = ped, -- yield [element] = ped, -- < deleted [element] = ped, [element] = ped } And we resume. That is when it is suppose to be happening according to this information. Solution without changing the table structure? pcall might be to catch the error and if there is an error, recreate the coroutine. local status, err = pcall(coroutine.resume, clearing_nonexisting_peds) if not status then clearing_nonexisting_peds = coroutine.create(forgetNonExistingPeds) end
-
Yes! ?
-
There is no limit to local variables, as long as they are used in different file or function scopes. -- file scope 200 local's function name () -- function scope 200 local's end
-
@TorNix~|nR That is not how this works. A table is a thing, it is something even if it is empty. if {} then outputChatBox("Always true") end local players = getElementsByType("player") for index,thisPlayer in pairs(#players > 0 and players or getElementsByType("ped")) do Note, this does not merge the tables. Just uses peds when there are no players.
-
getElementsByType("gui-staticimage", resourceRoot) Maybe you get other resource elements as well?
-
@Xwad Master this loop and all possibility will open up to you. local theTable = {[0] = 0, 1,2,3,4,5,6,7} local index = 1 for i=0, #theTable, 2 do print("position: ", index * 10) index = index + 1 print("index: ", theTable[i]) print("index: ", theTable[i + 1]) print("---") end